Consider adding colored output or prepended string for each line of output
E.g.:
(process ["foo" "bar"] {:color :green :prepend "FOO"})
This would be useful in babashka tasks where multiple processes are running in parallel so you can distinguish them.
Just a note that foreman only colors the process name at the beginning of the line. The rest of the output is unmodified.
Would it be sufficient to just have a convenience option like
:process-line-fn (fn [s] (str (termcolor :green "FOO | ") s))
Pasting in my current plain bash solution that I'd like to replace. Essentially, I'm wrapping each line with some stuff.
frontend and backend are normal bash functions that cd into the right directory, and run make dev or something similar.
Perhaps I could delete the whole thing and replace it with a little bb.edn :)
with_prefix() {
# Usage: with_prefix $APPNAME $COLOR
local NOCOLOR='\033[0m'
awk -v name="$1" -v color="$2" -v nocolor="$NOCOLOR" '{ printf "%s[%s]%s %s\n", color, name, nocolor, $0 }'
}
apps() {
# from https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux
#
# Black 0;30 Dark Gray 1;30
# Red 0;31 Light Red 1;31
# Green 0;32 Light Green 1;32
# Brown/Orange 0;33 Yellow 1;33
# Blue 0;34 Light Blue 1;34
# Purple 0;35 Light Purple 1;35
# Cyan 0;36 Light Cyan 1;36
# Light Gray 0;37 White 1;37
local NO_COLOR='\033[0m'
local BLACK='\033[0;30m'
local RED='\033[0;31m'
local GREEN='\033[0;32m'
local BROWN_ORANGE='\033[0;33m'
local BLUE='\033[0;34m'
local PURPLE='\033[0;35m'
local CYAN='\033[0;36m'
local LIGHT_GRAY='\033[0;37m'
local DARK_GRAY='\033[1;30m'
local LIGHT_RED='\033[1;31m'
local LIGHT_GREEN='\033[1;32m'
local YELLOW='\033[1;33m'
local LIGHT_BLUE='\033[1;34m'
local LIGHT_PURPLE='\033[1;35m'
local LIGHT_CYAN='\033[1;36m'
local WHITE='\033[1;37m'
local BLACK='\033[0;30m'
local RED='\033[0;31m'
local GREEN='\033[0;32m'
# If secrets env vars are not set, try to source bash / zsh.
frontend 2> >(with_prefix "frontend" "$RED") 1> >(with_prefix "frontend" "$GREEN") &
backend 2> >(with_prefix "backend" "$RED") 1> >(with_prefix "backend" "$BLUE") &
nats 2> >(with_prefix "nats" "$RED") 1> >(with_prefix "nats" "$LIGHT_CYAN") &
sleep 999999999999
}
@jkxyz Indeed, having just a function to map over the stdout and/or stderr would be the most flexible solution. Just an interceptor basically.
See discussion here with a potential solution:
https://github.com/babashka/process/discussions/102#discussioncomment-4903758