Search code examples
cconsolencursescursessox

Animate console graphics without Curses


I have been using the SoX play command line tool to playback audio files from the console, and have noticed that there is a nice little display of the time info and left/right levels that update in real time with the audio source . . .

Screenshot from SoX homepage Screenshot from SoX homepage

However, after cloning the source, I could not find any mention of Ncurses. Does anyone know how SoX achieves this neat little console trick? I just don't know what to look for, or which file to look in to see how this is implemented.


Solution

  • I doubt it's merely using the \b character. My guess would be that it's using the terminal cursor movement commands, which are a set of escape sequences supported by many (but not all) Linux terminals.

    You can even use these straight from the command line using echo. For instance:

    $ s=($(stty size)); echo -en "\e[2J\e[$((s[0]/2));$((s[1]/2-6))HHello world.\e[${s[0]};0H"
    

    This should give you a blank screen, except for the the message "Hello world." printed right in the middle of the screen, and a prompt at the very bottom.