Avoid starting curses when not needed (like for --help), it blinks my screen (#5)

This commit is contained in:
Julien Palard 2020-01-22 17:57:12 +01:00 committed by GitHub
parent 95228eb03f
commit fd43d33e3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 15 deletions

View File

@ -13,6 +13,7 @@ from textwrap import fill
import regex
import polib
from tabulate import tabulate
from shutil import get_terminal_size
def get_colors():
@ -34,19 +35,6 @@ def get_colors():
RED, GREEN, MAGENTA, NO_COLOR = get_colors()
def get_term_width():
scr = curses.initscr()
width = scr.getmaxyx()[1]
try:
curses.endwin()
except curses.error:
pass
return width
WIDTH = get_term_width()
def colorize(text, pattern, prefixes):
result = regex.sub(pattern, RED + r"\g<0>" + NO_COLOR, text)
for pnum, pfile in prefixes:
@ -62,6 +50,7 @@ def colorize(text, pattern, prefixes):
def find_in_po(pattern, path, linenum, file_match, no_messages):
table = []
prefixes = []
term_width = get_terminal_size()[0]
for filename in path:
try:
pofile = polib.pofile(filename)
@ -85,8 +74,8 @@ def find_in_po(pattern, path, linenum, file_match, no_messages):
prefixes.append((pnum, pfile))
table.append(
[
fill(left, width=(WIDTH - 7) // 2),
fill(entry.msgstr, width=(WIDTH - 7) // 2),
fill(left, width=(term_width - 7) // 2),
fill(entry.msgstr, width=(term_width - 7) // 2),
]
)
if not file_match: