Coverage for openhcs/textual_tui/widgets/different_values_input.py: 0.0%
34 statements
« prev ^ index » next coverage.py v7.10.3, created at 2025-08-14 05:57 +0000
« prev ^ index » next coverage.py v7.10.3, created at 2025-08-14 05:57 +0000
1"""Special input widget for handling different values across multiple configurations."""
3from typing import Any, Optional
4from textual.widgets import Input
5from textual.events import Click
8class DifferentValuesInput(Input):
9 """Special input widget that shows 'DIFFERENT VALUES' and handles click-to-default behavior.
11 This widget is used in multi-orchestrator configuration editing when a field has
12 different values across the selected orchestrators. It displays "DIFFERENT VALUES"
13 as a placeholder and allows the user to click to set it to the default value.
14 """
16 def __init__(
17 self,
18 default_value: Any,
19 field_name: str = "",
20 **kwargs
21 ):
22 """Initialize the DifferentValuesInput widget.
24 Args:
25 default_value: The default value to use when clicked
26 field_name: Name of the field (for debugging/logging)
27 **kwargs: Additional arguments passed to Input
28 """
29 # Set "DIFFERENT" as placeholder, empty value
30 kwargs.setdefault("placeholder", "DIFFERENT")
31 kwargs.setdefault("value", "")
33 super().__init__(**kwargs)
35 self.default_value = default_value
36 self.field_name = field_name
37 self.is_different_state = True
39 # No special styling - looks like normal input
41 def on_click(self, event: Click) -> None:
42 """Handle click event - set to default value if in different state."""
43 if self.is_different_state:
44 # Convert default value to string for display
45 self.value = str(self.default_value) if self.default_value is not None else ""
46 self.is_different_state = False
48 # Clear placeholder since we now have a value
49 self.placeholder = ""
51 # Focus the input for immediate editing
52 self.focus()
54 def reset_to_different(self) -> None:
55 """Reset the widget back to 'DIFFERENT' placeholder state."""
56 self.value = ""
57 self.placeholder = "DIFFERENT"
58 self.is_different_state = True
60 def set_value(self, value: Any) -> None:
61 """Set a specific value (not from click-to-default)."""
62 self.value = str(value) if value is not None else ""
63 self.is_different_state = False
64 self.placeholder = ""
66 @property
67 def current_state(self) -> str:
68 """Get the current state of the widget."""
69 if self.is_different_state:
70 return "different"
71 elif self.value == str(self.default_value):
72 return "default"
73 else:
74 return "modified"
77class DifferentValuesInputCSS:
78 """CSS styles for DifferentValuesInput widget."""
80 CSS = """
81 .different-values-input {
82 border: dashed $warning;
83 color: $warning;
84 background: $surface;
85 }
87 .different-values-input:hover {
88 border: solid $warning;
89 background: $warning 20%;
90 }
92 .different-values-input:focus {
93 border: solid $warning;
94 background: $warning 30%;
95 }
97 .modified-from-different {
98 border: solid $success;
99 color: $text;
100 background: $success 10%;
101 }
103 .user-modified {
104 border: solid $primary;
105 color: $text;
106 background: $primary 10%;
107 }
108 """