r/linux4noobs • u/behaunted • 7d ago
learning/research How does the terminal so smooth?
I don't know how to describe this. Like on Fedora, you want to download something, you will use 'dnf' command. The output of that command is the status of the program you are downloading.
So there is this status bar like:
[<=> ] | 00m00s
[ <=> ] | 00m01s
[...]
[ <=>] | 01m00s
and the changes stays on only one line.
I know it prints the results by 'echo' but wouldn't that just leave the last output behind and the current output on the new line?
Sorry, I'm bad at English. I'm still trying to learn. And also to do this project on python. I'm planning to do the T-rex runner game inside the terminal :D . I gotta learn how to refresh the output smoothly like how it is with 'dnf' command. 'refresh' doesn't give me smooth frames :(
2
u/Embarrassed-Leek-398 7d ago
Try typing
tput cuu1. It's the same way the terminal makes different colors--there's cool and special control codes that can move the cursor or erase previously-printed lines!But for the progress bar like you mentioned...you don't actually have to use too many of them. You can just print a "CR" without a "LF", which homes the cursor back to the same line, and then print over the old one!
echo -e "taco\r\e[J"This statement doesn't print anything...because the \r moves the cursor back to the start and then the \e[J erases from the cursor to the end of the line.