Skip to content

πŸ™Œ OpenHands: AI-Driven Development

cli: fix Ubuntu white-on-white model autocomplete by merging default prompt_toolkit UI style (#10347)

Engel Nystbef6b1afee19
diff --git a/openhands/cli/pt_style.py b/openhands/cli/pt_style.py
new file mode 100644
index 0000000000..be4cd9ab46
--- /dev/null
+++ b/openhands/cli/pt_style.py
@@ -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])
diff --git a/openhands/cli/settings.py b/openhands/cli/settings.py
index c81bcfea88..3a7a3015c8 100644
--- a/openhands/cli/settings.py
+++ b/openhands/cli/settings.py
@@ -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
diff --git a/openhands/cli/tui.py b/openhands/cli/tui.py
index 684207241d..6b00e6298e 100644
--- a/openhands/cli/tui.py
+++ b/openhands/cli/tui.py
@@ -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',