Note that there are some explanatory texts on larger screens.

plurals
  1. POZSH print array objects in color to terminal window
    primarykey
    data
    text
    <p>Still learning shell scripting and ZSH. But was wondering if someone knew how to create an array of simple objects think, json type objects/hashes, and then print the properties of each object in column format in different colors. </p> <p>I want to create a specific function in my zsh plugin that prints to my terminal in a very precise way.</p> <p>Open questions:</p> <p>1.) How to print specific strings in different colors</p> <p>2.) How to define arrays of basic objects with multiple key/value pairs </p> <p>The following pseudo code will hopefully clarify what I am trying to do.</p> <pre><code>function display-collection() { collection=( {param1: foo1, param2: bar1, param3: baz1 } {param1: foo2, param2: bar2, param3: baz2 } {param1: foo3, param2: bar3, param3: baz3 } {param1: foo4, param2: bar4, param3: baz4 } {param1: foo5, param2: bar5, param3: baz5 } {param1: foo6, param2: bar6, param3: baz6 } ) print -l $collection } </code></pre> <p>Make the above function spit out the contents to the terminal in color</p> <pre><code>foo1 (RED TEXT) bar1 (DEFAULT COLOR) baz1 (YELLOW COLOR) foo2 (RED TEXT) bar2 (DEFAULT COLOR) baz2 (YELLOW COLOR) foo3 (RED TEXT) bar3 (DEFAULT COLOR) baz3 (YELLOW COLOR) foo4 (RED TEXT) bar4 (DEFAULT COLOR) baz4 (YELLOW COLOR) foo5 (RED TEXT) bar5 (DEFAULT COLOR) baz5 (YELLOW COLOR) foo6 (RED TEXT) bar6 (DEFAULT COLOR) baz6 (YELLOW COLOR) </code></pre> <p>In other words column text like this with each column color coorindated the foo values would be red, the bar values would be default and the baz values would be yellow</p> <pre><code>foo1 bar1 baz1 foo2 bar2 baz2 foo3 bar3 baz3 foo4 bar4 baz4 foo5 bar5 baz5 foo6 bar6 baz6 </code></pre> <p>Bonus points if I can format the alignment to be nice ordered columns, with arbitrary delimiters/separators.</p> <pre><code>foo1 : bar1 = baz1 string1 : some string = another string string2 : some longer string = another longer string helloworld : This is a function = it prints helloworld </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload