端末上でのカーソル位置制御やテキストの表示などの制御をするためのライブラリにcursesライブラリというものがあります。今回は、それを使ってみたので、その時のメモです。
initscr()で初期化して、endwin()で終了です。standout()は、強調表示開始 standend()は、強調表示終了です。
sample.c
#include <stdio.h>
#include <curses.h>
int main( int argc, char *argv[] )
{
int i;
initscr();
clear();
for( i = 0; i < LINES; i++ ) {
move(i,i+1);
if( i%2 == 1 )
standout();
addstr("Hello, world");
if( i%2 == 1 )
standend();
}
refresh();
getch();
endwin();
return 0;
}
ビルド時には、ライブラリを指定してあげる必要があります。
gcc sample.c -lcurses -o sample