Linux screen Programming: Use of the curses library

Source: Internet
Author: User
Tags clear screen


The curses library is a set of functions that you can use to set the position of the cursor and the character styles that appear on the terminal screen. The curses library sees the terminal screen as a grid of character cells, each marked by a (row, column) coordinate pair. The coordinate origin is the upper-left corner of the screen, row coordinates are incremented from top to bottom, and column coordinates are incremented from left to right.

Here are a few common functions:

INITSCR () Initialize curses libraries and TTY

Endwin () Close the curses library and reset the TTY

Refresh () to make the screen appear as you intended

Move (r,s) moves the cursor to the (r,s) position of the screen

Addstr (s) Draw string s at current position

ADDCH (c) stooped character C at the current position

Clear () Clear screen

Standout () Start standout mode (typically reverse-color the screen)

Standend () Close standout mode


A simple Curses library program curses1.c:

#include <stdio.h> #include <curses.h>main () {INITSCR ();        Clear ();        Move (10,20);        Addstr ("Hello,world");       Move (lines-1,0);        Lines is the number of rows in the current terminal, refresh ();        Getch (); Endwin ();}
$GCC-O Curese curses.c

The compilation error is as follows:

error:curses.h:no such file or directory

The curses library file is missing and the dependent packages are checked:

$yum provides */curses.h ... ncurses-devel-5.7-3.20090208.el6.x86_64:development files for the ncurses    : library Repo:server matched From:filename:/usr/include/ncurses/curses.h Filename :/usr/include/curses.h Filename:/usr/include/ncursesw/curses.h ...

Yum Install NCURSES-DEVEL-Y//installs the package to

[[email protected] 7]# gcc -o curses1 curses1.c/tmp/cclupdcb.o: in  function  ' main ': curses1.c: (. text+0x5): undefined reference to  ' Initscr ' curses1.c: (. TEXT+0XC): undefined reference to  ' Stdscr ' curses1.c: (. text+0x14): undefined  reference to  ' Wclear ' curses1.c: (. text+0x1b): undefined reference to  ' STDSCR ' CURSES1.C: (. text+0x2d): undefined reference to  ' Wmove ' curses1.c: (. text+0x34):  undefined reference to  ' STDSCR ' curses1.c: (. text+0x46):  undefined reference to   ' Waddnstr ' curses1.c: (. text+0x4c): undefined reference to  ' LINES ' curses1.c: (. text+ 0x56): undefined reference to  ' Stdscr ' curses1.c: (. text+0x65): undefined  reference to  ' Wmove ' curses1.c: (. text+0x6c): undefined reference to  ' STDSCR ' CURSES1.C: (. text+0x74):  undefined reference to  ' Wrefresh ' curses1.c: (. text+0x7b): undefined reference to  ' STDSCR ' CURSES1.C: (. text+0x83): undefined reference to  ' Wgetch ' curses1.c: (. text+0x88):  undefined reference to  ' Endwin ' collect2: ld returned 1 exit status

The workaround is to add the parameter-lncurses at compile time

Gcc-o curses1 curses1.c-lncurses


This article is from the "Dance Fish" blog, please be sure to keep this source http://ty1992.blog.51cto.com/7098269/1684265

Linux screen Programming: Use of the curses library

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.