Skip to content

Commit

Permalink
fix!: fixes app colors when terminal theme doesn't match
Browse files Browse the repository at this point in the history
BREAKING CHANGE: thais changes the color palette and config schema
  • Loading branch information
ju1ius committed Nov 23, 2023
1 parent fbc9cb3 commit f574170
Show file tree
Hide file tree
Showing 7 changed files with 342 additions and 249 deletions.
8 changes: 1 addition & 7 deletions clisnips/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,11 @@ class UrwidMarkupHelper:
palette = {
'default': ('default', 'default'),
'accent': ('dark magenta', 'default'),
'accent:inverse': ('black', 'dark magenta'),
'success': ('dark green', 'default'),
'success:inverse': ('black', 'dark green'),
'error': ('dark red', 'default'),
'error:inverse': ('black', 'dark red'),
'warning': ('brown', 'default'),
'warning:inverse': ('black', 'brown'),
'info': ('dark blue', 'default'),
'info:inverse': ('white', 'dark blue'),
'debug': ('light cyan', 'default'),
'debug:inverse': ('black', 'light cyan'),
'debug': ('dark cyan', 'default'),
}

def __init__(self):
Expand Down
49 changes: 30 additions & 19 deletions clisnips/config/palette.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@

default_palette = {
'default': {'fg': 'light gray', 'bg': 'black'},
'info': {'fg': 'dark blue', 'bg': 'default'},
'success': {'fg': 'dark green', 'bg': 'default'},
'warning': {'fg': 'brown', 'bg': 'default'},
'error': {'fg': 'dark red', 'bg': 'default'},
'accent': {'fg': 'dark magenta', 'bg': 'black'},
# standard feedback colors
'disabled': {'fg': 'dark gray,bold', 'bg': 'black'},
'debug': {'fg': 'dark cyan', 'bg': 'black'},
'info': {'fg': 'dark blue', 'bg': 'black'},
'success': {'fg': 'dark green', 'bg': 'black'},
'warning': {'fg': 'brown', 'bg': 'black'},
'error': {'fg': 'dark red', 'bg': 'black'},

'action:default': 'default',
'action:suggested': {'fg': 'dark cyan,bold', 'bg': 'black'},
'action:destructive': {'fg': 'dark red,bold', 'bg': 'black'},
'action:disabled': 'disabled',
Expand All @@ -26,31 +30,38 @@
'help:key': {'fg': 'dark cyan', 'bg': 'black'},

# views / components
'view:default': {'fg': 'light gray', 'bg': 'black'},
'view:default': 'default',
'search-entry:caption': {'fg': 'dark cyan', 'bg': 'black'},
'snip:title': {'fg': 'light gray,italics', 'bg': 'black'},
'snip:tag': {'fg': 'brown', 'bg': 'black'},
'snip:cmd': {'fg': 'dark green', 'bg': 'black'},
'snippets-list': 'default',
'snippets-list:focused': {'fg': 'light gray', 'bg': 'dark gray', 'mono': 'standout'},
'snippets-list:cmd': {'fg': 'dark green', 'bg': 'black'},
'snippets-list:cmd': 'snip:cmd',
'snippets-list:cmd:focused': {'fg': 'dark green', 'bg': 'dark gray', 'mono': 'standout'},
'snippets-list:title': {'fg': 'light gray,italics', 'bg': 'black'},
'snippets-list:title:focused': {'fg': 'light gray,italics', 'bg': 'dark gray', 'mono': 'standout'},
'snippets-list:tag': {'fg': 'brown', 'bg': 'black'},
'snippets-list:title': 'snip:title',
'snippets-list:title:focused': {'fg': 'light gray,italics', 'bg': 'dark gray', 'mono': 'standout,italics'},
'snippets-list:tag': 'snip:tag',
'snippets-list:tag:focused': {'fg': 'brown', 'bg': 'dark gray', 'mono': 'standout'},

# widgets
'path-completion:file': {'fg': 'light gray', 'bg': 'default'},
'path-completion:directory': {'fg': 'dark blue', 'bg': 'default'},
'path-completion:symlink-directory': {'fg': 'dark cyan', 'bg': 'default'},
'path-completion:symlink-file': {'fg': 'brown', 'bg': 'default'},
'dialog': 'default',
'popup-menu': 'default',
'path-completion:file': 'default',
'path-completion:directory': {'fg': 'dark blue', 'bg': 'black'},
'path-completion:symlink-directory': {'fg': 'dark cyan', 'bg': 'black'},
'path-completion:symlink-file': {'fg': 'brown', 'bg': 'black'},

# syntax highlighting
'syn:cmd:default': {'fg': 'dark green', 'bg': 'black'},
'syn:cmd:punctuation': {'fg': 'light gray', 'bg': 'black'},
'syn:cmd:default': 'snip:cmd',
'syn:cmd:punctuation': 'default',
'syn:cmd:field-marker': {'fg': 'dark magenta', 'bg': 'black'},
'syn:cmd:field-name': {'fg': 'dark magenta', 'bg': 'black'},
'syn:cmd:field-conversion': {'fg': 'dark cyan', 'bg': 'black'},
'syn:cmd:field-format': {'fg': 'dark cyan', 'bg': 'black'},

'syn:doc:default': {'fg': 'light gray', 'bg': 'black'},
'syn:doc:default': 'default',
'syn:doc:punctuation': 'syn:doc:default',
'syn:doc:parameter': {'fg': 'dark magenta', 'bg': 'black'},
'syn:doc:type-hint': {'fg': 'dark cyan', 'bg': 'black'},
'syn:doc:value-hint': {'fg': 'brown', 'bg': 'black'},
Expand All @@ -59,15 +70,15 @@
'syn:doc:number': {'fg': 'yellow', 'bg': 'black'},
'syn:doc:code-fence': {'fg': 'dark red', 'bg': 'black'},

'syn:py:default': {'fg': 'light gray', 'bg': 'black'},
'syn:py:name': {'fg': 'light gray', 'bg': 'black'},
'syn:py:default': 'default',
'syn:py:name': 'default',
'syn:py:comment': {'fg': 'dark gray', 'bg': 'black'},
'syn:py:keyword': {'fg': 'dark magenta', 'bg': 'black'},
'syn:py:class': {'fg': 'brown', 'bg': 'black'},
'syn:py:decorator': {'fg': 'brown', 'bg': 'black'},
'syn:py:string': {'fg': 'dark green', 'bg': 'black'},
'syn:py:string:escape': {'fg': 'light cyan', 'bg': 'black'},
'syn:py:string:interp': {'fg': 'light gray', 'bg': 'black'},
'syn:py:string:interp': 'default',
'syn:py:function': {'fg': 'dark cyan', 'bg': 'black'},
'syn:py:number': {'fg': 'yellow', 'bg': 'black'},
} # fmt: skip
Expand Down
2 changes: 1 addition & 1 deletion clisnips/tui/components/edit_snippet_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def _check_doc_syntax_on_changed(self, entry, value):
self._errors.discard('doc')

