Difference between revisions of "Curses notes"

From Helpful
Jump to: navigation, search
m
m
 
Line 1: Line 1:
 
{{stub}}
 
{{stub}}
  
 +
 +
==curses, ncurses==
 
curses is an API that lets you write text-mode interfaces - in a terminal-independent way based on [[terminfo]]/[[termcap]].
 
curses is an API that lets you write text-mode interfaces - in a terminal-independent way based on [[terminfo]]/[[termcap]].
  
Line 6: Line 8:
  
  
ncurses is the modern implementation, which evolved from BSD and SysV curses - originally a clone but now its own thing.
+
ncurses is the modern implementation, which evolved from BSD and SysV curses.  
 
+
ncurses is a C library, though various wrappers exist. While most are fairly thin wrappers, they may still be less code for the same thing.
+
My notes below will use the python wrapper .
+
  
 +
ncurses was originally a clone but now its own thing.
  
 +
ncurses is a C library, though various wrappers exist.
 +
While most are fairly thin wrappers, they may still be less code for the same thing.
  
  
 +
===Command line wrappers for some simple dialogs===
 
Related:
 
Related:
 
* [https://en.wikipedia.org/wiki/Dialog_(software) dialog], built on curses/ncurses, provides GUI-like widgets in text mode from a script-like description
 
* [https://en.wikipedia.org/wiki/Dialog_(software) dialog], built on curses/ncurses, provides GUI-like widgets in text mode from a script-like description
Line 31: Line 34:
  
 
<!--
 
<!--
 +
* (see has_colors to check whether the terminal supports colors)
 +
* call start_color() (after initscr, before any color manipulation)
 +
* call init_pair() to initialize colors
 +
 +
 +
* (see can_change_color to check whether you can redefine colors)
 +
 +
 +
* pair_content fetches the two colors in a pair{{verify}}
 +
* color_content() fetches amount of r,g,b in an initialized color.
 +
 +
 +
 
ncurses stores color pairs, foreground and background.
 
ncurses stores color pairs, foreground and background.
  
It focuses on the 8 ANSI colors,  
+
 
 +
You can have
 +
* up to COLORS amount of colors defined,
 +
* up to COLOR_PAIRS amount of pairs defined
 +
 
 +
 
 +
 
 +
 
 +
Basic functionality focuses on the main 8 ANSI colors,  
 +
though true color has been introduced in ncurses 6
 +
 
  
 
In the basic use, you would  
 
In the basic use, you would  
Line 47: Line 73:
 
  COLOR_WHITE
 
  COLOR_WHITE
  
colorpair is an enumeration of the pairs you have initialised. In many practical cases your program wants to work from the colors themselves - so you'll want your own lookup from colors to ncurses-colorpair.
+
 
 +
init_pair returns an enumeration of to ''pairs'' you have initialised.
 +
 
 +
Some program may want their own lookups between this and the actual colors.
 +
 
 +
 
  
  
  
true color has been introduced in ncurses 6
 
 
-->
 
-->
  

Latest revision as of 17:55, 10 October 2019

This article/section is a stub — probably a pile of half-sorted notes, is not well-checked so may have incorrect bits. (Feel free to ignore, fix, or tell me)


curses, ncurses

curses is an API that lets you write text-mode interfaces - in a terminal-independent way based on terminfo/termcap.

It also optimizes what changes are transmitted, which mattered in the days of slow remote shells.


ncurses is the modern implementation, which evolved from BSD and SysV curses.

ncurses was originally a clone but now its own thing.

ncurses is a C library, though various wrappers exist. While most are fairly thin wrappers, they may still be less code for the same thing.


Command line wrappers for some simple dialogs

Related:

  • dialog, built on curses/ncurses, provides GUI-like widgets in text mode from a script-like description
  • newt, effectively an alternative to ncurses
  • whiptail, like dialog (and largely compatible) but built on newt. Simple example

Example:

dialog   --title "Example" --msgbox "Hit OK to continue." 8 78
whiptail --title "Example" --msgbox "Hit OK to continue." 8 78



Colors

See also