Skip to content

Commit

Permalink
ikhal: prettier help/keybindings pane
Browse files Browse the repository at this point in the history
  • Loading branch information
geier committed Jun 16, 2023
1 parent b8a987a commit b0c7b3f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 14 additions & 10 deletions khal/ui/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import logging
import threading
import time
from typing import List, Union, Callable, Tuple, Optional

import urwid

Expand Down Expand Up @@ -77,16 +78,20 @@ def dialog(self, text, buttons):
overlay = urwid.Overlay(content, self, 'center', ('relative', 70), ('relative', 70), None)
self.window.open(overlay)

def scrollable_dialog(self, text, buttons=None, title="Press `ESC` to close this window"):
def scrollable_dialog(self,
text: Union[str, List[urwid.Text]],
buttons: Optional[List[Tuple[str, Callable]]]=None,
title="Press `ESC` to close this window",
) -> None:
"""Open a scrollable dialog box.
:param text: Text to appear as the body of the Dialog box
:type text: str
:param buttons: list of tuples of button labels and functions to call
when the button is pressed
:type buttons: list(str, callable)
:param buttons: button labels and functions to call when the button is pressed
"""
body = urwid.ListBox([urwid.Text(line) for line in text.splitlines()])
if isinstance(text, str):
body = urwid.ListBox([urwid.Text(line) for line in text.splitlines()])
else:
body = urwid.ListBox(text)
if buttons:
buttons = NColumns(
[urwid.Button(label, on_press=func) for label, func in buttons],
Expand Down Expand Up @@ -115,12 +120,11 @@ def keypress(self, size, key):

def show_keybindings(self):
lines = []
lines.append(' Command Keys')
lines.append(' ======= ====')
lines.append(urwid.AttrMap(urwid.Text(' Command Keys'), 'alt header'))
for command, keys in self._conf['keybindings'].items():
lines.append(f' {command:20} {keys}')
lines.append(urwid.Text(f' {command:20} {", ".join(keys)}'))
self.scrollable_dialog(
'\n'.join(lines),
lines,
title="Press `ESC` to close this window, arrows to scroll",
)

Expand Down
2 changes: 2 additions & 0 deletions khal/ui/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
('header', 'white', 'black'),
('footer', 'white', 'black'),
('line header', 'black', 'white', 'bold'),
('alt header', 'white', '', 'bold'),
('bright', 'dark blue', 'white', ('bold', 'standout')),
('list', 'black', 'white'),
('list focused', 'white', 'light blue', 'bold'),
Expand Down Expand Up @@ -59,6 +60,7 @@
('header', 'black', 'white'),
('footer', 'black', 'white'),
('line header', 'black', 'white', 'bold'),
('alt header', 'black', '', 'bold'),
('bright', 'dark blue', 'white', ('bold', 'standout')),
('list', 'black', 'white'),
('list focused', 'white', 'light blue', 'bold'),
Expand Down

0 comments on commit b0c7b3f

Please sign in to comment.