-
Notifications
You must be signed in to change notification settings - Fork 183
Added ability to change theme from command line arguments #177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b1a5510
f1bff1d
439ef27
2557eb6
476c559
978a9dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| import hangups | ||
| from hangups.ui.notify import Notifier | ||
| from hangups.ui.utils import get_conv_name | ||
| from hangups.ui.utils import add_color_to_scheme | ||
|
|
||
|
|
||
| LOG_FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' | ||
|
|
@@ -22,6 +23,7 @@ | |
| ('inactive_tab', 'standout', ''), | ||
| ('msg_date', '', ''), | ||
| ('msg_sender', '', ''), | ||
| ('msg_self', '', ''), | ||
| ('msg_text', '', ''), | ||
| ('status_line', 'standout', ''), | ||
| ('tab_background', 'standout', ''), | ||
|
|
@@ -31,18 +33,21 @@ | |
| ('inactive_tab', 'underline', 'light green'), | ||
| ('msg_date', 'dark cyan', ''), | ||
| ('msg_sender', 'dark blue', ''), | ||
| ('msg_self', 'light blue', ''), | ||
| ('msg_text', '', ''), | ||
| ('status_line', 'standout', ''), | ||
| ('tab_background', 'underline', 'black'), | ||
| }, | ||
| } | ||
| COL_SCHEME_NAMES = ('active_tab', 'inactive_tab', 'msg_date', 'msg_sender', | ||
| 'msg_self', 'msg_text', 'status_line', 'tab_background') | ||
|
|
||
|
|
||
| class ChatUI(object): | ||
| """User interface for hangups.""" | ||
|
|
||
| def __init__(self, refresh_token_path, keybindings, palette, datetimefmt, | ||
| disable_notifier): | ||
| def __init__(self, refresh_token_path, keybindings, palette, | ||
| palette_colors, datetimefmt, disable_notifier): | ||
| """Start the user interface.""" | ||
| self._keys = keybindings | ||
| self._datetimefmt = datetimefmt | ||
|
|
@@ -73,6 +78,7 @@ def __init__(self, refresh_token_path, keybindings, palette, datetimefmt, | |
| event_loop=urwid.AsyncioEventLoop(loop=loop) | ||
| ) | ||
|
|
||
| self._urwid_loop.screen.set_terminal_properties(colors=palette_colors) | ||
| self._urwid_loop.start() | ||
| try: | ||
| # Returns when the connection is closed. | ||
|
|
@@ -438,7 +444,8 @@ def __init__(self, timestamp, text, datetimefmt, user=None, | |
| ('msg_text', text) | ||
| ] | ||
| if user is not None: | ||
| text.insert(1, ('msg_sender', user.first_name + ': ')) | ||
| text.insert(1, ('msg_self' if user.is_self else 'msg_sender', | ||
| user.first_name + ': ')) | ||
| self._widget = urwid.Text(text) | ||
| super().__init__(self._widget) | ||
|
|
||
|
|
@@ -857,8 +864,6 @@ def main(): | |
| help='show this help message and exit') | ||
| general_group.add('--token-path', default=default_token_path, | ||
| help='path used to store OAuth refresh token') | ||
| general_group.add('--col-scheme', choices=COL_SCHEMES.keys(), | ||
| default='default', help='colour scheme to use') | ||
| general_group.add('--date-format', default='< %y-%m-%d >', | ||
| help='date format string') | ||
| general_group.add('--time-format', default='(%I:%M:%S %p)', | ||
|
|
@@ -887,20 +892,44 @@ def main(): | |
| help='keybinding for alternate up key') | ||
| key_group.add('--key-down', default='j', | ||
| help='keybinding for alternate down key') | ||
|
|
||
| # add color scheme options | ||
| col_group = parser.add_argument_group('Colors') | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also add the existing |
||
| col_group.add('--col-scheme', choices=COL_SCHEMES.keys(), | ||
| default='default', help='colour scheme to use') | ||
| col_group.add('--col-palette-colors', choices=('16', '88', '256'), | ||
| default=16, help='Amount of available colors') | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Last choice should be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, yes it should be. Fixed now |
||
| for name in COL_SCHEME_NAMES: | ||
| col_group.add('--col-' + name.replace('_', '-') + '-fg', | ||
| help=name + ' foreground color') | ||
| col_group.add('--col-' + name.replace('_', '-') + '-bg', | ||
| help=name + ' background color') | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| # Create all necessary directories. | ||
| for path in [args.log, args.token_path]: | ||
| dir_maker(path) | ||
|
|
||
| log_level = logging.DEBUG if args.debug else logging.WARNING | ||
| logging.basicConfig(filename=args.log, level=log_level, format=LOG_FORMAT) | ||
| logging.basicConfig(filename=args.log, | ||
| level=logging.DEBUG if args.debug else logging.WARNING, | ||
| format=LOG_FORMAT) | ||
| # urwid makes asyncio's debugging logs VERY noisy, so adjust the log level: | ||
| logging.getLogger('asyncio').setLevel(logging.WARNING) | ||
|
|
||
| datetimefmt = {'date': args.date_format, | ||
| 'time': args.time_format} | ||
|
|
||
| # setup color scheme | ||
| palette_colors = int(args.col_palette_colors) | ||
|
|
||
| col_scheme = COL_SCHEMES[args.col_scheme] | ||
| for name in COL_SCHEME_NAMES: | ||
| col_scheme = add_color_to_scheme(col_scheme, name, | ||
| getattr(args, 'col_' + name + '_fg'), | ||
| getattr(args, 'col_' + name + '_bg'), | ||
| palette_colors) | ||
|
|
||
| try: | ||
| ChatUI( | ||
| args.token_path, { | ||
|
|
@@ -911,8 +940,8 @@ def main(): | |
| 'menu': args.key_menu, | ||
| 'up': args.key_up, | ||
| 'down': args.key_down | ||
| }, COL_SCHEMES[args.col_scheme], datetimefmt, | ||
| args.disable_notifications | ||
| }, col_scheme, palette_colors, | ||
| datetimefmt, args.disable_notifications | ||
| ) | ||
| except KeyboardInterrupt: | ||
| sys.exit('Caught KeyboardInterrupt, exiting abnormally') | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did
light bluework for you? It's the same default colour as the message text for me. Strangely, it looks correct in urwid'spalette_test.py.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works on my end. this is what it looks like: https://i.imgur.com/e1Hw73f.png. It might depend on the terminal colours you use though.:
I ended up going with this, looks pretty nice with base16 terminal colours.
col-palette-colors=88
col-active-tab-fg=black
col-active-tab-bg=h12
col-inactive-tab-fg=black, standout
col-inactive-tab-bg=h8
col-msg-date-fg=h5
col-msg-sender-fg=h6, bold
col-msg-self-fg=h12
col-status-line-fg=h8, standout
col-status-line-bg=black
col-tab-background-fg=default