-
Notifications
You must be signed in to change notification settings - Fork 829
feat(cli): add theme option for interactive shell and enhance configuration #2519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Devesh36
wants to merge
8
commits into
Tracer-Cloud:main
Choose a base branch
from
Devesh36:themee
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
68fa4f3
feat(cli): add theme option for interactive shell and enhance configu…
Devesh36 7559677
fix(cli): pass CI quality and address theme PR review
Devesh36 07533c3
fix(cli): resolve CodeQL findings and theme CI issues
Devesh36 e1301d3
Merge branch 'main' into themee
Devesh36 29ff8f4
Merge branch 'main' into themee
Devesh36 20dccad
Merge branch 'main' into themee
Devesh36 df8ea3b
refactor(theme): update theme option to use dynamic theme list
Devesh36 73c978e
refactor(theme): streamline theme choices generation in interactive s…
Devesh36 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| """Slash command: interactive theme selection and persistence.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from rich.console import Console | ||
|
|
||
| from app.cli.interactive_shell.command_registry.types import ExecutionTier, SlashCommand | ||
| from app.cli.interactive_shell.runtime import ReplSession | ||
| from app.cli.interactive_shell.ui import theme as ui_theme | ||
| from app.cli.interactive_shell.ui.choice_menu import repl_choose_one, repl_tty_interactive | ||
| from app.cli.interactive_shell.ui.theme import ( | ||
| get_active_theme_name, | ||
| list_theme_names, | ||
| set_active_theme, | ||
| ) | ||
|
|
||
|
|
||
| def _refresh_prompt_style(session: ReplSession) -> None: | ||
| """Schedule a prompt-toolkit style refresh on the main thread.""" | ||
| from app.cli.interactive_shell.prompting.prompt_surface import refresh_prompt_theme | ||
|
|
||
| if session.main_loop is not None: | ||
| session.main_loop.call_soon_threadsafe(refresh_prompt_theme, session) | ||
|
|
||
|
|
||
| def _persist_and_report_theme( | ||
| session: ReplSession, | ||
| console: Console, | ||
| selected: str, | ||
| ) -> None: | ||
| from app.cli.commands.config import _load_config, _save_config, _set_nested_key | ||
| from app.cli.interactive_shell.runtime.loop import drain_stale_cpr_bytes | ||
| from app.cli.interactive_shell.ui.rendering import refresh_welcome_poster | ||
|
|
||
| active = set_active_theme(selected) | ||
| session.active_theme_name = active.name | ||
| _refresh_prompt_style(session) | ||
|
|
||
| updated = _set_nested_key(_load_config(), "interactive.theme", active.name) | ||
| _save_config(updated) | ||
|
|
||
| drain_stale_cpr_bytes() | ||
| refresh_welcome_poster(console, session=session, theme_notice=active.name) | ||
| drain_stale_cpr_bytes() | ||
|
|
||
|
|
||
| def _cmd_theme(session: ReplSession, console: Console, args: list[str]) -> bool: | ||
| if args: | ||
| selected = args[0].strip().lower() | ||
| if selected not in list_theme_names(): | ||
| supported = ", ".join(list_theme_names()) | ||
| console.print(f"[{ui_theme.ERROR}]unknown theme:[/] {selected} (choose: {supported})") | ||
| return True | ||
| _persist_and_report_theme(session, console, selected) | ||
| return True | ||
|
greptile-apps[bot] marked this conversation as resolved.
|
||
|
|
||
| if not repl_tty_interactive(): | ||
| console.print(f"[{ui_theme.DIM}]/theme requires an interactive TTY session.[/]") | ||
| return True | ||
|
|
||
| current = get_active_theme_name() | ||
| session.active_theme_name = current | ||
| choices = [ | ||
| (name, f"{name}{' (current)' if name == current else ''}") for name in list_theme_names() | ||
| ] | ||
| picked = repl_choose_one( | ||
| title="theme", | ||
| breadcrumb="/theme", | ||
| choices=choices, | ||
| initial_value=current, | ||
| ) | ||
| if picked is None: | ||
| console.print(f"[{ui_theme.DIM}]theme unchanged.[/]") | ||
| return True | ||
|
|
||
| _persist_and_report_theme(session, console, picked) | ||
| return True | ||
|
|
||
|
|
||
| _THEME_FIRST_ARGS: tuple[tuple[str, str], ...] = tuple( | ||
| (name, "interactive palette") for name in list_theme_names() | ||
| ) | ||
|
|
||
| COMMANDS: list[SlashCommand] = [ | ||
| SlashCommand( | ||
| "/theme", | ||
| "Choose and persist the interactive shell color theme.", | ||
| _cmd_theme, | ||
| usage=("/theme", "/theme <name>"), | ||
| examples=("/theme blue", "/theme green"), | ||
| first_arg_completions=_THEME_FIRST_ARGS, | ||
| execution_tier=ExecutionTier.SAFE, | ||
| ) | ||
| ] | ||
|
|
||
| __all__ = ["COMMANDS"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.