Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5a00769

Browse files
Documented curses.wrapper and curses.textpad.
1 parent 5af256d commit 5a00769

1 file changed

Lines changed: 131 additions & 2 deletions

File tree

Doc/lib/libcurses.tex

Lines changed: 131 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
\section{\module{curses} ---
22
Screen painting and input handling for character-cell terminals}
33

4-
\declaremodule{extension}{curses}
4+
\declaremodule{standard}{curses}
55
\sectionauthor{Moshe Zadka}{[email protected]}
66
\sectionauthor{Eric Raymond}{[email protected]}
77
\modulesynopsis{An interface to the curses library.}
8+
\versionadded{1.6}
89

910
The \module{curses} module provides an interface to the curses \UNIX{}
1011
library, the de-facto standard for portable advanced terminal
@@ -20,7 +21,7 @@ \section{\module{curses} ---
2021
\seemodule{curses.ascii}{Utilities for working with \ASCII{}
2122
characters, regardless of your locale
2223
settings.}
23-
\seemodule{curses.textbox}{Editable text widget for curses supporting
24+
\seemodule{curses.textpad}{Editable text widget for curses supporting
2425
Emacs-like bindings.}
2526
\seetext{Tutorial material on using curses with Python is available
2627
on the Python Web site as Andrew Kuchling's
@@ -1163,3 +1164,131 @@ \subsection{Constants}
11631164
\lineii{COLOR_YELLOW}{Yellow}
11641165
\end{tableii}
11651166

1167+
\section{\module{curses.textpad} ---
1168+
Text input widget for curses programs}
1169+
1170+
\declaremodule{standard}{curses.textpad}
1171+
\sectionauthor{Eric Raymond}{[email protected]}
1172+
\moduleauthor{Eric Raymond}{[email protected]}
1173+
\modulesynopsis{Emacs-like input editing in a curses window.}
1174+
\versionadded{1.6}
1175+
1176+
The \module{curses.textpad} module provides a \class{Textbox} class
1177+
that handles elementary text editing in a curses window, supporting a
1178+
set of keybindings resembling those of Emacs (thus, also of Netscape
1179+
Navigator, BBedit 6.x, FrameMaker, and many other programs). The
1180+
module also provides a rectangle-drawing function useful for framing
1181+
text boxes or for other purposes.
1182+
1183+
\subsection{Functions \label{curses-textpad-functions}}
1184+
1185+
The module \module{curses.textpad} defines the following functions:
1186+
1187+
\begin{funcdesc}{rectangle}{win, uly, ulx, lry, lrx}
1188+
Draw a rectangle. The first argument must be a window object; the
1189+
remaining arguments are coordinates relative to that window. The
1190+
second and third arguments are the y and x coordinates of the upper
1191+
left hand corner of the rectangle To be drawn; the fourth and fifth
1192+
arguments are the y and x coordinates of the lower right hand corner.
1193+
The rectangle will be drawn using VT100/IBM PC forms characters on
1194+
terminals that make this possible (including xterm and most other
1195+
software terminal emulators). Otherwise it will be drawn with ASCII
1196+
dashes, vertical bars, and plus signs.
1197+
\end{funcdesc}
1198+
1199+
\subsection{Textbox objects \label{curses-textpad-objects}}
1200+
1201+
You can instantiate a \class{Textbox} object as follows:
1202+
1203+
\classdesc{Textbox}{win}
1204+
Return a textbox widget object. The win argument should be a curses
1205+
\class{WindowObject} in which the textbox is to be contained. The
1206+
edit cursor of the textbox is initially located at the upper left
1207+
hand corner of the containin window, with coordinates (0,0). The
1208+
instance's \member{stripspaces} flag is initially on.
1209+
\end{classdesc}
1210+
1211+
Textbox objects, have the following methods:
1212+
1213+
\begin{methoddesc}{edit}{validator=None}
1214+
This is the entry point you will normally use. It accepts editing
1215+
keystrokes until one of the termination keystrokes is entered. If a
1216+
validator function is specified, each entered keystroke is passed to
1217+
it; command dispatch is done on the result. This method returns the
1218+
window contents as a string; whether blanks in the window are included
1219+
is affected by the \member{stripspaces} member.
1220+
\end{methoddesc}
1221+
1222+
\begin{methoddesc}{do_command}{ch}
1223+
Process a single command keystroke. Here are the supported special
1224+
keystrokes:
1225+
1226+
\begin{tableii}{c|l}{code}{keystroke}{action}
1227+
\lineii{Ctrl-A}{Go to left edge of window.}
1228+
\lineii{Ctrl-B}{Cursor left, wrapping to previous line if appropriate.}
1229+
\lineii{Ctrl-D}{Delete character under cursor.}
1230+
\lineii{Ctrl-E}{Go to right edge (stripspaces off) or end of line (stripspaces on).}
1231+
\lineii{Ctrl-F}{Cursor right, wrapping to next line when appropriate.}
1232+
\lineii{Ctrl-G}{Terminate, returning the window contents.}
1233+
\lineii{Ctrl-H}{Delete character backward.}
1234+
\lineii{Ctrl-J}{Terminate if the window is 1 line, otherwise insert newline.}
1235+
\lineii{Ctrl-K}{If line is blank, delete it, otherwise clear to end of line.}
1236+
\lineii{Ctrl-L}{Refresh screen.}
1237+
\lineii{Ctrl-N}{Cursor down; move down one line.}
1238+
\lineii{Ctrl-O}{Insert a blank line at cursor location.}
1239+
\lineii{Ctrl-P}{Cursor up; move up one line.}
1240+
\end{tableii}
1241+
1242+
Move operations do nothing if the cursor is at an edge where the
1243+
movement is not possible. The following synonyms are supported where
1244+
possible: KEY_LEFT = Ctrl-B, KEY_RIGHT = Ctrl-F, KEY_UP = Ctrl-P,
1245+
KEY_DOWN = Ctrl-N, KEY_BACKSPACE = Ctrl-h.
1246+
1247+
All other keystrokes are treated as a command to insert the given
1248+
character and move right (with line wrapping).
1249+
\end{methoddesc}
1250+
1251+
\begin{methoddesc}{gather}{}
1252+
This method returns the window contents as a string; whether blanks in
1253+
the window are included is affected by the \member{stripspaces}
1254+
member.
1255+
\end{methoddesc}
1256+
1257+
\begin{methoddesc}{stripspaces}{}
1258+
This data member is a flag which controls the interpretation of blanks in
1259+
the window. When it is on, trailing blanks on each line are ignored;
1260+
any cursor motion that would land the cursor on a trailing blank goes
1261+
to the end of that line instead, and trailing blanks are stripped when
1262+
the window contents is gathered.
1263+
\end{methoddesc}
1264+
1265+
\section{\module{curses.wrapper} ---
1266+
Exception-handling wrapper for curses programs.}
1267+
1268+
\declaremodule{standard}{curses.wrapper}
1269+
\sectionauthor{Eric Raymond}{[email protected]}
1270+
\moduleauthor{Eric Raymond}{[email protected]}
1271+
\modulesynopsis{Exception-handling wrapper for curses programs.}
1272+
\versionadded{1.6}
1273+
1274+
This module supplies one function, \function{wrapper()}, which runs
1275+
another function which should be the rest of your curses-using
1276+
application. If the application raises an exception,
1277+
\function{wrapper()} will restore the terminal to a sane state before
1278+
passing it further up the stack and generating a traceback.
1279+
1280+
\subsection{Functions \label{curses-wrapper-functions}}
1281+
1282+
\begin{funcdesc}{wrapper}{func, *rest}
1283+
Wrapper function that initializes curses and calls another function,
1284+
\function{func}, restoring normal keyboard/screen behavior on error.
1285+
The callable object 'func' is then passed the main window 'stdscr'
1286+
as its first argument, followed by any other arguments passed to
1287+
\function{wrapper()}.
1288+
\end{funcdesc}
1289+
1290+
Before calling the hook function, \function{wrapper()} turns on
1291+
cbreak mode, turns off echo, and enables the terminal keypad. On
1292+
exit (whether normally or by exception) it restores cooked mode,
1293+
turns on echo, and disables the terminal keypad.
1294+

0 commit comments

Comments
 (0)