NCurses Tutorial Filiz Şenyüzlüler Güzelbey. What is nCurses? Ncurses is a library, which is...

13
nCurses Tutorial Filiz Şenyüzlüler Güzelbey

description

What is nCurses? What you can do with Ncurses: – Use any part of the screen according to your request. – Create and manage windows. – Use 8 different colors. – Use the function keys on the keyboard.

Transcript of NCurses Tutorial Filiz Şenyüzlüler Güzelbey. What is nCurses? Ncurses is a library, which is...

Page 1: NCurses Tutorial Filiz Şenyüzlüler Güzelbey. What is nCurses? Ncurses is a library, which is used for creating and using windows, screen painting and.

nCurses Tutorial

Filiz Şenyüzlüler Güzelbey

Page 2: NCurses Tutorial Filiz Şenyüzlüler Güzelbey. What is nCurses? Ncurses is a library, which is used for creating and using windows, screen painting and.

What is nCurses?

• Ncurses is a library, which is used for creating and using windows, screen painting and using function keys for text-based terminals.

Page 3: NCurses Tutorial Filiz Şenyüzlüler Güzelbey. What is nCurses? Ncurses is a library, which is used for creating and using windows, screen painting and.

What is nCurses?

• What you can do with Ncurses:

– Use any part of the screen according to your request.

– Create and manage windows.– Use 8 different colors.– Use the function keys on the keyboard.

Page 4: NCurses Tutorial Filiz Şenyüzlüler Güzelbey. What is nCurses? Ncurses is a library, which is used for creating and using windows, screen painting and.

Getting Ready

• Add #include <ncurses.h>

• Open Terminal (Compile & Run from Terminal)

Page 5: NCurses Tutorial Filiz Şenyüzlüler Güzelbey. What is nCurses? Ncurses is a library, which is used for creating and using windows, screen painting and.

Basic Functions • initscr();

– initializes the terminal in curses mode.– it clears the screen and presents a blank screen.

• printw("Hello World !!!");

• refresh() checks the window and updates only the portion which has been changed.

• endwin() frees the memory taken by curses sub-system and its data structures and puts the terminal in normal mode.

Page 6: NCurses Tutorial Filiz Şenyüzlüler Güzelbey. What is nCurses? Ncurses is a library, which is used for creating and using windows, screen painting and.

Hello World !!

Page 7: NCurses Tutorial Filiz Şenyüzlüler Güzelbey. What is nCurses? Ncurses is a library, which is used for creating and using windows, screen painting and.

Hello World !! (2)

Page 8: NCurses Tutorial Filiz Şenyüzlüler Güzelbey. What is nCurses? Ncurses is a library, which is used for creating and using windows, screen painting and.

Using Terminal

• cd Desktop (to reach the file-path)

• cd foldername

• g++ filename.cpp –lncurses (to compile)

• ./a.out (to run)

Page 9: NCurses Tutorial Filiz Şenyüzlüler Güzelbey. What is nCurses? Ncurses is a library, which is used for creating and using windows, screen painting and.

Basic Functions

• getch() – Waits for user input

• clear()– Clears the screen

Page 10: NCurses Tutorial Filiz Şenyüzlüler Güzelbey. What is nCurses? Ncurses is a library, which is used for creating and using windows, screen painting and.

clearing the screen

Page 11: NCurses Tutorial Filiz Şenyüzlüler Güzelbey. What is nCurses? Ncurses is a library, which is used for creating and using windows, screen painting and.

attributes

• attributes are used to print characters with some special effects.

• attron(), attroff() can be used to switch attributes on/off

Page 12: NCurses Tutorial Filiz Şenyüzlüler Güzelbey. What is nCurses? Ncurses is a library, which is used for creating and using windows, screen painting and.

A_BOLD attron(A_BOLD);

printw("%c", ch);attroff(A_BOLD);

Page 13: NCurses Tutorial Filiz Şenyüzlüler Güzelbey. What is nCurses? Ncurses is a library, which is used for creating and using windows, screen painting and.

COLOR_PAIR(n) start_color(); /* Start color*/init_pair(1, COLOR_RED, COLOR_GREEN); attron(COLOR_PAIR(1));printw("%c", ch);attroff(COLOR_PAIR(1));