Conversation
neofetch
Outdated
@@ -3978,27 +3984,31 @@ prin() { | |||
if [[ "$(trim "$1")" && "$2" ]]; then | |||
[[ "$json" ]] && { printf ' %s\n' "\"${1}\": \"${2}\","; return; } | |||
|
|||
string="${1}${2:+: $2}" | |||
string="${1}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way things are printed in this PR makes concatenating arg2 to arg1 redundant, but arg1 is still formatted correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a more complete explanation now.
Originally, this if statement joined the two arguments into the same string, but to properly align the info by label, the labels and their corresponding data had to stay separate. I've left the JSON logic in place, but set string to the first argument in both cases, so I've updated the code to be
# If $2 doesn't exist we format $1 as info.
if [[ "$(trim "$1")" && "$2" ]]; then
[[ "$json" ]] && { printf ' %s\n' "\"${1}\": \"${2}\","; return; }
fi
string="${1}"
string="$(trim "${string//$'\e[0m'}")"
Now I'm not really sure what the lines
length="$(strip_sequences "$string")"
length="${#length}"
do, but removing them doesn't seem to change anything, so I've left them in.
Anyway, not concatenating $2 to $1 has several benefits:
First, we still strip all sequences from the labels, standardize them to bold, and get the length.
Second, now I can pad the first argument of calls to prin with an arbitrary number of \033[0m \033[0m ...
and manually center text if I want to give my own short byline like this screenshot:
BUT DO NOTE that using sequences in prin -- for whatever reason -- means the string is not considered by the alignment logic. For this statement to be true the sequences have to be raw (e.g. you have to put \33[0m in your string instead of ${reset}). If you try to use substitutions the whole strong is considered and it throws the info way to the right. I consider this a feature, but I can see how someone might want this to be fixed later, so that they can choose whether to exclude something and use ${reset}${bold}${italic} etc.
Third, we can still properly detect automatically whether or not the user probably wants a separator at the end of the string with
string="${string}${reset}${colon_color}"
[[ "$2" ]] && string="${string}${separator}${separator:=:}"
Fourth: Now users can use arbitrary sequences to format text the way they like (italic, flashing, etc).
With the string formatting simplified we can do:
printf '%b' "${text_padding:+\e[${text_padding}C}${zws}"
case "$align_output" in
"left") printf '%-*b' $offset "${string}" ;;
"right") printf '%+*b' $offset "${string}" ;;
"off") printf '%b' "${string}" ;;
esac
[[ "$2" ]] && printf '%b' "${info_color}${2}"
printf '\n'
If any of this breaks existing behavior I haven't witnessed it, so I'll need feedback from people with more exotic setups.
2399ff0
to
3415b90
Compare
df1bccb
to
1d4b925
Compare
a6da753
to
c52715a
Compare
ed2c3a9
to
da500d2
Compare
c4d20d7
to
ffe7c5b
Compare
I went ahead and rebased this on master to see if it would fix those failing checks from a few months ago, and it seems that it has. |
Let's try this again with a clean git log -- sorry about that.
Description
Adds the option to align the output to the space after the end of the separator string ":", "->", etc by padding all arguments to printf by the same amount regardless of length
Features
--align_output 'left', 'right', 'off'
left: Don't right-justify labels like "OS", but align what gets listed after
right: Align labels to make their contents aligned
off: Default behavior of neofetch
Issues