Sunday, May 29, 2011

Bash script cursor control

taken from:
http://bashscript.blogspot.com/2010/04/how-to-handle-cursor-movement-in-shell.html


The movement escape sequences are as follows:

        - Position the Cursor:
          \033[<L>;<C>H
             Or
          \033[<L>;<C>f
          puts the cursor at line L and column C.
        - Move the cursor up N lines:
          \033[<N>A
        - Move the cursor down N lines:
          \033[<N>B
        - Move the cursor forward N columns:
          \033[<N>C
        - Move the cursor backward N columns:
          \033[<N>D
        - Clear the screen, move to (0,0):
          \033[2J
        - Erase to end of line:
          \033[K
        - Save cursor position:
          \033[s
        - Restore cursor position:
          \033[u
example:
echo -en "\033[s\033[7B\033[1;34m BASH BASH\033[u\033[0m" 
 
Script to print position of a file in a process:
 
prints on line 2, column 1 
 
#!/bin/bash

/bin/echo -en "\033[2J"
while [ 1 ] ; do
/bin/echo -en "\033[2;1H"
echo `cat /proc/5648/fdinfo/1|grep pos`
echo $a
done
 

No comments:

Post a Comment