diff --git a/CHANGES.txt b/CHANGES.txt index 2d0b634..dcefd3d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -4,6 +4,9 @@ Changelog 0.6.5 - ------------------ +- Allow customizing select key bindings. + [ggozad] + - Fixed erroneous OLLAMA_URL documentaion. [gerroon] diff --git a/README.md b/README.md index 1d887b2..c1441ca 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ the text-based terminal client for [Ollama](https://github.com/ollama/ollama). - [Customizing models](#customizing-models) - [Chat session storage](#chat-session-storage) - [App configuration](#app-configuration) + - [Key bindings](#key-bindings) - [Screenshots](#screenshots) - [License](#license) @@ -178,6 +179,22 @@ You can set the following options in the configuration file: `theme` can be either `dark` or `light`. `splash-screen` controls whether the splash screen is shown on startup. +### Key bindings + +We strive to have sane default key bindings, but there will always be cases where your terminal emulator or shell will interfere. You can customize select keybindings by editing the app config `config.json` file. The following are the defaults: + +```json +{ + ... + "keymap": { + "next.chat": "ctrl+tab", + "prev.chat": "ctrl+shift+tab", + "quit": "ctrl+q", + "newline": "shift+enter", + } +} +``` + ### Screenshots ![Splash](screenshots/splash.gif) The splash screen animation that greets users when they start oterm. diff --git a/pyproject.toml b/pyproject.toml index dd85f28..e3f236d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,7 @@ classifiers = [ ] requires-python = ">=3.10" dependencies = [ - "textual>=0.81.0", + "textual>=0.83.0", "typer>=0.12.4", "python-dotenv>=1.0.1", "aiosql>=11.1", diff --git a/src/oterm/app/oterm.py b/src/oterm/app/oterm.py index 1547bc3..7cd7258 100644 --- a/src/oterm/app/oterm.py +++ b/src/oterm/app/oterm.py @@ -3,6 +3,7 @@ from textual import on, work from textual.app import App, ComposeResult, SystemCommand +from textual.binding import Binding from textual.screen import Screen from textual.widgets import Footer, Header, TabbedContent, TabPane @@ -20,9 +21,9 @@ class OTerm(App): SUB_TITLE = "A terminal-based Ollama client." CSS_PATH = "oterm.tcss" BINDINGS = [ - ("ctrl+tab", "cycle_chat(+1)", "next chat"), - ("ctrl+shift+tab", "cycle_chat(-1)", "prev chat"), - ("ctrl+q", "quit", "quit"), + Binding("ctrl+tab", "cycle_chat(+1)", "next chat", id="next.chat"), + Binding("ctrl+shift+tab", "cycle_chat(-1)", "prev chat", id="prev.chat"), + Binding("ctrl+q", "quit", "quit", id="quit"), ] def get_system_commands(self, screen: Screen) -> Iterable[SystemCommand]: @@ -164,6 +165,11 @@ async def on_mount(self) -> None: self.dark = appConfig.get("theme") == "dark" saved_chats = await store.get_chats() + # Apply any remap of key bindings. + keymap = appConfig.get("keymap") + if keymap: + self.set_keymap(keymap) + async def on_splash_done(message) -> None: if not saved_chats: # Pyright suggests awaiting here which has bitten me twice diff --git a/src/oterm/app/widgets/prompt.py b/src/oterm/app/widgets/prompt.py index 7ebf1c8..e01c54d 100644 --- a/src/oterm/app/widgets/prompt.py +++ b/src/oterm/app/widgets/prompt.py @@ -36,6 +36,7 @@ class PostableTextArea(TextArea): show=True, key_display=None, priority=True, + id="newline", ), ] @@ -54,7 +55,7 @@ def action_submit(self) -> None: def action_newline(self) -> None: cur = self.cursor_location lines = self.text.split("\n") - lines[cur[0]] = lines[cur[0]][:cur[1]] + "\n" + lines[cur[0]][cur[1]:] + lines[cur[0]] = lines[cur[0]][: cur[1]] + "\n" + lines[cur[0]][cur[1] :] self.text = "\n".join(lines) self.cursor_location = (cur[0] + 1, 0) @@ -68,6 +69,7 @@ class PastableInput(Input): show=True, key_display=None, priority=True, + id="toggle.multiline", ), ] @@ -92,7 +94,7 @@ class FlexibleInput(Widget): text = reactive("") BINDINGS = [ - ("ctrl+i", "add_image", "add image"), + Binding("ctrl+i", "add_image", "add image", id="add.image"), ] @dataclass diff --git a/tests/test_ollama_api.py b/tests/test_ollama_api.py index f5574c0..6059915 100644 --- a/tests/test_ollama_api.py +++ b/tests/test_ollama_api.py @@ -12,7 +12,6 @@ def test_list(): def test_show(): llm = OllamaLLM() response = llm.show("llama3.2") - print(response.keys()) for key in [ "modelfile", "parameters", diff --git a/uv.lock b/uv.lock index e32377a..12e5ba8 100644 --- a/uv.lock +++ b/uv.lock @@ -618,7 +618,7 @@ requires-dist = [ { name = "pyperclip", specifier = ">=1.9.0" }, { name = "python-dotenv", specifier = ">=1.0.1" }, { name = "rich-pixels", specifier = ">=3.0.1" }, - { name = "textual", specifier = ">=0.81.0" }, + { name = "textual", specifier = ">=0.83.0" }, { name = "textualeffects", specifier = ">=0.1.3" }, { name = "typer", specifier = ">=0.12.4" }, ] @@ -887,7 +887,7 @@ wheels = [ [[package]] name = "textual" -version = "0.81.0" +version = "0.83.0" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "markdown-it-py", extra = ["linkify", "plugins"] }, @@ -895,9 +895,9 @@ dependencies = [ { name = "rich" }, { name = "typing-extensions" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/2c/f0/b530868b21d68fd27a8a68f7511ef8573e0d63b359004c50da7b36b6c7b7/textual-0.81.0.tar.gz", hash = "sha256:b438f7e6bb143fdec379170ccc6709a32d273bd998e70179537109263de7c818", size = 1398749 } +sdist = { url = "https://files.pythonhosted.org/packages/cf/0b/58ec0dbcd92a5121fdae972f09de71b5bc38d389bab53a638e24349f904d/textual-0.83.0.tar.gz", hash = "sha256:fc3b97796092d9c7e685e5392f38f3eb2007ffe1b3b1384dee6d3f10d256babd", size = 1449378 } wheels = [ - { url = "https://files.pythonhosted.org/packages/1f/a1/491750a84d9d0982f49ed49f1227ee32cf32ef0e287811e154cc79e64827/textual-0.81.0-py3-none-any.whl", hash = "sha256:5f94e3bf185a1693c31f5e2bcbc413c8ed093a53abc96a956c65322d48f9543c", size = 596420 }, + { url = "https://files.pythonhosted.org/packages/18/39/6cec279ca41dcacb1c92ad6e4467c9e88db4eb4d2f02300c66218ec432de/textual-0.83.0-py3-none-any.whl", hash = "sha256:d6efc1e5c54086fd0a4fe274f18b5638ca24a69325c07e1b4400a7d0a1a14c55", size = 600387 }, ] [[package]]