Coverage for src/lilbee/cli/tui/screens/sessions.py: 100%

43 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-08-14 11:46 +0000

1"""Full-screen Sessions view: browse and manage saved conversations.""" 

2 

3from __future__ import annotations 

4 

5from typing import TYPE_CHECKING, ClassVar 

6 

7from textual import on 

8from textual.app import ComposeResult 

9from textual.binding import BindingType 

10from textual.screen import Screen 

11 

12from lilbee.cli.tui.browse_bindings import BROWSE_LIST_BINDINGS, browse_back_bindings 

13from lilbee.cli.tui.widgets.session_list import SessionListPanel 

14 

15if TYPE_CHECKING: 

16 from lilbee.cli.tui.app import LilbeeApp 

17 

18 

19class SessionsScreen(Screen[None]): 

20 """Manage saved conversations: filter, resume, rename, delete, new.""" 

21 

22 app: LilbeeApp # type: ignore[assignment] 

23 

24 CSS_PATH = "sessions.tcss" 

25 

26 BINDINGS: ClassVar[list[BindingType]] = [ 

27 *browse_back_bindings(), 

28 *BROWSE_LIST_BINDINGS, 

29 ] 

30 

31 def compose(self) -> ComposeResult: 

32 from textual.widgets import Footer 

33 

34 from lilbee.cli.tui.widgets.bottom_bars import BottomBars 

35 from lilbee.cli.tui.widgets.status_bar import ViewTabs 

36 from lilbee.cli.tui.widgets.task_bar import TaskBar 

37 from lilbee.cli.tui.widgets.top_bars import TopBars 

38 

39 with TopBars(): 

40 yield ViewTabs() 

41 yield SessionListPanel(focus_filter=False) 

42 with BottomBars(): 

43 yield TaskBar() 

44 yield Footer() 

45 

46 def action_go_back(self) -> None: 

47 self.app.go_back() 

48 

49 def action_cursor_down(self) -> None: 

50 self.query_one(SessionListPanel).action_cursor_down() 

51 

52 def action_cursor_up(self) -> None: 

53 self.query_one(SessionListPanel).action_cursor_up() 

54 

55 def action_jump_top(self) -> None: 

56 self.query_one(SessionListPanel).jump_to(0) 

57 

58 def action_jump_bottom(self) -> None: 

59 self.query_one(SessionListPanel).jump_to(-1) 

60 

61 @on(SessionListPanel.Resumed) 

62 def _on_resumed(self, event: SessionListPanel.Resumed) -> None: 

63 self.app.resume_session(event.session_id) 

64 

65 @on(SessionListPanel.NewChat) 

66 def _on_new_chat(self, _event: SessionListPanel.NewChat) -> None: 

67 self.app.new_chat() 

68 

69 @on(SessionListPanel.CloseRequested) 

70 def _on_close(self, _event: SessionListPanel.CloseRequested) -> None: 

71 # Same semantics as q: return to where the user came from. 

72 self.app.go_back()