No Description

a 13bb5e656f . 2 weeks ago
.gitignore db32eeabad initial commit 7 months ago
1.png 95d702205c . 7 months ago
README.md 13bb5e656f . 2 weeks ago
print2.c 13bb5e656f . 2 weeks ago
yepstat.c 13bb5e656f . 2 weeks ago

README.md

Notice the first grey CPU 0% 0% 0% line

yepstat is acting like status line that overwrites your very first terminal line every 0.5 seconds, so you can easily keep track of things that you are interested to monitor while hacking something in the terminal. It's meant to be efficient and fast even when under 100% cpu and drive I/O load.

This is exactly what we do: save the current position of the cursor, move it to the top left corner of the terminal, clear the entire line, output the desired data and restore the cursor position, so you get the feeling that there is a real status line up there.

Here is the tput equivalent of yepstat:

while true; do tput sc;tput cup 0 0; tput el;printf '%s' 'Hello World';tput rc;sleep 0.5;done &

We could also use the -S option:

while true; do tput -S <<EOF
sc
cup 0 0
el
EOF
;printf '%s' 'Hello World';tput rc;sleep 0.5;done &

To be able to use PageUp and PageDown in your terminal, you'll have to disable auto scrolling on tty output.

Do some simple benchmark to grasp over why tput doesn't provide us enough speed. Use the first tput example and decrease the sleep time to 0.1. Then try typing some text over and over as fast as you can and notice how many characters will NOT be written. Open up this program source code and replace "500L *" with "100L *", recompile and repeat the typing test. Move to the second tput example and again decrease the sleep down 0.1, and repeat the typing test.

Once you understand the concept, you'll find 6 interesting, after which you'll get why the program needs to be as fast as possible.

Spoiler, single iteration comparison:

# yepstat
real    0m0.001s
user    0m0.000s
sys     0m0.000s

# tput
real    0m0.006s
user    0m0.002s
sys     0m0.002s

# the shell alone
# echo -en "\0337\033[1;1H\033[K" open and read /tmp/yepstat "\0338"
real    0m0.003s
user    0m0.001s
sys     0m0.002s

Obviously the "speed" has it's price and it's the compatibility that tput provides.


Installation

linux

gcc -std=c99 -D_POSIX_C_SOURCE=200112L -Wall -Wextra -O2 -o yepstat yepstat.c

*BSD

gcc -std=c99 -D_DEFAULT_SOURCE -Wall -Wextra -O2 -o yepstat yepstat.c

Usage

Changing colours, font type, boldness and so on happens by using ANSI escape codes 1 , 2 , 3 and 4

We use tmpfs (your RAM), so even when your drive is under heavy write and read I/O the program to remain lightning fast.

# The updating process
while true; do echo '\e[101;96mlight cyan fg on light red bg\e[0m'; done | ./yepstat &

# instead using "print,printf,echo",
# but you'll have to replace "033,x1B" occurences with "\e"
while true; do print2 '\e[101;96mlight cyan fg on light red bg\e[0m'; done | ./yepstat &

Requirements

  • gcc/clang
  • glibc/libc
  • terminal emulator supporting ANSI escape codes 5