diff options
author | HampusM <hampus@hampusmat.com> | 2021-12-14 12:38:33 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2021-12-14 12:38:33 +0100 |
commit | 362c3265031b91eb78890a515da48b47ca20376d (patch) | |
tree | c437a9c15c828c584b255779596f6b43f77c2caa /utils.py | |
parent | 5b2643bbbc53fabf4a49e5eb4df52ffe88c150e7 (diff) |
Diffstat (limited to 'utils.py')
-rw-r--r-- | utils.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..40a8f81 --- /dev/null +++ b/utils.py @@ -0,0 +1,20 @@ +import sys +import io +from typing import Optional + +from pygments.formatters import HtmlFormatter + + +def configure_io(): + sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8', errors='replace') + sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace') + + +def write_style(formatter: HtmlFormatter, opt_style: Optional[str] = None): + sys.stdout.write('<style>') + + if opt_style: + sys.stdout.write(opt_style) + + sys.stdout.write(formatter.get_style_defs('.highlight')) + sys.stdout.write('</style>') |