Chris
Chris

Reputation: 31266

Terminal: get rid of cursor flicker

I am printing to the same line over and over with a while loop to monitor progress.

echo; while true; do 
    sleep 0.1; 
    echo -en "\e[1A"; 
    run | some |code | awk '{print}'; 
done;

Prints my output to the same line every time.

However, there is a buffer problem: the cursor flickers between the echo and the print statement.

How do I get rid of the terminal cursor flicker in my status while loop?

Perhaps a different question, but still a solution: how to temporarily suppress the cursor after a command?

Upvotes: 0

Views: 79

Answers (1)

Thomas Dickey
Thomas Dickey

Reputation: 54583

You can reduce flicker by combining the echo into the awk command. For instance:

echo; while true; do 
    sleep 0.1; 
    run | some |code | awk '{printf("\033[A%s\n", $0); }'; 
done;

The (nonstandard) \e is equivalent to \033, and you do not really need the repeat-count 1.

Upvotes: 1

Related Questions