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.
I want to create a specific function in my zsh plugin that prints to my terminal in a very precise way.
Open questions:
1.) How to print specific strings in different colors
2.) How to define arrays of basic objects with multiple key/value pairs
The following pseudo code will hopefully clarify what I am trying to do.
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
}
Make the above function spit out the contents to the terminal in color
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)
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
foo1 bar1 baz1
foo2 bar2 baz2
foo3 bar3 baz3
foo4 bar4 baz4
foo5 bar5 baz5
foo6 bar6 baz6
Bonus points if I can format the alignment to be nice ordered columns, with arbitrary delimiters/separators.
foo1 : bar1 = baz1
string1 : some string = another string
string2 : some longer string = another longer string
helloworld : This is a function = it prints helloworld