DRYer
This commit is contained in:
parent
424bd8a6cd
commit
50384fac97
@ -3,7 +3,7 @@
|
|||||||
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from typing import Any, Dict, NamedTuple, Optional, Sequence, Set, Tuple
|
from typing import Any, Dict, NamedTuple, Optional, Sequence, Tuple
|
||||||
|
|
||||||
from .config import build_ansi_color_table
|
from .config import build_ansi_color_table
|
||||||
from .constants import WindowGeometry
|
from .constants import WindowGeometry
|
||||||
@ -46,7 +46,9 @@ def as_rgb(x: int) -> int:
|
|||||||
return (x << 8) | 2
|
return (x << 8) | 2
|
||||||
|
|
||||||
|
|
||||||
template_failures: Set[str] = set()
|
@lru_cache()
|
||||||
|
def report_template_failure(template: str, e: str) -> None:
|
||||||
|
log_error('Invalid tab title template: "{}" with error: {}'.format(template, e))
|
||||||
|
|
||||||
|
|
||||||
@lru_cache()
|
@lru_cache()
|
||||||
@ -54,9 +56,7 @@ def compile_template(template: str) -> Any:
|
|||||||
try:
|
try:
|
||||||
return compile('f"""' + template + '"""', '<template>', 'eval')
|
return compile('f"""' + template + '"""', '<template>', 'eval')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if template not in template_failures:
|
report_template_failure(template, str(e))
|
||||||
template_failures.add(template)
|
|
||||||
log_error('Invalid tab title template: "{}" with error: {}'.format(template, e))
|
|
||||||
|
|
||||||
|
|
||||||
def draw_title(draw_data: DrawData, screen: Screen, tab: TabBarData, index: int) -> None:
|
def draw_title(draw_data: DrawData, screen: Screen, tab: TabBarData, index: int) -> None:
|
||||||
@ -77,9 +77,7 @@ def draw_title(draw_data: DrawData, screen: Screen, tab: TabBarData, index: int)
|
|||||||
}
|
}
|
||||||
title = eval(compile_template(template), {'__builtins__': {}}, eval_locals)
|
title = eval(compile_template(template), {'__builtins__': {}}, eval_locals)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if template not in template_failures:
|
report_template_failure(template, str(e))
|
||||||
template_failures.add(template)
|
|
||||||
log_error('Invalid tab title template: "{}" with error: {}'.format(template, e))
|
|
||||||
title = tab.title
|
title = tab.title
|
||||||
screen.draw(title)
|
screen.draw(title)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user