I doubt if it is needed to launch a sub-process for each markup directive. This is fine for small output, but will slow down processing of larger chunks of text. I would be interested in a bash solution based on associative arrays.
As an example, one might want to look at the zsh implementation of the colors script in the main distribution[0], which makes colors available as an associative array:
# Set once in shell init script:
autoload -U colors && colors
# And use it anywhere:
print $fg[blue]hello colorful world!$fg[reset]
I'm a little surprised something like "$(fgcolor red hello)" requires a $(fgcolor end) - if you include arguments shouldn't it be self-closing? Then you get nice things like "$(fgcolor red " $(hr)")"
$(title "header") could be cool, outputting " header$(br)------"
But if you've done: "$(fgcolor red)red text$(fgcolor green "green text") what color is this?"... then it would have to model a stack on top of the actual underlying implementation, which does not have any concept of "closing" a sequence to pop the colour back to the previous colour. It could automatically emit the \x1b[0m, but it would be making assumptions about nesting.
Unrelated, I'm pretty sad that there hasn't been further work in packaging shell extensions like this. Most of it is adhoc, and people usually tend to stick to `curl | bash` (I'm guilty of this as well with dokku and other OS projects).
function color ($name) { $Host.UI.RawUI.ForegroundColor = $name }
function sayhello { 'pardon me do you have any grey poupon?' }
echo $(color yellow) $(sayhello)
The other stuff (bold, pictures) requires host support (more than regular powershell.exe provides).
Some remarks:
I doubt if it is needed to launch a sub-process for each markup directive. This is fine for small output, but will slow down processing of larger chunks of text. I would be interested in a bash solution based on associative arrays.
As an example, one might want to look at the zsh implementation of the colors script in the main distribution[0], which makes colors available as an associative array:
[0]: http://sourceforge.net/p/zsh/code/ci/master/tree/Functions/M...