Finish the tab bar for the themes kitten
This commit is contained in:
parent
92a9b71f21
commit
ba85ca1991
@ -19,7 +19,7 @@ from kitty.utils import ScreenSize
|
|||||||
|
|
||||||
from ..tui.handler import Handler
|
from ..tui.handler import Handler
|
||||||
from ..tui.loop import Loop
|
from ..tui.loop import Loop
|
||||||
from ..tui.operations import styled, color_code
|
from ..tui.operations import styled
|
||||||
from .collection import Theme, Themes, load_themes
|
from .collection import Theme, Themes, load_themes
|
||||||
|
|
||||||
|
|
||||||
@ -202,40 +202,40 @@ class ThemesHandler(Handler):
|
|||||||
|
|
||||||
# Theme browsing {{{
|
# Theme browsing {{{
|
||||||
def draw_tab_bar(self) -> None:
|
def draw_tab_bar(self) -> None:
|
||||||
bar_bg = self.current_opts.tab_bar_background or self.current_opts.background
|
self.print(styled(' ' * self.screen_size.cols, reverse=True), end='\r')
|
||||||
self.cmd.sgr(color_code(bar_bg, base=40))
|
|
||||||
self.print(' ' * self.screen_size.cols, end='\r')
|
|
||||||
|
|
||||||
def draw_tab(text: str, name: str, sc: str) -> None:
|
def draw_tab(text: str, name: str, acc_idx: int = 0) -> None:
|
||||||
is_active = name == self.current_category
|
is_active = name == self.current_category
|
||||||
text = f'{sc}: {text}'
|
|
||||||
if is_active:
|
if is_active:
|
||||||
text = f'{text} ({len(self.themes_list)})'
|
text = styled(f'{text} #{len(self.themes_list)}', italic=True)
|
||||||
fg, bg = self.current_opts.active_tab_foreground, self.current_opts.active_tab_background
|
|
||||||
else:
|
else:
|
||||||
fg, bg = self.current_opts.inactive_tab_foreground, self.current_opts.inactive_tab_background
|
text = text[:acc_idx] + styled(text[acc_idx], underline='straight', underline_color='red', bold=True, fg_intense=True) + text[acc_idx+1:]
|
||||||
|
|
||||||
def draw_sep(which: str) -> None:
|
self.write(styled(f' {text} ', reverse=not is_active))
|
||||||
self.write(styled(which, fg=bar_bg, bg=bg))
|
|
||||||
self.cmd.sgr(color_code(fg), color_code(bg, base=40))
|
|
||||||
|
|
||||||
draw_sep('')
|
draw_tab('All', 'all')
|
||||||
self.write(f' {text} ')
|
draw_tab('Dark', 'dark')
|
||||||
draw_sep('')
|
draw_tab('Light', 'light')
|
||||||
|
draw_tab('Recent', 'recent')
|
||||||
draw_tab('All', 'all', 'F1')
|
self.cmd.sgr('0')
|
||||||
draw_tab('Dark', 'dark', 'F2')
|
self.print()
|
||||||
draw_tab('Light', 'light', 'F3')
|
|
||||||
draw_tab('Recent', 'recent', 'F4')
|
|
||||||
self.cmd.sgr('39', '49') # reset fg/bg
|
|
||||||
|
|
||||||
def draw_browsing_screen(self) -> None:
|
def draw_browsing_screen(self) -> None:
|
||||||
self.draw_tab_bar()
|
self.draw_tab_bar()
|
||||||
|
|
||||||
|
def on_browsing_key_event(self, key_event: KeyEventType, in_bracketed_paste: bool = False) -> None:
|
||||||
|
for cat in 'all dark light recent'.split():
|
||||||
|
if key_event.matches(cat[0]):
|
||||||
|
self.current_category = cat
|
||||||
|
self.redraw_after_category_change()
|
||||||
|
return
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
def on_key_event(self, key_event: KeyEventType, in_bracketed_paste: bool = False) -> None:
|
def on_key_event(self, key_event: KeyEventType, in_bracketed_paste: bool = False) -> None:
|
||||||
if self.state is State.fetching:
|
if self.state is State.fetching:
|
||||||
self.on_fetching_key_event(key_event, in_bracketed_paste)
|
self.on_fetching_key_event(key_event, in_bracketed_paste)
|
||||||
|
elif self.state is State.browsing:
|
||||||
|
self.on_browsing_key_event(key_event, in_bracketed_paste)
|
||||||
|
|
||||||
def draw_screen(self) -> None:
|
def draw_screen(self) -> None:
|
||||||
self.cmd.clear_screen()
|
self.cmd.clear_screen()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user