Curses

From LQWiki
Jump to navigation Jump to search

Curses is a library providing terminal (and terminal emulator) independent functions for textual-based screen rendering and input handling.

Curses uses information about specific types of terminals/emulators found in the termcap or terminfo files to render the screen, abstracting away the specific details of the actual terminal/emulator - software written using curses will typically work on any terminal or terminal emulator whose escape sequences are known to the termcap or terminfo database.

An example of a curses application is linux' kernel configuration when using make menuconfig:

Linux Kernel v2.6.9 Configuration
 ┌───────────────────────────── General setup ─────────────────────────────┐
 │  Arrow keys navigate the menu.  <Enter> selects submenus --->.          │  
 │  Highlighted letters are hotkeys.  Pressing <Y> includes, <N> excludes, │  
 │  <M> modularizes features.  Press <Esc><Esc> to exit, <?> for Help, </> │  
 │  for Search.  Legend: [*] built-in  [ ] excluded  <M> module  < >       │  
 │ ┌─^(-)────────────────────────────────────────────────────────────────┐ │  
 │ │ [*]   Enable system-call auditing support                           │ │  
 │ │ (14) Kernel log buffer size (16 => 64KB, 17 => 128KB)               │ │  
 │ │ [*] Support for hot-pluggable devices                               │ │  
 │ │ [ ] Kernel .config support                                          │ │  
 │ │ [ ] Configure standard kernel features (for small systems)  --->    │ │  
 │ └─────────────────────────────────────────────────────────────────────┘ │  
 ├─────────────────────────────────────────────────────────────────────────┤  
 │                    <Select>    < Exit >    < Help >                     │  
 └─────────────────────────────────────────────────────────────────────────┘  

There are borders and buttons, all drawn with characters. One can navigate the menu like one would with a graphical interface in X, selecting categories and checking off options.

The same configuration can be done without curses, using make config:

* Linux Kernel Configuration
*
*
* Code maturity level options
*
Prompt for development and/or incomplete code/drivers (EXPERIMENTAL) [Y/n/?] 
  Select only drivers expected to compile cleanly (CLEAN_COMPILE) [Y/n/?] 
*
* General setup
*
Local version - append to kernel release (LOCALVERSION) [] 
Support for paging of anonymous memory (swap) (SWAP) [Y/n/?] 
System V IPC (SYSVIPC) [Y/n/?] 
POSIX Message Queues (POSIX_MQUEUE) [Y/n/?] 
BSD Process Accounting (BSD_PROCESS_ACCT) [N/y/?] 
Sysctl support (SYSCTL) [Y/n/?] 
Auditing support (AUDIT) [Y/n/?] 
  Enable system-call auditing support (AUDITSYSCALL) [Y/n/?] 
Kernel log buffer size (16 => 64KB, 17 => 128KB) (LOG_BUF_SHIFT) [14] 

This is the standard prompt-read system where one replies 'y'es, 'n'o, '?' help, and nothing to accept the default. All the options are iterated, and replied to one by one.

Curses applications are good for presenting loads information in a structured way, and to let the user interact with it . Non-curses applications, however, are scriptable.

References

See also

External links