Skip to content

Commit

Permalink
Cycle saved chats with Ctrl+Tab
Browse files Browse the repository at this point in the history
Ctrl+Tab cycles from left to right
Ctrl+Shift+Tab cycles from right to left
  • Loading branch information
yilmaz08 committed Aug 12, 2024
1 parent 82eebbe commit 1a37cbc
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions oterm/app/oterm.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class OTerm(App):
CSS_PATH = "oterm.tcss"
BINDINGS = [
("ctrl+n", "new_chat", "new"),
("ctrl+tab", "next_chat", "next chat"),
("ctrl+shift+tab", "prev_chat", "prev chat"),
("ctrl+t", "toggle_dark", "toggle theme"),
("ctrl+q", "quit", "quit"),
]
Expand All @@ -28,6 +30,32 @@ def action_toggle_dark(self) -> None:
async def action_quit(self) -> None:
return self.exit()

async def action_next_chat(self) -> None:
tabs = self.query_one(TabbedContent)
saved_chats = await self.store.get_chats()
if tabs.active_pane is None:
return
active_id = int(str(tabs.active_pane.id).split("-")[1])
for _chat in saved_chats:
if _chat[0] == active_id:
next_index = (saved_chats.index(_chat) + 1) % len(saved_chats)
next_id = saved_chats[next_index][0]
tabs.active = f"chat-{next_id}"
break

async def action_prev_chat(self) -> None:
tabs = self.query_one(TabbedContent)
saved_chats = await self.store.get_chats()
if tabs.active_pane is None:
return
active_id = int(str(tabs.active_pane.id).split("-")[1])
for _chat in saved_chats:
if _chat[0] == active_id:
prev_index = (saved_chats.index(_chat) - 1) % len(saved_chats)
prev_id = saved_chats[prev_index][0]
tabs.active = f"chat-{prev_id}"
break

def action_new_chat(self) -> None:
async def on_model_select(model_info: str | None) -> None:
if model_info is None:
Expand Down

0 comments on commit 1a37cbc

Please sign in to comment.