Avoid starting curses when not needed (like for --help), it blinks my screen (#5)
This commit is contained in:
parent
95228eb03f
commit
fd43d33e3a
19
pogrep.py
19
pogrep.py
|
@ -13,6 +13,7 @@ from textwrap import fill
|
||||||
import regex
|
import regex
|
||||||
import polib
|
import polib
|
||||||
from tabulate import tabulate
|
from tabulate import tabulate
|
||||||
|
from shutil import get_terminal_size
|
||||||
|
|
||||||
|
|
||||||
def get_colors():
|
def get_colors():
|
||||||
|
@ -34,19 +35,6 @@ def get_colors():
|
||||||
RED, GREEN, MAGENTA, NO_COLOR = 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):
|
def colorize(text, pattern, prefixes):
|
||||||
result = regex.sub(pattern, RED + r"\g<0>" + NO_COLOR, text)
|
result = regex.sub(pattern, RED + r"\g<0>" + NO_COLOR, text)
|
||||||
for pnum, pfile in prefixes:
|
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):
|
def find_in_po(pattern, path, linenum, file_match, no_messages):
|
||||||
table = []
|
table = []
|
||||||
prefixes = []
|
prefixes = []
|
||||||
|
term_width = get_terminal_size()[0]
|
||||||
for filename in path:
|
for filename in path:
|
||||||
try:
|
try:
|
||||||
pofile = polib.pofile(filename)
|
pofile = polib.pofile(filename)
|
||||||
|
@ -85,8 +74,8 @@ def find_in_po(pattern, path, linenum, file_match, no_messages):
|
||||||
prefixes.append((pnum, pfile))
|
prefixes.append((pnum, pfile))
|
||||||
table.append(
|
table.append(
|
||||||
[
|
[
|
||||||
fill(left, width=(WIDTH - 7) // 2),
|
fill(left, width=(term_width - 7) // 2),
|
||||||
fill(entry.msgstr, width=(WIDTH - 7) // 2),
|
fill(entry.msgstr, width=(term_width - 7) // 2),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
if not file_match:
|
if not file_match:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user