Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 38 additions & 9 deletions hangups/ui/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -22,6 +23,7 @@
('inactive_tab', 'standout', ''),
('msg_date', '', ''),
('msg_sender', '', ''),
('msg_self', '', ''),
('msg_text', '', ''),
('status_line', 'standout', ''),
('tab_background', 'standout', ''),
Expand All @@ -31,18 +33,21 @@
('inactive_tab', 'underline', 'light green'),
('msg_date', 'dark cyan', ''),
('msg_sender', 'dark blue', ''),
('msg_self', 'light blue', ''),
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did light blue work for you? It's the same default colour as the message text for me. Strangely, it looks correct in urwid's palette_test.py.

Copy link
Copy Markdown
Contributor Author

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

('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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)',
Expand Down Expand Up @@ -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')
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add the existing --col-scheme option to this group?

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')
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last choice should be 256 instead of 265.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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, {
Expand All @@ -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')
Expand Down
5 changes: 4 additions & 1 deletion hangups/ui/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
'title "{convo_name}" '
'subtitle "{sender_name}"'),
]
NOTIFY_ESCAPER = lambda s: s.replace('"', '\\"')

def NOTIFY_ESCAPER(s):
return s.replace('"', '\\"')
else:
NOTIFY_CMD = [
'gdbus', 'call', '--session', '--dest',
Expand All @@ -33,6 +35,7 @@
'org.freedesktop.Notifications.Notify', 'hangups', '{replaces_id}', '',
'{sender_name}', '{msg_text}', '[]', '{{}}', ' -1'
]

def NOTIFY_ESCAPER(text):
"""Escape text for passing into gdbus."""
# Prevent the notifier from interpreting markup:
Expand Down
21 changes: 21 additions & 0 deletions hangups/ui/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,24 @@ def get_conv_name(conv, truncate=False, show_unread=False):
postfix)
else:
return ', '.join(names) + postfix


def add_color_to_scheme(scheme, name, foreground, background, palette_colors):
"""Add foreground and background colours to a color scheme"""
if foreground is None and background is None:
return scheme

new_scheme = []
for item in scheme:
if item[0] == name:
if foreground is None:
foreground = item[1]
if background is None:
background = item[2]
if palette_colors > 16:
new_scheme.append((name, '', '', '', foreground, background))
else:
new_scheme.append((name, foreground, background))
else:
new_scheme.append(item)
return new_scheme