From 445454dc61ab7db9453e6f83bd460a03c7703f23 Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Sat, 27 Feb 2016 12:45:52 -0500 Subject: [PATCH 1/2] fix linefeeds in xonfig wizard on windows --- xonsh/xonfig.py | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/xonsh/xonfig.py b/xonsh/xonfig.py index 71dc6f996..dee069b6e 100644 --- a/xonsh/xonfig.py +++ b/xonsh/xonfig.py @@ -23,8 +23,8 @@ HR = "'`-.,_,.-*'`-.,_,.-*'`-.,_,.-*'`-.,_,.-*'`-.,_,.-*'`-.,_,.-*'`-.,_,.-*'" WIZARD_HEAD = """ {{BOLD_WHITE}}Welcome to the xonsh configuration wizard!{{NO_COLOR}} {{YELLOW}}------------------------------------------{{NO_COLOR}} -This will present a guided tour through setting up the xonsh static -config file. Xonsh will automatically ask you if you want to run this +This will present a guided tour through setting up the xonsh static +config file. Xonsh will automatically ask you if you want to run this wizard if the configuration file does not exist. However, you can always rerun this wizard with the xonfig command: @@ -48,12 +48,12 @@ WIZARD_FS = """ {{BOLD_WHITE}}Foreign Shell Setup{{NO_COLOR}} {{YELLOW}}-------------------{{NO_COLOR}} The xonsh shell has the ability to interface with foreign shells such -as Bash, zsh, or fish. +as Bash, zsh, or fish. -For configuration, this means that xonsh can load the environment, -aliases, and functions specified in the config files of these shells. -Naturally, these shells must be available on the system to work. -Being able to share configuration (and source) from foreign shells +For configuration, this means that xonsh can load the environment, +aliases, and functions specified in the config files of these shells. +Naturally, these shells must be available on the system to work. +Being able to share configuration (and source) from foreign shells makes it easier to transition to and from xonsh. """.format(hr=HR) @@ -69,18 +69,21 @@ Still, setting environment variables in this way can help define options that are global to the system or user. The following lists the environment variable name, its documentation, -the default value, and the current value. The default and current +the default value, and the current value. The default and current values are presented as pretty repr strings of their Python types. -{{BOLD_GREEN}}Note:{{NO_COLOR}} Simply hitting enter for any environment variable +{{BOLD_GREEN}}Note:{{NO_COLOR}} Simply hitting enter for any environment variable will accept the default value for that entry. +""".format(hr=HR) + +WIZARD_ENV_QUESTION = "Would you like to set env vars now, " + YN -Would you like to set env vars now, """.format(hr=HR) + YN WIZARD_TAIL = """ Thanks for using the xonsh configuration wizard!""" + def make_fs(): """Makes the foreign shell part of the wizard.""" cond = create_truefalse_cond(prompt='Add a foreign shell, ' + YN) @@ -160,7 +163,7 @@ def make_envvar(name): node = StoreNonEmpty(prompt, converter=ens.convert, show_conversion=True, path=path) return node - + def make_env(): """Makes an environment variable wizard.""" @@ -185,7 +188,8 @@ def make_wizard(default_file=None, confirm=False): Load(default_file=default_file, check=True), Message(message=WIZARD_FS), make_fs(), - YesNo(question=WIZARD_ENV, yes=make_env(), no=Pass()), + Message(message=WIZARD_ENV), + YesNo(question=WIZARD_ENV_QUESTION, yes=make_env(), no=Pass()), Message(message='\n' + HR + '\n'), Save(default_file=default_file, check=True), Message(message=WIZARD_TAIL), @@ -227,11 +231,11 @@ def _format_json(data): data = {k.replace(' ', '_'): v for k, v in data} s = json.dumps(data, sort_keys=True, indent=1) + '\n' return s - + def _info(ns): data = [ - ('xonsh', XONSH_VERSION), + ('xonsh', XONSH_VERSION), ('Python', '.'.join(map(str, tools.VER_FULL))), ('PLY', ply.__version__), ('have readline', is_readline_available()), @@ -253,18 +257,18 @@ def _info(ns): @functools.lru_cache() def _create_parser(): - p = ArgumentParser(prog='xonfig', + p = ArgumentParser(prog='xonfig', description='Manages xonsh configuration.') subp = p.add_subparsers(title='action', dest='action') info = subp.add_parser('info', help=('displays configuration information, ' 'default action')) - info.add_argument('--json', action='store_true', default=False, + info.add_argument('--json', action='store_true', default=False, help='reports results as json') wiz = subp.add_parser('wizard', help=('displays configuration information, ' 'default action')) - wiz.add_argument('--file', default=None, + wiz.add_argument('--file', default=None, help='config file location, default=$XONSHCONFIG') - wiz.add_argument('--confirm', action='store_true', default=False, + wiz.add_argument('--confirm', action='store_true', default=False, help='confirm that the wizard should be run.') return p @@ -276,7 +280,7 @@ _MAIN_ACTIONS = { def main(args=None): """Main xonfig entry point.""" - if not args or (args[0] not in _MAIN_ACTIONS and + if not args or (args[0] not in _MAIN_ACTIONS and args[0] not in {'-h', '--help'}): args.insert(0, 'info') parser = _create_parser() From 9dc1ba222275c64744cf3013d3d87fdd582b72cf Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Sat, 27 Feb 2016 17:46:35 -0500 Subject: [PATCH 2/2] env var fix --- xonsh/xonfig.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/xonsh/xonfig.py b/xonsh/xonfig.py index dee069b6e..e19ae5fe4 100644 --- a/xonsh/xonfig.py +++ b/xonsh/xonfig.py @@ -134,12 +134,13 @@ def _wrap_paragraphs(text, width=70, **kwargs): s = '\n'.join(pars) return s -ENVVAR_PROMPT = """ +ENVVAR_MESSAGE = """ {{BOLD_CYAN}}${name}{{NO_COLOR}} {docstr} {{RED}}default value:{{NO_COLOR}} {default} -{{RED}}current value:{{NO_COLOR}} {current} -{{BOLD_GREEN}}>>>{{NO_COLOR}} """ +{{RED}}current value:{{NO_COLOR}} {current}""" + +ENVVAR_PROMPT = "{BOLD_GREEN}>>>{NO_COLOR} " def make_envvar(name): """Makes a StoreNonEmpty node for an environment variable.""" @@ -156,20 +157,25 @@ def make_envvar(name): curr = pformat(curr, width=69) if '\n' in curr: curr = '\n' + curr - prompt = ENVVAR_PROMPT.format(name=name, default=default, current=curr, + msg = ENVVAR_MESSAGE.format(name=name, default=default, current=curr, docstr=_wrap_paragraphs(vd.docstr, width=69)) + mnode = Message(message=msg) ens = env.get_ensurer(name) path = '/env/' + name - node = StoreNonEmpty(prompt, converter=ens.convert, show_conversion=True, - path=path) - return node + pnode = StoreNonEmpty(ENVVAR_PROMPT, converter=ens.convert, + show_conversion=True, path=path) + return mnode, pnode def make_env(): """Makes an environment variable wizard.""" kids = map(make_envvar, sorted(builtins.__xonsh_env__.docs.keys())) - kids = [k for k in kids if k is not None] - wiz = Wizard(children=kids) + flatkids = [] + for k in kids: + if k is None: + continue + flatkids.extend(k) + wiz = Wizard(children=flatkids) return wiz