diff options
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>') |