Skip to content

Commit

Permalink
scripts: Add render_symbols to test symbol rendering.
Browse files Browse the repository at this point in the history
This commit adds a new folder `scripts/` to ship scripts that are meant
for users. This commit also adds a new script that enables users to check
how the various symbols listed in `config/symbols.py` render on their
terminal emulator.

The need for this script has arisen from the observed issues on the Windows
Terminal, where with varying fonts, symbol rendering has also varied.
  • Loading branch information
prah23 committed Apr 13, 2021
1 parent e381030 commit 87ae86a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ def long_description():
entry_points={
'console_scripts': [
'zulip-term = zulipterminal.cli.run:main',
'zulip-term-check-symbols = '
'zulipterminal.scripts.render_symbols:main',
],
},
extras_require={
Expand Down
Empty file.
51 changes: 51 additions & 0 deletions zulipterminal/scripts/render_symbols.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import sys

import urwid
from urwid import set_encoding

from zulipterminal.config import symbols


set_encoding('utf-8')

palette = [
('header', 'white, bold', 'light blue'),
('footer', 'black', 'white'),
]

variables = vars(symbols)
symbol_dict = {symbol: variables[symbol] for symbol in variables
if not symbol.startswith('__') and not symbol.endswith('__')}

symbol_names_list = [urwid.Text(name, align='center')
for name in symbol_dict.keys()]
symbols_list = [urwid.Text(symbol) for symbol in symbol_dict.values()]

# given_width is hardcoded based on the longest symbol name (26 characters).
# TODO: Update the width if we have a longer name for a symbol.
symbols_display_box = urwid.Columns([
(27, urwid.Pile(symbol_names_list)),
(3, urwid.Pile(symbols_list))
], dividechars=9)

line_box = urwid.LineBox(symbols_display_box,
title="Render Symbols",
title_attr='header')
info_box = urwid.Text(('footer', u" Exit: ^C "), align='center')
display_box = urwid.Pile([
line_box,
info_box
])

# Allot a width of 45 to the display_box. line_box occupies about 39 characters
# so we consider that as a maximum. Use extra width to make it look cleaner.
body = urwid.Filler(urwid.Padding(display_box, align='center', width=45),
valign='middle')


def main() -> None:
try:
loop = urwid.MainLoop(body, palette)
loop.run()
finally:
sys.exit(0)

0 comments on commit 87ae86a

Please sign in to comment.