Difference between
modified post 2cffbe38 by Anonymous on Wed 27th Apr 2022 18:18
original post 53f9a by Anonymous on Wed 27th Apr 2022 18:08
Download diff
Show
old version |
new version |
both versions
| 1 | 1 | #!/usr/bin/ksh93 | |
| 2 | 2 | ||
| 3 | 3 | compound c=( | |
| 4 | 4 | compound tty=( | |
| 5 | 5 | integer max_x | |
| 6 | 6 | integer max_y | |
| 7 | 7 | ) | |
| 8 | 8 | ||
| 9 | 9 | compound sample_data=( | |
| 10 | 10 | float -a vals | |
| 11 | 11 | float min=0 | |
| 12 | 12 | float max=0 | |
| 13 | 13 | ) | |
| 14 | 14 | ||
| 15 | 15 | float min_data_shift | |
| 16 | 16 | float max_data_shift | |
| 17 | 17 | float data_scale_to_tty_max_y | |
| 18 | 18 | ) | |
| 19 | 19 | ||
| 20 | 20 | integer i | |
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | 23 | # | |
| 24 | 24 | # get terminal info | |
| 25 | 25 | # | |
| 26 | 26 | (( c.tty.max_x=$(tput cols)-2 )) | |
| 27 | 27 | (( c.tty.max_y=$(tput lines)-2 )) | |
| 28 | 28 | ||
| 29 | 29 | # | |
| 30 | 30 | # collect samples data | |
| 31 | 31 | # | |
| 32 | 32 | integer max_i=${c.tty.max_x} | |
| 33 | 33 | for ((i=0 ; i < max_i ; i++ )) ; do | |
| 34 | 34 | (( c.sample_data.vals[i]=sin(i/5.) )) | |
| 35 | 35 | done | |
| 36 | 36 | ||
| 37 | 37 | # | |
| 38 | 38 | # get minimum/maximum value of all data samples | |
| 39 | 39 | # | |
| 40 | 40 | # we use $ for i in "${!@}" instead of $ for ((i=0 ; i < ... ; i++ )) # syntax | |
| 41 | 41 | # here so we can handle sparse data/sparse arrays | |
| 42 | 42 | # | |
| 43 | 43 | for i in "${!c.sample_data.vals[@]}" ; do | |
| 44 | 44 | (( c.sample_data.min=fmin(c.sample_data.vals[i], c.sample_data.min) )) | |
| 45 | 45 | (( c.sample_data.max=fmax(c.sample_data.vals[i], c.sample_data.max) )) | |
| 46 | 46 | done | |
| 47 | 47 | ||
| 48 | 48 | # | |
| 49 | 49 | # calculations for output scaling etc | |
| 50 | 50 | # | |
| 51 | 51 | (( c.min_data_shift = c.sample_data.min * -1.0 )) | |
| 52 | 52 | (( c.max_data_shift = c.min_data_shift + c.sample_data.max )) | |
| 53 | 53 | (( c.data_scale_to_tty_max_y = c.tty.max_y / c.max_data_shift )) | |
| 54 | 54 | ||
| 55 | 55 | # | |
| 56 | 56 | # output | |
| 57 | 57 | # | |
| 58 | 58 | tput clear | |
| 59 | 59 | for i in "${!c.sample_data.vals[@]}" ; do | |
| 60 | 60 | tput cup $(( int( c.data_scale_to_tty_max_y * (c.min_data_shift+c.sample_data.vals[i]) ) )) $i | |
| 61 | 61 | printf '.' | |
| 62 | 62 | done | |
| 63 | 63 | ||
| 64 | 64 | # move cursor to bottom, and then print a newline | |
| 65 | 65 | tput cup ${c.tty.max_y} ${c.tty.max_x} ; print | |
| 66 | 66 | ||
| 67 | 67 | #print -v c | |
| 68 | 68 | ||
| 69 | 69 | # EOF. | |
| 70 | 70 |
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
rovema.kpaste.net RSS