Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

'typeset -p' of assocs (was: Re: PATCH: [key]=value syntax, work in progress)



Oliver Kiddle wrote on Wed, Sep 13, 2017 at 11:14:04 +0200:
> It would be good to make typeset -p output use this new syntax by default
> for associative arrays because (without other cues like alignment) it
> can be clearer which items in the list are keys and which values.

I've been using a local patch that prints one space between key and its
value, but two spaces between value and the following key:

    % typeset -p color
    typeset -A color=(  00 none  01 bold  02 faint  03 standout  04 underline  05 blink  07 reverse  08 conceal  22 normal  23 no-standout  24 no-underline  25 no-blink  27 no-reverse  28 no-conceal  30 black  31 red  32 green  33 yellow  34 blue  35 magenta  36 cyan  37 white  39 default  40 bg-black  41 bg-red  42 bg-green  43 bg-yellow  44 bg-blue  45 bg-magenta  46 bg-cyan  47 bg-white  49 bg-default  bg-black 40  bg-blue 44  bg-cyan 46  bg-default 49  bg-green 42  bg-grey 40  bg-magenta 45  bg-red 41  bg-white 47  bg-yellow 43  black 30  blink 05  blue 34  bold 01  conceal 08  cyan 36  default 39  faint 02  fg-black 30  fg-blue 34  fg-cyan 36  fg-default 39  fg-green 32  fg-grey 30  fg-magenta 35  fg-red 31  fg-white 37  fg-yellow 33  green 32  grey 30  magenta 35  no-blink 25  no-conceal 28  no-reverse 27  no-standout 23  no-underline 24  none 00  normal 22  red 31  reverse 07  standout 03  underline 04  white 37  yellow 33  )

I think I posted it once, but here it is again.

Cheers,

Daniel
From 714da4bb3a26957cbd65058f7fb4afca85f82ee2 Mon Sep 17 00:00:00 2001
From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
Date: Wed, 28 Sep 2016 13:15:04 +0000
Subject: [PATCH] Print two spaces in 'typeset -p' of assocs

(tweaked for upstream 39704/0f5e670cde5f844680a20f986786249dfe983584)
---
 Src/params.c         | 6 ++++--
 Test/V10private.ztst | 2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/Src/params.c b/Src/params.c
index ef72cba44..39af27c40 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -5298,6 +5298,7 @@ printparamvalue(Param p, int printflags)
 	if (!(printflags & PRINT_KV_PAIR)) {
 	    putchar('(');
 	    putchar(' ');
+	    putchar(' ');
 	}
 	{
             HashTable ht = p->gsu.h->getfn(p);
@@ -5309,9 +5310,10 @@ printparamvalue(Param p, int printflags)
 	    putchar(')');
 	break;
     }
-    if (printflags & PRINT_KV_PAIR)
+    if (printflags & PRINT_KV_PAIR) {
 	putchar(' ');
-    else
+	putchar(' ');
+    } else
 	putchar('\n');
 }
 
diff --git a/Test/V10private.ztst b/Test/V10private.ztst
index 7ebf5a87f..d1d9b0887 100644
--- a/Test/V10private.ztst
+++ b/Test/V10private.ztst
@@ -128,7 +128,7 @@
  print ${(kv)hash_test}
 0:private hides value from surrounding scope in nested scope
 >typeset -a hash_test=( top level )
->typeset -A hash_test=( in function )
+>typeset -A hash_test=(  in function  )
 >typeset -g -a hash_test=( top level )
 >array-local top level
 >top level


Messages sorted by: Reverse Date, Date, Thread, Author