Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Allow customizing select key bindings. #131

Merged
merged 2 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changelog
0.6.5 -
------------------

- Allow customizing select key bindings.
[ggozad]

- Fixed erroneous OLLAMA_URL documentaion.
[gerroon]

Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 9 additions & 3 deletions src/oterm/app/oterm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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]:
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/oterm/app/widgets/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class PostableTextArea(TextArea):
show=True,
key_display=None,
priority=True,
id="newline",
),
]

Expand All @@ -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)

Expand All @@ -68,6 +69,7 @@ class PastableInput(Input):
show=True,
key_display=None,
priority=True,
id="toggle.multiline",
),
]

Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion tests/test_ollama_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.