Skip to content

Commit 73eb26a

Browse files
committed
feat(repl): show a startup banner
When the REPL starts in an interactive terminal it now prints a Python-style banner with the RobotCode, Robot Framework, and Python versions, plus a hint about `.help` and `.exit`. The banner is skipped when stdin is piped/redirected or when running `--files` without `--inspect`.
1 parent 8a34747 commit 73eb26a

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

‎packages/repl/src/robotcode/repl/console_interpreter.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929
convert_from_rest,
3030
get_library_doc,
3131
)
32+
from robotcode.robot.utils import get_robot_version_str
3233
from robotcode.robot.utils.markdownformatter import MarkDownFormatter
3334

35+
from .__version__ import __version__
3436
from ._indent import compute_indent
3537
from ._keyword_lookup import _LIB_KEYWORDS_ATTR, lookup_keyword_doc, lookup_library_doc
3638
from ._session_export import render_robot_file
@@ -341,6 +343,28 @@ def show_doc(self, title: str, markdown: str) -> None:
341343
if self.app is not None:
342344
self.app.echo_via_pager(body, color=False)
343345

346+
def show_banner(self) -> None:
347+
"""Print a Python-REPL-style banner before the first prompt.
348+
349+
Skipped when stdin isn't a TTY (input piped/redirected) or
350+
when running non-interactively from ``--files`` without
351+
``--inspect`` — neither case ever reaches an interactive prompt.
352+
"""
353+
if self.app is None or not sys.stdin.isatty():
354+
return
355+
if self.files and not self.inspect:
356+
return
357+
358+
py = f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}"
359+
rf = get_robot_version_str()
360+
header = f"RobotCode REPL {__version__} (Robot Framework {rf}, Python {py} on {sys.platform})"
361+
self.app.echo(click.style(header, bold=True))
362+
self.app.echo('Type ".help" for commands, ".exit" to quit.')
363+
364+
def run(self) -> Any:
365+
self.show_banner()
366+
return super().run()
367+
344368
# ------------------------------------------------------------------
345369
# Robot integration
346370
# ------------------------------------------------------------------

0 commit comments

Comments
 (0)