Skip to content

Commit 65f7444

Browse files
authored
🔀 Merge pull request #5 from davep/movable-input
Allow moving the command line to the top of the screen
2 parents 5a7c75f + 2606ff3 commit 65f7444

File tree

7 files changed

+62
-8
lines changed

7 files changed

+62
-8
lines changed

ChangeLog.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
([#2](https://github.com/davep/hike/pull/2))
99
- The suggester for the command line now prefers newer history entries over
1010
older. ([#3](https://github.com/davep/hike/pull/3))
11+
- Add the ability to move the command line to the top of the screen.
12+
([#5](https://github.com/davep/hike/pull/5))
1113

1214
## v0.1.0
1315

src/hike/commands/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Local imports.
55
from .main import (
66
BookmarkLocation,
7+
ChangeCommandLineLocation,
78
ChangeNavigationSide,
89
JumpToCommandLine,
910
Reload,
@@ -24,6 +25,7 @@
2425
__all__ = [
2526
"Backward",
2627
"BookmarkLocation",
28+
"ChangeCommandLineLocation",
2729
"ChangeNavigationSide",
2830
"Forward",
2931
"JumpToBookmarks",

src/hike/commands/main.py

+7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ class JumpToCommandLine(Command):
2828
BINDING_KEY = "/"
2929

3030

31+
##############################################################################
32+
class ChangeCommandLineLocation(Command):
33+
"""Swap the position of the command line between top and bottom"""
34+
35+
BINDING_KEY = "ctrl+up, ctrl+down"
36+
37+
3138
##############################################################################
3239
class BookmarkLocation(Command):
3340
"""Bookmark the current location"""

src/hike/data/config.py

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class Configuration:
3131
markdown_extensions: list[str] = field(default_factory=lambda: [".md", ".markdown"])
3232
"""The file extensions to consider to be Markdown files."""
3333

34+
command_line_on_top: bool = False
35+
"""Should the command line live at the top of the screen?"""
36+
3437

3538
##############################################################################
3639
def configuration_file() -> Path:

src/hike/providers/main.py

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from ..commands import (
1616
Backward,
1717
BookmarkLocation,
18+
ChangeCommandLineLocation,
1819
ChangeNavigationSide,
1920
Forward,
2021
JumpToBookmarks,
@@ -40,6 +41,7 @@ def commands(self) -> CommandHits:
4041
"""
4142
yield Backward()
4243
yield BookmarkLocation()
44+
yield ChangeCommandLineLocation()
4345
yield ChangeNavigationSide()
4446
yield ChangeTheme()
4547
yield Forward()

src/hike/screens/main.py

+11
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from ..commands import (
2929
Backward,
3030
BookmarkLocation,
31+
ChangeCommandLineLocation,
3132
ChangeNavigationSide,
3233
Forward,
3334
JumpToBookmarks,
@@ -124,6 +125,7 @@ class Main(EnhancedScreen[None]):
124125
# Everything else.
125126
Backward,
126127
BookmarkLocation,
128+
ChangeCommandLineLocation,
127129
ChangeNavigationSide,
128130
Forward,
129131
JumpToBookmarks,
@@ -171,6 +173,7 @@ def on_mount(self) -> None:
171173
BookmarkCommands.bookmarks = bookmarks
172174
self.query_one(Viewer).history = load_history()
173175
self.query_one(CommandLine).history = load_command_history()
176+
self.query_one(CommandLine).dock_top = config.command_line_on_top
174177
if self._arguments.command:
175178
self.query_one(CommandLine).handle_input(" ".join(self._arguments.command))
176179

@@ -314,6 +317,14 @@ def action_change_navigation_side_command(self) -> None:
314317
with update_configuration() as config:
315318
config.navigation_on_right = navigation.dock_right
316319

320+
@on(ChangeCommandLineLocation)
321+
def action_change_command_line_location_command(self) -> None:
322+
"""Change the location of the command line."""
323+
command_line = self.query_one(CommandLine)
324+
command_line.dock_top = not command_line.dock_top
325+
with update_configuration() as config:
326+
config.command_line_on_top = command_line.dock_top
327+
317328
@on(JumpToCommandLine)
318329
def action_jump_to_command_line_command(self) -> None:
319330
"""Jump to the command line."""

src/hike/widgets/command_line/widget.py

+35-8
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
# Textual imports.
1414
from textual import on
1515
from textual.app import ComposeResult
16-
from textual.containers import Horizontal
16+
from textual.containers import Horizontal, Vertical
1717
from textual.message import Message
1818
from textual.reactive import var
1919
from textual.suggester import SuggestFromList
20-
from textual.widgets import Input, Label
20+
from textual.widgets import Input, Label, Rule
2121
from textual.widgets.input import Selection
2222

2323
##############################################################################
@@ -57,15 +57,17 @@
5757

5858

5959
##############################################################################
60-
class CommandLine(Horizontal):
60+
class CommandLine(Vertical):
6161
"""A command line for getting input from the user."""
6262

6363
DEFAULT_CSS = """
6464
CommandLine {
6565
height: 1;
66+
6667
Label, Input {
6768
color: $text-muted;
6869
}
70+
6971
&:focus-within {
7072
Label, Input {
7173
color: $text;
@@ -74,12 +76,28 @@ class CommandLine(Horizontal):
7476
text-style: bold;
7577
}
7678
}
79+
80+
Rule {
81+
height: 1;
82+
margin: 0 !important;
83+
color: $foreground 10%;
84+
display: none;
85+
}
86+
7787
Input, Input:focus {
7888
border: none;
7989
padding: 0;
8090
height: 1fr;
8191
background: transparent;
8292
}
93+
94+
&.--top {
95+
dock: top;
96+
height: 2;
97+
Rule {
98+
display: block;
99+
}
100+
}
83101
}
84102
"""
85103

@@ -123,24 +141,33 @@ class CommandLine(Horizontal):
123141
history: var[CommandHistory] = var(CommandHistory)
124142
"""The command line history."""
125143

144+
dock_top: var[bool] = var(False)
145+
"""Should the input dock to the top of the screen?"""
146+
126147
@property
127148
def _history_suggester(self) -> SuggestFromList:
128149
"""A suggester for the history of input."""
129150
return SuggestFromList(reversed(list(self.history)))
130151

131152
def compose(self) -> ComposeResult:
132153
"""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")
138161

139162
def _watch_history(self) -> None:
140163
"""React to history being updated."""
141164
if self.is_mounted:
142165
self.query_one(Input).suggester = self._history_suggester
143166

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+
144171
@dataclass
145172
class HistoryUpdated(Message):
146173
"""Message posted when the command history is updated."""

0 commit comments

Comments
 (0)