5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

cursesライブラリを使う

Posted at

端末上でのカーソル位置制御やテキストの表示などの制御をするためのライブラリに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
5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?