From 8a432f8f8445b7bc4ba726ffa3cee71cdce2066d Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Mon, 17 Feb 2025 16:31:45 +0000 Subject: [PATCH 01/15] :sparkles: Add quit as a command for the command line --- ChangeLog.md | 1 + src/hike/widgets/command_line/quit.py | 40 +++++++++++++++++++++++++ src/hike/widgets/command_line/widget.py | 2 ++ 3 files changed, 43 insertions(+) create mode 100644 src/hike/widgets/command_line/quit.py diff --git a/ChangeLog.md b/ChangeLog.md index b793fa9..689d35a 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -8,6 +8,7 @@ ([#15](https://github.com/davep/hike/pull/15)) - Made `chdir` a lot less fussy about the path given. ([#18](https://github.com/davep/hike/pull/18)) +- Added `quit` as a command that the comment line understands. ## v0.2.0 diff --git a/src/hike/widgets/command_line/quit.py b/src/hike/widgets/command_line/quit.py new file mode 100644 index 0000000..9f2ab84 --- /dev/null +++ b/src/hike/widgets/command_line/quit.py @@ -0,0 +1,40 @@ +"""Provides the command for quitting the application.""" + +############################################################################## +# Textual imports. +from textual.widget import Widget + +############################################################################## +# Textual enhanced imports. +from textual_enhanced.commands import Quit + +############################################################################## +# Local imports. +from .base_command import InputCommand + + +############################################################################## +class QuitCommand(InputCommand): + """Quit the application""" + + COMMAND = "`quit`" + ALIASES = "`q`" + + @classmethod + def handle(cls, text: str, for_widget: Widget) -> bool: + """Handle the command. + + Args: + text: The text of the command. + for_widget: The widget to handle the command for. + + Returns: + `True` if the command was handled; `False` if not. + """ + if f"`{text.strip().lower()}`" in (cls.COMMAND, cls.ALIASES): + for_widget.post_message(Quit()) + return True + return False + + +### quit.py ends here diff --git a/src/hike/widgets/command_line/widget.py b/src/hike/widgets/command_line/widget.py index 4254295..1839304 100644 --- a/src/hike/widgets/command_line/widget.py +++ b/src/hike/widgets/command_line/widget.py @@ -39,6 +39,7 @@ OpenFromGitLab, ) from .open_url import OpenURLCommand +from .quit import QuitCommand ############################################################################## COMMANDS: Final[tuple[type[InputCommand], ...]] = ( @@ -53,6 +54,7 @@ OpenFromCodeberg, OpenFromGitHub, OpenFromGitLab, + QuitCommand, ) """The commands used for the input.""" From 1628dd6e4e63d4f81d4b12899cc9bfdb66b74d5e Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Mon, 17 Feb 2025 16:32:59 +0000 Subject: [PATCH 02/15] :art: Code tidy --- src/hike/widgets/command_line/open_url.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/hike/widgets/command_line/open_url.py b/src/hike/widgets/command_line/open_url.py index 8290448..f40e489 100644 --- a/src/hike/widgets/command_line/open_url.py +++ b/src/hike/widgets/command_line/open_url.py @@ -8,10 +8,9 @@ # Textual imports. from textual.widget import Widget -from ...data import looks_urllike - ############################################################################## # Local imports. +from ...data import looks_urllike from ...messages import OpenLocation from .base_command import InputCommand From 0e62674c7d3033e6fdfbc97e0bd63520284bd5e4 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Mon, 17 Feb 2025 17:09:33 +0000 Subject: [PATCH 03/15] :sparkles: Add some useful support code to the base command line input I'd had a couple of ways of parsing commands in a couple of the classes; this brings it all together in a more simple way. --- src/hike/widgets/command_line/base_command.py | 32 ++++++++++ tests/unit/test_command_line_commands.py | 60 +++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 tests/unit/test_command_line_commands.py diff --git a/src/hike/widgets/command_line/base_command.py b/src/hike/widgets/command_line/base_command.py index fb78b7f..6cd7a86 100644 --- a/src/hike/widgets/command_line/base_command.py +++ b/src/hike/widgets/command_line/base_command.py @@ -40,5 +40,37 @@ def handle(cls, text: str, for_widget: Widget) -> bool: """ return False + @staticmethod + def split_command(text: str) -> tuple[str, str]: + """Split the command for further testing. + + Args: + text: The text of the command. + + Returns: + The command and its tail. + """ + command, _, tail = text.strip().partition(" ") + return command.strip(), tail.strip() + + @classmethod + def is_command(cls, command: str) -> bool: + """Does the given command appear to be a match? + + Args: + command: The command to test. + + Returns: + `True` if the given command seems to be a match, `False` if not. + """ + # Build up all the possible matches. These are built from the main + # command and also the aliases. By convention the code will often + # use `code` fences for commands, and the aliases will be a comma + # list, so we clean that up as we go... + return command.strip().lower() in ( + candidate.strip().lower().removeprefix("`").removesuffix("`") + for candidate in (cls.COMMAND, *cls.ALIASES.split(",")) + ) + ### base_command.py ends here diff --git a/tests/unit/test_command_line_commands.py b/tests/unit/test_command_line_commands.py new file mode 100644 index 0000000..885ed88 --- /dev/null +++ b/tests/unit/test_command_line_commands.py @@ -0,0 +1,60 @@ +"""Tests for the command line command matching code.""" + +############################################################################## +# Pytest imports. +from pytest import mark + +############################################################################## +# Local imports. +from hike.widgets.command_line.base_command import InputCommand + + +############################################################################## +class ExampleCommand(InputCommand): + COMMAND = "`test`" + ALIASES = "`t`, `tester`, `testing`" + + +############################################################################## +@mark.parametrize( + "look_for, found", + ( + ("test", True), + ("t", True), + ("tester", True), + ("testing", True), + ("TEST", True), + ("T", True), + ("TESTER", True), + ("TESTING", True), + (" TeST ", True), + (" T ", True), + (" TEstER ", True), + (" TESting ", True), + ("", False), + ("te", False), + ), +) +def test_is_command(look_for: str, found: bool) -> None: + """We should be able to find if a command is a match.""" + assert ExampleCommand.is_command(look_for) is found + + +############################################################################## +@mark.parametrize( + "split, result", + ( + ("", ("", "")), + ("test", ("test", "")), + (" test ", ("test", "")), + ("test test", ("test", "test")), + (" test test ", ("test", "test")), + ("test test test test", ("test", "test test test")), + ), +) +def test_split_command(split: str, result: tuple[str, str]) -> None: + """The command splitting code should work as expected.""" + assert ExampleCommand.split_command(split) == result + + +### test_command_line_commands.py ends here From 38ce4746e8ade8b2243ffd85a435d880e3339d8d Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Mon, 17 Feb 2025 17:10:38 +0000 Subject: [PATCH 04/15] :sparkles: Add a quit command to the command line --- src/hike/widgets/command_line/quit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hike/widgets/command_line/quit.py b/src/hike/widgets/command_line/quit.py index 9f2ab84..bb860f8 100644 --- a/src/hike/widgets/command_line/quit.py +++ b/src/hike/widgets/command_line/quit.py @@ -31,7 +31,7 @@ def handle(cls, text: str, for_widget: Widget) -> bool: Returns: `True` if the command was handled; `False` if not. """ - if f"`{text.strip().lower()}`" in (cls.COMMAND, cls.ALIASES): + if cls.is_command(text): for_widget.post_message(Quit()) return True return False From 24f7251db3e464432a12d46df923b5a6e2f87630 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Mon, 17 Feb 2025 17:11:13 +0000 Subject: [PATCH 05/15] :hammer: Tidy up the forge command --- .../widgets/command_line/open_from_forge.py | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/src/hike/widgets/command_line/open_from_forge.py b/src/hike/widgets/command_line/open_from_forge.py index 702002f..44f92fc 100644 --- a/src/hike/widgets/command_line/open_from_forge.py +++ b/src/hike/widgets/command_line/open_from_forge.py @@ -53,20 +53,6 @@ class OpenFromForgeCommand(InputCommand): `main` branch and then `master`. """ - @staticmethod - def split_command(text: str) -> tuple[str, str]: - """Split the command for further testing. - - Args: - text: The text of the command. - - Returns: - The command and its arguments. - """ - if len(candidate := text.split(maxsplit=1)) == 1: - return candidate[0], "" - return (candidate[0], candidate[1]) if candidate else ("", "") - @classmethod def maybe_request(cls, arguments: str, for_widget: Widget) -> bool: """Maybe request a file be opened from the given forge. @@ -115,9 +101,7 @@ def handle(cls, text: str, for_widget: Widget) -> bool: `True` if the command was handled; `False` if not. """ command, arguments = cls.split_command(text) - return f"`{command}`" in (cls.COMMAND, cls.ALIASES) and cls.maybe_request( - arguments, for_widget - ) + return cls.is_command(command) and cls.maybe_request(arguments, for_widget) ############################################################################## From 931453094ed3fb17c85ebb14de361edc2b88c7ad Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Mon, 17 Feb 2025 17:11:33 +0000 Subject: [PATCH 06/15] :hammer: Tidy up the chdir command Also add some more aliases that people might type. --- .../widgets/command_line/change_directory.py | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/hike/widgets/command_line/change_directory.py b/src/hike/widgets/command_line/change_directory.py index 9e3e634..aa6fd71 100644 --- a/src/hike/widgets/command_line/change_directory.py +++ b/src/hike/widgets/command_line/change_directory.py @@ -3,8 +3,6 @@ ############################################################################## # Python imports. from pathlib import Path -from re import Pattern, compile -from typing import Final ############################################################################## # Textual imports. @@ -15,17 +13,13 @@ from ...messages import SetLocalViewRoot from .base_command import InputCommand -############################################################################## -CHDIR: Final[Pattern[str]] = compile(r"^\s*(chdir|cd)\s+(?P.+)$") -"""Regular expression for matching the command.""" - ############################################################################## class ChangeDirectoryCommand(InputCommand): """Change the root directory of the local file browser""" COMMAND = "`chdir`" - ALIASES = "`cd`" + ALIASES = "`cd`, `dir`, `ls`" ARGUMENTS = "``" @classmethod @@ -39,13 +33,14 @@ def handle(cls, text: str, for_widget: Widget) -> bool: Returns: `True` if the command was handled; `False` if not. """ - if match := CHDIR.search(text): - if ( - match["directory"] - and (root := Path(match["directory"].strip()).expanduser()).is_dir() - ): - for_widget.post_message(SetLocalViewRoot(Path(root).resolve())) - return True + command, directory = cls.split_command(text) + if ( + cls.is_command(command) + and directory + and (root := Path(directory).expanduser()).is_dir() + ): + for_widget.post_message(SetLocalViewRoot(Path(root).resolve())) + return True return False From d71caed85d486c592080688b7db49c8b17be4d81 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Mon, 17 Feb 2025 17:12:32 +0000 Subject: [PATCH 07/15] :books: Update the ChangeLog --- ChangeLog.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index 689d35a..f547994 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -8,7 +8,8 @@ ([#15](https://github.com/davep/hike/pull/15)) - Made `chdir` a lot less fussy about the path given. ([#18](https://github.com/davep/hike/pull/18)) -- Added `quit` as a command that the comment line understands. +- Added `quit` as a command that the command line understands. +- Added `dir` and `ls` as aliases for `chdir`. ## v0.2.0 From d00355bc10fc17463fa7da0747785c8feb3379a8 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Mon, 17 Feb 2025 17:18:39 +0000 Subject: [PATCH 08/15] :books: Link the ChangeLog to the PR --- ChangeLog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index f547994..ac1009b 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -9,7 +9,9 @@ - Made `chdir` a lot less fussy about the path given. ([#18](https://github.com/davep/hike/pull/18)) - Added `quit` as a command that the command line understands. + ([#24](https://github.com/davep/hike/pull/24)) - Added `dir` and `ls` as aliases for `chdir`. + ([#24](https://github.com/davep/hike/pull/24)) ## v0.2.0 From 9856b7dce9062ca593438ecc4e44311c9febfeaf Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Tue, 18 Feb 2025 08:22:19 +0000 Subject: [PATCH 09/15] :sparkles: Add a command to jump to the table of contents --- ChangeLog.md | 2 ++ src/hike/widgets/command_line/contents.py | 37 +++++++++++++++++++++++ src/hike/widgets/command_line/widget.py | 2 ++ 3 files changed, 41 insertions(+) create mode 100644 src/hike/widgets/command_line/contents.py diff --git a/ChangeLog.md b/ChangeLog.md index ac1009b..cc0ab82 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -12,6 +12,8 @@ ([#24](https://github.com/davep/hike/pull/24)) - Added `dir` and `ls` as aliases for `chdir`. ([#24](https://github.com/davep/hike/pull/24)) +- Added `contents` as a command that the command line understands. + ([#24](https://github.com/davep/hike/pull/24)) ## v0.2.0 diff --git a/src/hike/widgets/command_line/contents.py b/src/hike/widgets/command_line/contents.py new file mode 100644 index 0000000..8959d20 --- /dev/null +++ b/src/hike/widgets/command_line/contents.py @@ -0,0 +1,37 @@ +"""Provides the command for jumping to the table of contents.""" + +############################################################################## +# Textual imports. +from textual.widget import Widget + +############################################################################## +# Local imports. +from ...commands import JumpToTableOfContents +from .base_command import InputCommand + + +############################################################################## +class ContentsCommand(InputCommand): + """Quit the application""" + + COMMAND = "`contents`" + ALIASES = "`c`, `toc`" + + @classmethod + def handle(cls, text: str, for_widget: Widget) -> bool: + """Handle the command. + + Args: + text: The text of the command. + for_widget: The widget to handle the command for. + + Returns: + `True` if the command was handled; `False` if not. + """ + if cls.is_command(text): + for_widget.post_message(JumpToTableOfContents()) + return True + return False + + +### contents.py ends here diff --git a/src/hike/widgets/command_line/widget.py b/src/hike/widgets/command_line/widget.py index 1839304..9db4e38 100644 --- a/src/hike/widgets/command_line/widget.py +++ b/src/hike/widgets/command_line/widget.py @@ -29,6 +29,7 @@ from ...types import CommandHistory from .base_command import InputCommand from .change_directory import ChangeDirectoryCommand +from .contents import ContentsCommand from .open_directory import OpenDirectoryCommand from .open_file import OpenFileCommand from .open_from_forge import ( @@ -54,6 +55,7 @@ OpenFromCodeberg, OpenFromGitHub, OpenFromGitLab, + ContentsCommand, QuitCommand, ) """The commands used for the input.""" From 83ae0f2ff5bf2d669051dce27640aa84f454009d Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Tue, 18 Feb 2025 08:56:10 +0000 Subject: [PATCH 10/15] :hammer: Give the more simple commands a common base class --- src/hike/widgets/command_line/contents.py | 37 ------------------- .../command_line/{quit.py => general.py} | 31 +++++++++++++--- src/hike/widgets/command_line/widget.py | 3 +- 3 files changed, 27 insertions(+), 44 deletions(-) delete mode 100644 src/hike/widgets/command_line/contents.py rename src/hike/widgets/command_line/{quit.py => general.py} (56%) diff --git a/src/hike/widgets/command_line/contents.py b/src/hike/widgets/command_line/contents.py deleted file mode 100644 index 8959d20..0000000 --- a/src/hike/widgets/command_line/contents.py +++ /dev/null @@ -1,37 +0,0 @@ -"""Provides the command for jumping to the table of contents.""" - -############################################################################## -# Textual imports. -from textual.widget import Widget - -############################################################################## -# Local imports. -from ...commands import JumpToTableOfContents -from .base_command import InputCommand - - -############################################################################## -class ContentsCommand(InputCommand): - """Quit the application""" - - COMMAND = "`contents`" - ALIASES = "`c`, `toc`" - - @classmethod - def handle(cls, text: str, for_widget: Widget) -> bool: - """Handle the command. - - Args: - text: The text of the command. - for_widget: The widget to handle the command for. - - Returns: - `True` if the command was handled; `False` if not. - """ - if cls.is_command(text): - for_widget.post_message(JumpToTableOfContents()) - return True - return False - - -### contents.py ends here diff --git a/src/hike/widgets/command_line/quit.py b/src/hike/widgets/command_line/general.py similarity index 56% rename from src/hike/widgets/command_line/quit.py rename to src/hike/widgets/command_line/general.py index bb860f8..0e854bd 100644 --- a/src/hike/widgets/command_line/quit.py +++ b/src/hike/widgets/command_line/general.py @@ -1,7 +1,8 @@ -"""Provides the command for quitting the application.""" +"""Provides general application commands for the command line.""" ############################################################################## # Textual imports. +from textual.message import Message from textual.widget import Widget ############################################################################## @@ -10,15 +11,17 @@ ############################################################################## # Local imports. +from ...commands import JumpToTableOfContents from .base_command import InputCommand ############################################################################## -class QuitCommand(InputCommand): - """Quit the application""" +class GeneralCommand(InputCommand): + """Base class for general commands.""" COMMAND = "`quit`" ALIASES = "`q`" + MESSAGE: type[Message] @classmethod def handle(cls, text: str, for_widget: Widget) -> bool: @@ -32,9 +35,27 @@ def handle(cls, text: str, for_widget: Widget) -> bool: `True` if the command was handled; `False` if not. """ if cls.is_command(text): - for_widget.post_message(Quit()) + for_widget.post_message(cls.MESSAGE()) return True return False -### quit.py ends here +############################################################################## +class ContentsCommand(GeneralCommand): + """Jump to the table of contents""" + + COMMAND = "`contents`" + ALIASES = "`c`, `toc`" + MESSAGE = JumpToTableOfContents + + +############################################################################## +class QuitCommand(GeneralCommand): + """Quit the application""" + + COMMAND = "`quit`" + ALIASES = "`q`" + MESSAGE = Quit + + +### general.py ends here diff --git a/src/hike/widgets/command_line/widget.py b/src/hike/widgets/command_line/widget.py index 9db4e38..42d40b7 100644 --- a/src/hike/widgets/command_line/widget.py +++ b/src/hike/widgets/command_line/widget.py @@ -29,7 +29,7 @@ from ...types import CommandHistory from .base_command import InputCommand from .change_directory import ChangeDirectoryCommand -from .contents import ContentsCommand +from .general import ContentsCommand, QuitCommand from .open_directory import OpenDirectoryCommand from .open_file import OpenFileCommand from .open_from_forge import ( @@ -40,7 +40,6 @@ OpenFromGitLab, ) from .open_url import OpenURLCommand -from .quit import QuitCommand ############################################################################## COMMANDS: Final[tuple[type[InputCommand], ...]] = ( From df58b549b4ec025c52c140d8f2236f646dd9e293 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Tue, 18 Feb 2025 08:58:58 +0000 Subject: [PATCH 11/15] :sparkles: Add a command line command for jumping to bookmarks --- src/hike/widgets/command_line/general.py | 11 ++++++++++- src/hike/widgets/command_line/widget.py | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/hike/widgets/command_line/general.py b/src/hike/widgets/command_line/general.py index 0e854bd..6d3c4d2 100644 --- a/src/hike/widgets/command_line/general.py +++ b/src/hike/widgets/command_line/general.py @@ -11,7 +11,7 @@ ############################################################################## # Local imports. -from ...commands import JumpToTableOfContents +from ...commands import JumpToBookmarks, JumpToTableOfContents from .base_command import InputCommand @@ -40,6 +40,15 @@ def handle(cls, text: str, for_widget: Widget) -> bool: return False +############################################################################## +class BookmarksCommand(GeneralCommand): + """Jump to the bookmarks""" + + COMMAND = "`bookmarks`" + ALIASES = "`b`, `bm`" + MESSAGE = JumpToBookmarks + + ############################################################################## class ContentsCommand(GeneralCommand): """Jump to the table of contents""" diff --git a/src/hike/widgets/command_line/widget.py b/src/hike/widgets/command_line/widget.py index 42d40b7..6837d1f 100644 --- a/src/hike/widgets/command_line/widget.py +++ b/src/hike/widgets/command_line/widget.py @@ -29,7 +29,7 @@ from ...types import CommandHistory from .base_command import InputCommand from .change_directory import ChangeDirectoryCommand -from .general import ContentsCommand, QuitCommand +from .general import BookmarksCommand, ContentsCommand, QuitCommand from .open_directory import OpenDirectoryCommand from .open_file import OpenFileCommand from .open_from_forge import ( @@ -49,6 +49,7 @@ OpenDirectoryCommand, OpenURLCommand, # Once the above are out of the way the order doesn't matter so much. + BookmarksCommand, ChangeDirectoryCommand, OpenFromBitbucket, OpenFromCodeberg, From 6f40b5a07b4d8f11071ce223f7aa8bd0b7b91197 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Tue, 18 Feb 2025 09:02:19 +0000 Subject: [PATCH 12/15] :sparkles: Add a command line command for jumping to history --- src/hike/widgets/command_line/general.py | 11 ++++++++++- src/hike/widgets/command_line/widget.py | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/hike/widgets/command_line/general.py b/src/hike/widgets/command_line/general.py index 6d3c4d2..7df5186 100644 --- a/src/hike/widgets/command_line/general.py +++ b/src/hike/widgets/command_line/general.py @@ -11,7 +11,7 @@ ############################################################################## # Local imports. -from ...commands import JumpToBookmarks, JumpToTableOfContents +from ...commands import JumpToBookmarks, JumpToHistory, JumpToTableOfContents from .base_command import InputCommand @@ -58,6 +58,15 @@ class ContentsCommand(GeneralCommand): MESSAGE = JumpToTableOfContents +############################################################################## +class HistoryCommand(GeneralCommand): + """Jump to the browsing history""" + + COMMAND = "`history`" + ALIASES = "`h`" + MESSAGE = JumpToHistory + + ############################################################################## class QuitCommand(GeneralCommand): """Quit the application""" diff --git a/src/hike/widgets/command_line/widget.py b/src/hike/widgets/command_line/widget.py index 6837d1f..26c3eab 100644 --- a/src/hike/widgets/command_line/widget.py +++ b/src/hike/widgets/command_line/widget.py @@ -29,7 +29,7 @@ from ...types import CommandHistory from .base_command import InputCommand from .change_directory import ChangeDirectoryCommand -from .general import BookmarksCommand, ContentsCommand, QuitCommand +from .general import BookmarksCommand, ContentsCommand, HistoryCommand, QuitCommand from .open_directory import OpenDirectoryCommand from .open_file import OpenFileCommand from .open_from_forge import ( @@ -51,6 +51,7 @@ # Once the above are out of the way the order doesn't matter so much. BookmarksCommand, ChangeDirectoryCommand, + HistoryCommand, OpenFromBitbucket, OpenFromCodeberg, OpenFromGitHub, From 8d356e8f6f574ba81f291c682bd916f4c6b9ec4c Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Tue, 18 Feb 2025 09:03:15 +0000 Subject: [PATCH 13/15] :books: Updated the ChangeLog --- ChangeLog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index cc0ab82..34b5f4f 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -14,6 +14,10 @@ ([#24](https://github.com/davep/hike/pull/24)) - Added `contents` as a command that the command line understands. ([#24](https://github.com/davep/hike/pull/24)) +- Added `bookmarks` as a command that the command line understands. + ([#24](https://github.com/davep/hike/pull/24)) +- Added `history` as a command that the command line understands. + ([#24](https://github.com/davep/hike/pull/24)) ## v0.2.0 From 598a83e50fb9bd3e15caf65f5f823af98f2d8f7c Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Tue, 18 Feb 2025 09:05:52 +0000 Subject: [PATCH 14/15] :sparkles: Add a command line command for jumping the local file browser --- ChangeLog.md | 2 ++ src/hike/widgets/command_line/general.py | 16 +++++++++++++++- src/hike/widgets/command_line/widget.py | 9 ++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 34b5f4f..7d273d5 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -18,6 +18,8 @@ ([#24](https://github.com/davep/hike/pull/24)) - Added `history` as a command that the command line understands. ([#24](https://github.com/davep/hike/pull/24)) +- Added `local` as a command that the command line understands. + ([#24](https://github.com/davep/hike/pull/24)) ## v0.2.0 diff --git a/src/hike/widgets/command_line/general.py b/src/hike/widgets/command_line/general.py index 7df5186..32640c5 100644 --- a/src/hike/widgets/command_line/general.py +++ b/src/hike/widgets/command_line/general.py @@ -11,7 +11,12 @@ ############################################################################## # Local imports. -from ...commands import JumpToBookmarks, JumpToHistory, JumpToTableOfContents +from ...commands import ( + JumpToBookmarks, + JumpToHistory, + JumpToLocalBrowser, + JumpToTableOfContents, +) from .base_command import InputCommand @@ -67,6 +72,15 @@ class HistoryCommand(GeneralCommand): MESSAGE = JumpToHistory +############################################################################## +class LocalCommand(GeneralCommand): + """Jump to the local file browser""" + + COMMAND = "`local`" + ALIASES = "`l`" + MESSAGE = JumpToLocalBrowser + + ############################################################################## class QuitCommand(GeneralCommand): """Quit the application""" diff --git a/src/hike/widgets/command_line/widget.py b/src/hike/widgets/command_line/widget.py index 26c3eab..59165c5 100644 --- a/src/hike/widgets/command_line/widget.py +++ b/src/hike/widgets/command_line/widget.py @@ -29,7 +29,13 @@ from ...types import CommandHistory from .base_command import InputCommand from .change_directory import ChangeDirectoryCommand -from .general import BookmarksCommand, ContentsCommand, HistoryCommand, QuitCommand +from .general import ( + BookmarksCommand, + ContentsCommand, + HistoryCommand, + LocalCommand, + QuitCommand, +) from .open_directory import OpenDirectoryCommand from .open_file import OpenFileCommand from .open_from_forge import ( @@ -52,6 +58,7 @@ BookmarksCommand, ChangeDirectoryCommand, HistoryCommand, + LocalCommand, OpenFromBitbucket, OpenFromCodeberg, OpenFromGitHub, From fd82bf89ede92b9046bebac3208b9aa597b88d1b Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Tue, 18 Feb 2025 09:17:35 +0000 Subject: [PATCH 15/15] :books: Improve the look of the command line help --- src/hike/widgets/command_line/open_from_forge.py | 9 +++++---- src/hike/widgets/command_line/widget.py | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/hike/widgets/command_line/open_from_forge.py b/src/hike/widgets/command_line/open_from_forge.py index 44f92fc..a3abfbd 100644 --- a/src/hike/widgets/command_line/open_from_forge.py +++ b/src/hike/widgets/command_line/open_from_forge.py @@ -11,6 +11,7 @@ ############################################################################## # Local imports. +from ...data import load_configuration from ...messages import OpenFromForge from .base_command import InputCommand @@ -19,7 +20,7 @@ class OpenFromForgeCommand(InputCommand): """Base class for commands that open a file from a forge.""" - ARGUMENTS = "` [:] []`" + ARGUMENTS = "``¹" WITHOUT_BRANCH: Final[Pattern[str]] = compile( r"^(?P[^/ ]+)[/ ](?P[^ :]+)(?: +(?P[^ ]+))?$" @@ -37,7 +38,7 @@ class OpenFromForgeCommand(InputCommand): URL_FORMAT = "" """The format of the raw URL for the forge.""" - HELP = """ + HELP = f""" | Format | Effect | | -- | -- | | `/` | Open `README.md` from a repository | @@ -49,8 +50,8 @@ class OpenFromForgeCommand(InputCommand): | `/: ` | Open a specific file from a specific branch of a repository | | ` : ` | Open a specific file from a specific branch of a repository | - If `` is omitted the requested file is looked for first in the - `main` branch and then `master`. + If `` is omitted the requested file is looked in the following branches: + {', '.join(f'`{branch}`' for branch in load_configuration().main_branches)}. """ @classmethod diff --git a/src/hike/widgets/command_line/widget.py b/src/hike/widgets/command_line/widget.py index 59165c5..cd512f6 100644 --- a/src/hike/widgets/command_line/widget.py +++ b/src/hike/widgets/command_line/widget.py @@ -123,9 +123,9 @@ class CommandLine(Vertical): | Command | Aliases | Arguments | Description | | -- | -- | -- | -- | - {'\n '.join(command.help_text() for command in COMMANDS)} + {'\n '.join(sorted(command.help_text() for command in COMMANDS))} - ### Forge support + ### ¹Forge support The forge-oriented commands listed above accept a number of different ways of quickly specifying which file you want to view. Examples include: