Prev: Unmounting a dead remote NFS system
Next: Video files access from a Canon VIXIA HF S20 camcorder
From: Baho Utot on 22 May 2010 14:23 I have a bash script that outputs information like the following printf "Building --> ${i}: " That leaves the cursor position at the end of the line. I would like to position to the start of that line and then erase it so I can update it with the current progress so I get "a stack" them like this Building --> rsync-files: [SKIPPED] Building --> tools-binutils-pass-1: [OK] Building --> tools-gcc-pass-1: [FAILED] Building --> tools-linux-api-headers: [OK] Building --> tools-glibc: configuring.... I don't know how to position the cusor to BOL so I can over write that line. Thanks
From: pk on 22 May 2010 14:26 Baho Utot wrote: > I have a bash script that outputs information like the following > > printf "Building --> ${i}: " > > That leaves the cursor position at the end of the line. > I would like to position to the start of that line and then erase it so I > can update it with the current progress so I get "a stack" them like this > > Building --> rsync-files: [SKIPPED] > Building --> tools-binutils-pass-1: [OK] > Building --> tools-gcc-pass-1: [FAILED] > Building --> tools-linux-api-headers: [OK] > Building --> tools-glibc: configuring.... > > I don't know how to position the cusor to BOL so I can over write that > line. printf "\r" should do that. Beware that what's already on the line will NOT be erased, so if the string you're writing is shorted than the previous one, it will mess up. So you may want to print a long string of spaces before printing a message. Silly example: printf "some long message" sleep 1 printf "\r \r" printf "short" sleep 1 printf "\r \r" etc.etc.
From: Henning Bekel on 22 May 2010 14:27 Baho Utot wrote: > I don't know how to position the cusor to BOL so I can over write that > line. printf 'original line' sleep 1 tput el # erase line tput cr # carriage return printf 'replaced line\n' Note that tput cr is equivalent to printf '\r'. See tput(1) and terminfo(1).
From: Chris Davies on 8 Jun 2010 06:24 Baho Utot <baho-utot(a)invalid.com> wrote: > I have a bash script that outputs information like the following > printf "Building --> ${i}: " > I would like to position to the start of that line and then erase it so I > can update it with the current progress so I get "a stack" them like this > I don't know how to position the cusor to BOL so I can over write that line. tput is your friend for this sort of work. It's terminal independent, so in many cases you don't even need to worry whether a particular feature exists. tput civis # hide cursor tput cnorm # unhide tput clear # clear the screen and go to (0,0) tput home # home the cursor ("tput cup 0 0") tput cup $Y $X # put the cursor at ($X,$Y), indexed from (0,0) tput el # clear to end of line tput ed # clear to end of screen tput smso # standout tput rmso # normal tput setaf 1 # red text tput setaf 7 # white text There are many additional options, allowing for saving/restoring cursor position, bold, etc. man 5 terminfo for (gory) details. printf "\rBuilding --> ${i}: "; tput el Chris
From: unruh on 8 Jun 2010 14:07 On 2010-06-08, Chris Davies <chris-usenet(a)roaima.co.uk> wrote: > Baho Utot <baho-utot(a)invalid.com> wrote: >> I have a bash script that outputs information like the following >> printf "Building --> ${i}: " > >> I would like to position to the start of that line and then erase it so I >> can update it with the current progress so I get "a stack" them like this > >> I don't know how to position the cusor to BOL so I can over write that line. The below is certainly one possibility. The other is to make sure that you use printf without and eol and then use backspaces to eliminate the previous stuff. Otherwise you will have the problem that the some lines being longer than the succeeding one, will have stuff from the previous line sticking out of the end the later one-- making for a messy screen. So print the stuff to a string, determine the length of the string, and then print out that number of backspaces. > > tput is your friend for this sort of work. It's terminal independent, > so in many cases you don't even need to worry whether a particular > feature exists. > > tput civis # hide cursor > tput cnorm # unhide > > tput clear # clear the screen and go to (0,0) > tput home # home the cursor ("tput cup 0 0") > tput cup $Y $X # put the cursor at ($X,$Y), indexed from (0,0) > > tput el # clear to end of line > tput ed # clear to end of screen > > tput smso # standout > tput rmso # normal > > tput setaf 1 # red text > tput setaf 7 # white text > > There are many additional options, allowing for saving/restoring cursor > position, bold, etc. man 5 terminfo for (gory) details. > > printf "\rBuilding --> ${i}: "; tput el > > Chris
|
Next
|
Last
Pages: 1 2 Prev: Unmounting a dead remote NFS system Next: Video files access from a Canon VIXIA HF S20 camcorder |