How can I print characters to screen like vim on linux?

170 Views Asked by At

I'm writing a program that needs to modify the terminal screen buffer without using printf or stdout. On win32 I did that by using CreateConsoleScreenBuffer() and SetConsoleActiveScreenBuffer() then writing to the console screen buffer using WriteConsoleOutputCharacter(). I want to do this on linux as well (kind of like how vim prints things out) but I can't find any way. It would also be great if there was a way to do this using the standard library!

1

There are 1 best solutions below

0
Thomas Dickey On

OP says

without using printf or stdout

you could use stderr (which usually points to the same terminal), e.g.,

    echo '\033[H\033[J' >&2

to clear the screen while writing to stderr. Or you could use tput, e.g.,

    tput clear >&2