Refactor color temrinal escaping into a common module

I have no idea which one of the existing pypi modules is best for these,
and given that we're using just two escape codes, I think it makes sense
not to bother with a more capable third-party module just for two magic
strings.
This commit is contained in:
Jan Kundrát
2019-05-30 12:25:53 +02:00
parent b2e12cd3e0
commit f09789f5ef
3 changed files with 16 additions and 2 deletions

View File

@@ -31,6 +31,7 @@ from gnpy.core.request import (Path_request, Result_element, compute_constrained
propagate, jsontocsv, Disjunction, compute_path_dsjctn, requests_aggregation,
propagate_and_optimize_mode)
from gnpy.core.exceptions import ConfigurationError
import gnpy.core.ansi_escapes as ansi_escapes
from copy import copy, deepcopy
from textwrap import dedent
from math import ceil
@@ -312,7 +313,7 @@ if __name__ == '__main__':
equipment = load_equipment(args.eqpt_filename)
network = load_network(args.network_filename,equipment)
except ConfigurationError as e:
print('\x1b[1;31;40m' + 'Configuration error:' + '\x1b[0m' + f' {e}')
print(f'{ansi_escapes.red}Configuration error:{ansi_escapes.reset} {e}')
exit(1)
# Build the network once using the default power defined in SI in eqpt config