13
13
# Textual imports.
14
14
from textual import on
15
15
from textual .app import ComposeResult
16
- from textual .containers import Horizontal
16
+ from textual .containers import Horizontal , Vertical
17
17
from textual .message import Message
18
18
from textual .reactive import var
19
19
from textual .suggester import SuggestFromList
20
- from textual .widgets import Input , Label
20
+ from textual .widgets import Input , Label , Rule
21
21
from textual .widgets .input import Selection
22
22
23
23
##############################################################################
57
57
58
58
59
59
##############################################################################
60
- class CommandLine (Horizontal ):
60
+ class CommandLine (Vertical ):
61
61
"""A command line for getting input from the user."""
62
62
63
63
DEFAULT_CSS = """
64
64
CommandLine {
65
65
height: 1;
66
+
66
67
Label, Input {
67
68
color: $text-muted;
68
69
}
70
+
69
71
&:focus-within {
70
72
Label, Input {
71
73
color: $text;
@@ -74,12 +76,28 @@ class CommandLine(Horizontal):
74
76
text-style: bold;
75
77
}
76
78
}
79
+
80
+ Rule {
81
+ height: 1;
82
+ margin: 0 !important;
83
+ color: $foreground 10%;
84
+ display: none;
85
+ }
86
+
77
87
Input, Input:focus {
78
88
border: none;
79
89
padding: 0;
80
90
height: 1fr;
81
91
background: transparent;
82
92
}
93
+
94
+ &.--top {
95
+ dock: top;
96
+ height: 2;
97
+ Rule {
98
+ display: block;
99
+ }
100
+ }
83
101
}
84
102
"""
85
103
@@ -123,24 +141,33 @@ class CommandLine(Horizontal):
123
141
history : var [CommandHistory ] = var (CommandHistory )
124
142
"""The command line history."""
125
143
144
+ dock_top : var [bool ] = var (False )
145
+ """Should the input dock to the top of the screen?"""
146
+
126
147
@property
127
148
def _history_suggester (self ) -> SuggestFromList :
128
149
"""A suggester for the history of input."""
129
150
return SuggestFromList (reversed (list (self .history )))
130
151
131
152
def compose (self ) -> ComposeResult :
132
153
"""Compose the content of the widget."""
133
- yield Label ("> " )
134
- yield Input (
135
- placeholder = "Enter a directory, file, path or command" ,
136
- suggester = self ._history_suggester ,
137
- )
154
+ with Horizontal ():
155
+ yield Label ("> " )
156
+ yield Input (
157
+ placeholder = "Enter a directory, file, path or command" ,
158
+ suggester = self ._history_suggester ,
159
+ )
160
+ yield Rule (line_style = "heavy" )
138
161
139
162
def _watch_history (self ) -> None :
140
163
"""React to history being updated."""
141
164
if self .is_mounted :
142
165
self .query_one (Input ).suggester = self ._history_suggester
143
166
167
+ def _watch_dock_top (self ) -> None :
168
+ """React to being asked to dock input to the top."""
169
+ self .set_class (self .dock_top , "--top" )
170
+
144
171
@dataclass
145
172
class HistoryUpdated (Message ):
146
173
"""Message posted when the command history is updated."""
0 commit comments