M
M
mkone1122021-09-13 18:05:03
linux
mkone112, 2021-09-13 18:05:03

Line alignment in terminal?

Right-aligning text in terminals is a terribly inconvenient thing for me. How to make it look like this?
613f68647778e055392378.png
Interested in a solution in any OS.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Saboteur, 2021-09-13
@mkone112

There is no such thing as alignment in the terminal.
A similar feature can be implemented in the terminal client, but among the popular clients, I don’t remember it in any of them, and it has never been in demand. Left alignment is automatic, because there is the beginning of the line, and the line feed therefore starts the next line always on the left.
Of course, you can write a function and pass the output of each command through it in order to align everything to the right through some printf thread.
Output one character to the right, for example, like this:

read WindowHeight WindowWidth<<<$(stty size)
printf "%$WindowWidth" "A"

Calculate the length of each line and align to the center or right.
But such a question is devoid of adequate meaning.
If you need to parse the entire output, start a new bash with redirection, for example like this:
bash|(while read;do printf "%80s\n" $REPLY;done)
instead of (..) you can write your own script that will parse everything in detail - the command output will be aligned.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question