def _on_errors_changed(self, errors: set[str]):
self._save_action.toggle(not errors)
self._save_action.toggle(enabled=not errors)


class SimpleField(urwid.Pile):
Expand Down
42 changes: 23 additions & 19 deletions clisnips/tui/components/show_snippet_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,43 @@
from clisnips.tui.widgets.divider import HorizontalDivider


def _create_field(label: TextMarkup, content: TextMarkup):
field = urwid.Pile(
(
urwid.Text(label),
urwid.Text(content),
),
)
return field


class ShowSnippetDialog(Dialog):
def __init__(self, parent, snippet: Snippet):
body = urwid.ListBox(
urwid.SimpleListWalker(
(
_create_field('Title', snippet['title']),
_field('Title:', ('snip:title', snippet['title'])),
HorizontalDivider(),
_create_field('Tags', snippet['tag']),
_field('Tags:', ('snip:tag', snippet['tag'])),
HorizontalDivider(),
_create_field('Command', highlight_command(snippet['cmd'])),
_field('Command:', highlight_command(snippet['cmd'])),
HorizontalDivider(),
_create_field('Documentation', highlight_documentation(snippet['doc'])),
_field('Documentation:', highlight_documentation(snippet['doc'])),
HorizontalDivider(),
urwid.Text(f"Created on: {date(snippet['created_at'])}"),
urwid.Text(f"Last used on: {date(snippet['last_used_at'])}"),
urwid.Text(f"Usage count: {snippet['usage_count']}"),
urwid.Text(f"Ranking: {snippet['ranking']}"),
_info('Created on: ', _date(snippet['created_at'])),
_info('Last used on: ', _date(snippet['last_used_at'])),
_info('Usage count: ', snippet['usage_count']),
_info('Ranking: ', snippet['ranking']),
),
),
)

super().__init__(parent, body)


def date(timestamp: float):
def _field(label: TextMarkup, content: TextMarkup):
field = urwid.Pile(
(
urwid.Text(label),
urwid.Text(content),
),
)
return field


def _info(label: str, value: str | float):
return urwid.Text([label, ('info', str(value))])


def _date(timestamp: float) -> str:
return time.strftime('%Y-%m-%d %H:%M:%S UTC', time.gmtime(timestamp))
2 changes: 1 addition & 1 deletion clisnips/tui/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class View(urwid.WidgetWrap):

def __init__(self, view: urwid.Widget):
self._view = view
self._wrapped_widget = urwid.AttrMap(self._view, 'view:default')
self._wrapped_widget = urwid.AttrMap(self._view, 'default')
super().__init__(self._wrapped_widget)
self._has_dialog = False

Expand Down
2 changes: 1 addition & 1 deletion clisnips/tui/widgets/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def __init__(self, view: View, body: urwid.Widget):
# pad area around listbox
w = urwid.Padding(w, align=Align.LEFT, left=2, right=2, width=(WHSettings.RELATIVE, 100))
w = urwid.Filler(w, valign=VAlign.TOP, top=1, bottom=1, height=('relative', 100))
w = urwid.AttrMap(w, 'body')
w = urwid.AttrMap(w, 'dialog')
super().__init__(w)

def close(self):
Expand Down
Loading

0 comments on commit f574170

Please sign in to comment.