From 43e075db7207f95ded6abe3a2b89c8db4809a4ed Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 23 May 2022 16:28:55 +0000 Subject: [PATCH] add --columns long opt --- mmgen/globalvars.py | 7 +++++-- mmgen/opts.py | 4 ++++ mmgen/tw/common.py | 2 +- test/test.py | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/mmgen/globalvars.py b/mmgen/globalvars.py index 4831011d..97fd31b7 100755 --- a/mmgen/globalvars.py +++ b/mmgen/globalvars.py @@ -116,9 +116,11 @@ class GlobalContext(Lockable): test_suite = False test_suite_deterministic = False test_suite_popen_spawn = False - terminal_width = 0 mnemonic_entry_modes = {} + + # display: + columns = 0 color = bool( ( sys.stdout.isatty() and not os.getenv('MMGEN_TEST_SUITE_PEXPECT') ) or os.getenv('MMGEN_FORCE_COLOR') @@ -166,6 +168,7 @@ class GlobalContext(Lockable): 'bob', 'coin', 'color', + 'columns', 'daemon_data_dir', 'daemon_id', 'force_256_color', @@ -233,10 +236,10 @@ class GlobalContext(Lockable): env_opts = ( 'MMGEN_DEBUG_ALL', # special: there is no g.debug_all var + 'MMGEN_COLUMNS', 'MMGEN_TEST_SUITE', 'MMGEN_TEST_SUITE_DETERMINISTIC', 'MMGEN_TEST_SUITE_POPEN_SPAWN', - 'MMGEN_TERMINAL_WIDTH', 'MMGEN_BOGUS_SEND', 'MMGEN_DEBUG', 'MMGEN_DEBUG_OPTS', diff --git a/mmgen/opts.py b/mmgen/opts.py index 908dff1b..654d58ce 100755 --- a/mmgen/opts.py +++ b/mmgen/opts.py @@ -218,6 +218,7 @@ common_opts_data = { --, --coin=c Choose coin unit. Default: BTC. Current choice: {cu_dfl} --, --token=t Specify an ERC20 token by address or symbol --, --color=0|1 Disable or enable color output (enabled by default) +--, --columns=N Force N columns of output with certain commands --, --force-256-color Force 256-color output when color is enabled --, --data-dir=path Specify {pnm} data directory location --, --daemon-data-dir=path Specify coin daemon data directory location @@ -591,6 +592,9 @@ def check_usr_opts(usr_opts): # Raises an exception if any check fails opt_is_int(val,desc) opt_compares(int(val),'>',0,desc) + def chk_columns(key,val,desc): + opt_compares(int(val),'>',10,desc) + # TODO: move this check elsewhere # def chk_token(key,val,desc): # if not 'token' in proto.caps: diff --git a/mmgen/tw/common.py b/mmgen/tw/common.py index bd945b9c..d380510c 100755 --- a/mmgen/tw/common.py +++ b/mmgen/tw/common.py @@ -100,7 +100,7 @@ class TwCommon: def set_term_columns(self): from ..term import get_terminal_size while True: - self.cols = g.terminal_width or get_terminal_size().width + self.cols = g.columns or get_terminal_size().width if self.cols >= g.min_screen_width: break line_input( diff --git a/test/test.py b/test/test.py index 3ee11ef9..cf7c2c86 100755 --- a/test/test.py +++ b/test/test.py @@ -471,7 +471,7 @@ def create_tmp_dirs(shm_dir): def set_environ_for_spawned_scripts(): from mmgen.term import get_terminal_size - os.environ['MMGEN_TERMINAL_WIDTH'] = str(get_terminal_size().width) + os.environ['MMGEN_COLUMNS'] = str(get_terminal_size().width) if os.getenv('MMGEN_DEBUG_ALL'): for name in g.env_opts: