Advertisement
Guest User

awk - clear vs tput clear and cursor up tester

a guest
Jul 6th, 2012
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Awk 1.14 KB | None | 0 0
  1. #!/usr/bin/env awk
  2.  
  3. BEGIN {
  4.     # helper
  5.     if ( !ARGV[2] || ARGV[1] == "--help" )
  6.     {
  7.     print "\nUsage: awk -f film.awk [speed in second] [how many cycles] [cursorup] [bash clear]\n"
  8.     print "\n[cursorup]: 0, no tput cuu1; 1, yes tput cuu1"
  9.     print "\n[bash clear]: 0, tput clear; 1, clear; command for each cycle"
  10.     print "\n[bash clear]: 2, tput clear; 3, clear; command for each print"
  11.     exit 1
  12.     }
  13.  
  14.     # parameters
  15.     pos = 0
  16.     sec = ARGV[1]
  17.     how = ARGV[2]
  18.     cup = ARGV[3]
  19.     bas = ARGV[4]
  20.     "tput clear" | getline Clear;
  21.     "tput cuu1" | getline CursorUp;
  22.     data[1] = "|"
  23.     data[2] = "/"
  24.     data[3] = "-"
  25.     data[4] = "\\"
  26.    
  27.     # main
  28.     for ( ; pos <= how; pos++ )
  29.     {
  30.     clearEcho( 0 )
  31.     for ( c in data )
  32.     {
  33.         clearEcho( 2 )
  34.         print data[c]
  35.         if ( cup )
  36.         printf CursorUp
  37.         system( "sleep "sec )
  38.     }
  39.     }
  40. }
  41.  
  42. # function
  43. function clearEcho ( ori )
  44. {
  45.     if ( !ori )
  46.     {
  47.     ori = 0
  48.     num = 1
  49.     }
  50.     else
  51.     num = ori + 1
  52.     if ( bas == ori )
  53.     printf Clear;
  54.     else
  55.     if ( bas == num )
  56.         system( "clear" )
  57.     if ( bas == ori || bas == num )
  58.     print "cycle "pos
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement