Coverage for src/lilbee/cli/tui/widgets/profile_line.py: 100%

31 statements  

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

1"""The line above the Settings tabs: the active profile and how many values you set.""" 

2 

3from __future__ import annotations 

4 

5from typing import TYPE_CHECKING, ClassVar 

6 

7from textual import events 

8from textual.app import ComposeResult 

9from textual.binding import Binding, BindingType 

10from textual.containers import Horizontal 

11from textual.message import Message 

12from textual.widgets import Static 

13 

14from lilbee.cli.tui import messages as msg 

15 

16if TYPE_CHECKING: 

17 from lilbee.cli.tui.screens.profile_tab import ProfileSnapshot 

18 

19 

20class ProfileLinePill(Static, can_focus=True): 

21 """The profile's name; Enter, Space or a click jumps to the Profile tab.""" 

22 

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

24 Binding("enter", "jump", "Profile tab"), 

25 Binding("space", "jump", "Profile tab", show=False), 

26 ] 

27 

28 class Jump(Message): 

29 """Asks the settings screen to show the Profile tab.""" 

30 

31 def action_jump(self) -> None: 

32 self.post_message(self.Jump()) 

33 

34 def on_click(self, event: events.Click) -> None: 

35 event.stop() 

36 self.action_jump() 

37 

38 

39class ProfileLine(Horizontal): 

40 """Shows the active profile, the count of your values, and a warning when its file is off.""" 

41 

42 def compose(self) -> ComposeResult: 

43 yield Static(msg.PROFILE_LINE_LABEL, id="profile-line-label") 

44 yield ProfileLinePill("", id="profile-line-name", markup=False) 

45 yield Static("", id="profile-line-count") 

46 yield Static("", id="profile-line-status") 

47 

48 def show(self, snapshot: ProfileSnapshot) -> None: 

49 """Fill the line from *snapshot*.""" 

50 self.query_one("#profile-line-name", ProfileLinePill).update(snapshot.active.name) 

51 count = self.query_one("#profile-line-count", Static) 

52 count.update(msg.profile_count_text(len(snapshot.active.changes))) 

53 status = self.query_one("#profile-line-status", Static) 

54 status_text = msg.PROFILE_STATUS_PILL[snapshot.active.status] 

55 status.update(status_text) 

56 status.display = bool(status_text)