mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 13:47:19 +08:00
cli: fix Ubuntu white-on-white model autocomplete by merging default prompt_toolkit UI style (#10347)
This commit is contained in:
26
openhands/cli/pt_style.py
Normal file
26
openhands/cli/pt_style.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from prompt_toolkit.styles import Style, merge_styles
|
||||
from prompt_toolkit.styles.defaults import default_ui_style
|
||||
|
||||
# Centralized helper for CLI styles so we can safely merge our custom colors
|
||||
# with prompt_toolkit's default UI style. This preserves completion menu and
|
||||
# fuzzy-match visibility across different terminal themes (e.g., Ubuntu).
|
||||
|
||||
COLOR_GOLD = '#FFD700'
|
||||
COLOR_GREY = '#808080'
|
||||
COLOR_AGENT_BLUE = '#4682B4' # Steel blue - readable on light/dark backgrounds
|
||||
|
||||
|
||||
def get_cli_style() -> Style:
|
||||
base = default_ui_style()
|
||||
custom = Style.from_dict(
|
||||
{
|
||||
'gold': COLOR_GOLD,
|
||||
'grey': COLOR_GREY,
|
||||
'prompt': f'{COLOR_GOLD} bold',
|
||||
# Ensure good contrast for fuzzy matches on the selected completion row
|
||||
# across terminals/themes (e.g., Ubuntu GNOME, Alacritty, Kitty).
|
||||
# See https://github.com/All-Hands-AI/OpenHands/issues/10330
|
||||
'completion-menu.completion.current fuzzymatch.outside': 'fg:#ffffff bg:#888888',
|
||||
}
|
||||
)
|
||||
return merge_styles([base, custom])
|
||||
@@ -8,8 +8,8 @@ from prompt_toolkit.shortcuts import print_container
|
||||
from prompt_toolkit.widgets import Frame, TextArea
|
||||
from pydantic import SecretStr
|
||||
|
||||
from openhands.cli.pt_style import COLOR_GREY, get_cli_style
|
||||
from openhands.cli.tui import (
|
||||
COLOR_GREY,
|
||||
UserCancelledError,
|
||||
cli_confirm,
|
||||
kb_cancel,
|
||||
@@ -242,7 +242,7 @@ async def modify_llm_settings_basic(
|
||||
provider_list = verified_providers + provider_list
|
||||
|
||||
provider_completer = FuzzyWordCompleter(provider_list, WORD=True)
|
||||
session = PromptSession(key_bindings=kb_cancel())
|
||||
session = PromptSession(key_bindings=kb_cancel(), style=get_cli_style())
|
||||
|
||||
current_provider, current_model, current_api_key = (
|
||||
_get_current_values_for_modification_basic(config)
|
||||
@@ -490,7 +490,7 @@ async def modify_llm_settings_basic(
|
||||
async def modify_llm_settings_advanced(
|
||||
config: OpenHandsConfig, settings_store: FileSettingsStore
|
||||
) -> None:
|
||||
session = PromptSession(key_bindings=kb_cancel())
|
||||
session = PromptSession(key_bindings=kb_cancel(), style=get_cli_style())
|
||||
llm_config = config.get_llm_config()
|
||||
|
||||
custom_model = None
|
||||
@@ -621,7 +621,7 @@ async def modify_search_api_settings(
|
||||
config: OpenHandsConfig, settings_store: FileSettingsStore
|
||||
) -> None:
|
||||
"""Modify search API settings."""
|
||||
session = PromptSession(key_bindings=kb_cancel())
|
||||
session = PromptSession(key_bindings=kb_cancel(), style=get_cli_style())
|
||||
|
||||
search_api_key = None
|
||||
|
||||
|
||||
@@ -31,6 +31,12 @@ from prompt_toolkit.styles import Style
|
||||
from prompt_toolkit.widgets import Frame, TextArea
|
||||
|
||||
from openhands import __version__
|
||||
from openhands.cli.pt_style import (
|
||||
COLOR_AGENT_BLUE,
|
||||
COLOR_GOLD,
|
||||
COLOR_GREY,
|
||||
get_cli_style,
|
||||
)
|
||||
from openhands.core.config import OpenHandsConfig
|
||||
from openhands.core.schema import AgentState
|
||||
from openhands.events import EventSource, EventStream
|
||||
@@ -66,16 +72,7 @@ recent_thoughts: list[str] = []
|
||||
MAX_RECENT_THOUGHTS = 5
|
||||
|
||||
# Color and styling constants
|
||||
COLOR_GOLD = '#FFD700'
|
||||
COLOR_GREY = '#808080'
|
||||
COLOR_AGENT_BLUE = '#4682B4' # Steel blue - less saturated, works well on both light and dark backgrounds
|
||||
DEFAULT_STYLE = Style.from_dict(
|
||||
{
|
||||
'gold': COLOR_GOLD,
|
||||
'grey': COLOR_GREY,
|
||||
'prompt': f'{COLOR_GOLD} bold',
|
||||
}
|
||||
)
|
||||
DEFAULT_STYLE = get_cli_style()
|
||||
|
||||
COMMANDS = {
|
||||
'/exit': 'Exit the application',
|
||||
|
||||
Reference in New Issue
Block a user