blob: fa25e68d3bc871381575f5cf2006abd866657d3e [file] [log] [blame]
Patrick Georgi3b77b722011-07-07 15:41:53 +02001PDCurses Implementor's Guide
2============================
3
4Version 1.3 - 200?/??/?? - notes about official ports
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -08005Version 1.2 - 2007/07/11 - added PDC_init_pair(), PDC_pair_content(),
Patrick Georgi3b77b722011-07-07 15:41:53 +02006 version history; removed pdc_atrtab
7Version 1.1 - 2007/06/06 - minor cosmetic change
8Version 1.0 - 2007/04/01 - initial revision
9
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -080010This document is for those wishing to port PDCurses to a new platform,
11or just wanting to better understand how it works. Nothing here should
12be needed for application programming; for that, refer to PDCurses.txt,
13as built in doc/, or distributed as a file separate from this source
14package. This document assumes that you've read the user-level
15documentation and are very familiar with application-level curses
Patrick Georgi3b77b722011-07-07 15:41:53 +020016programming.
17
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -080018If you want to submit your port for possible inclusion into the main
Patrick Georgi3b77b722011-07-07 15:41:53 +020019PDCurses distribution, please follow these guidelines:
20
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -080021 - Don't modify anything in the pdcurses directory or in other port
22 directories. Don't modify curses.h or curspriv.h unless absolutely
Patrick Georgi3b77b722011-07-07 15:41:53 +020023 necessary. (And prefer modifying curspriv.h over curses.h.)
24
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -080025 - Use the same indentation style, naming and scope conventions as the
Patrick Georgi3b77b722011-07-07 15:41:53 +020026 existing code.
27
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -080028 - Release all your code to the public domain -- no copyright. Code
Patrick Georgi3b77b722011-07-07 15:41:53 +020029 under GPL, BSD, etc. will not be accepted.
30
31
32DATA STRUCTURES
33---------------
34
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -080035A port of PDCurses must provide acs_map[], a 128-element array of
36chtypes, with values laid out based on the Alternate Character Set of
37the VT100 (see curses.h). PDC_transform_line() must use this table; when
38it encounters a chtype with the A_ALTCHARSET flag set, and an A_CHARTEXT
39value in the range 0-127, it must render it using the A_CHARTEXT portion
40of the corresponding value from this table, instead of the original
41value. Also, values may be read from this table by apps, and passed
42through functions such as waddch(), which does no special processing on
43control characters (0-31 and 127) when the A_ALTCHARSET flag is set.
44Thus, any control characters used in acs_map[] should also have the
45A_ALTCHARSET flag set. Implementations should provide suitable values
46for all the ACS_ macros defined in curses.h; other values in the table
47should be filled with their own indices (e.g., acs_map['E'] == 'E'). The
48table can be either hardwired, or filled by PDC_scr_open(). Existing
Patrick Georgi3b77b722011-07-07 15:41:53 +020049ports define it in pdcdisp.c, but this is not required.
50
51
52FUNCTIONS
53---------
54
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -080055A port of PDCurses must implement the following functions, with extern
56scope. These functions are traditionally divided into several modules,
57as indicated below; this division is not required (only the functions
58are), but may make it easier to follow for someone familiar with the
Patrick Georgi3b77b722011-07-07 15:41:53 +020059existing ports.
60
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -080061Any other functions you create as part of your implementation should
62have static scope, if possible. If they can't be static, they should be
63named with the "PDC_" prefix. This minimizes the risk of collision with
Patrick Georgi3b77b722011-07-07 15:41:53 +020064an application's choices.
65
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -080066Current PDCurses style also uses a single leading underscore with the
67name of any static function; and modified BSD/Allman-style indentation,
68approximately equivalent to "indent -kr -i8 -bl -bli0", with adjustments
69to keep every line under 80 columns. This isn't essential, but a
Patrick Georgi3b77b722011-07-07 15:41:53 +020070consistent style helps readability.
71
72
73pdcdisp.c:
74----------
75
76void PDC_gotoyx(int y, int x);
77
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -080078Move the physical cursor (as opposed to the logical cursor affected by
79wmove()) to the given location. This is called mainly from doupdate().
80In general, this function need not compare the old location with the new
Patrick Georgi3b77b722011-07-07 15:41:53 +020081one, and should just move the cursor unconditionally.
82
83void PDC_transform_line(int lineno, int x, int len, const chtype *srcp);
84
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -080085The core output routine. It takes len chtype entities from srcp (a
86pointer into curscr) and renders them to the physical screen at line
87lineno, column x. It must also translate characters 0-127 via acs_map[],
88if they're flagged with A_ALTCHARSET in the attribute portion of the
Patrick Georgi3b77b722011-07-07 15:41:53 +020089chtype.
90
91
92pdcgetsc.c:
93-----------
94
95int PDC_get_columns(void);
96
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -080097Returns the size of the screen in columns. It's used in resize_term() to
98set the new value of COLS. (Some existing implementations also call it
Patrick Georgi3b77b722011-07-07 15:41:53 +020099internally from PDC_scr_open(), but this is not required.)
100
101int PDC_get_cursor_mode(void);
102
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -0800103Returns the size/shape of the cursor. The format of the result is
104unspecified, except that it must be returned as an int. This function is
105called from initscr(), and the result is stored in SP->orig_cursor,
106which is used by PDC_curs_set() to determine the size/shape of the
Patrick Georgi3b77b722011-07-07 15:41:53 +0200107cursor in normal visibility mode (curs_set(1)).
108
109int PDC_get_rows(void);
110
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -0800111Returns the size of the screen in rows. It's used in resize_term() to
112set the new value of LINES. (Some existing implementations also call it
Patrick Georgi3b77b722011-07-07 15:41:53 +0200113internally from PDC_scr_open(), but this is not required.)
114
115
116pdckbd.c:
117---------
118
119bool PDC_check_key(void);
120
121Keyboard/mouse event check, called from wgetch(). Returns TRUE if
122there's an event ready to process. This function must be non-blocking.
123
124void PDC_flushinp(void);
125
126This is the core of flushinp(). It discards any pending key or mouse
127events, removing them from any internal queue and from the OS queue, if
128applicable.
129
130int PDC_get_key(void);
131
132Get the next available key, or mouse event (indicated by a return of
133KEY_MOUSE), and remove it from the OS' input queue, if applicable. This
134function is called from wgetch(). This function may be blocking, and
135traditionally is; but it need not be. If a valid key or mouse event
136cannot be returned, for any reason, this function returns -1. Valid keys
137are those that fall within the appropriate character set, or are in the
138list of special keys found in curses.h (KEY_MIN through KEY_MAX). When
139returning a special key code, this routine must also set SP->key_code to
140TRUE; otherwise it must set it to FALSE. If SP->return_key_modifiers is
141TRUE, this function may return modifier keys (shift, control, alt),
142pressed alone, as special key codes; if SP->return_key_modifiers is
143FALSE, it must not. If modifier keys are returned, it should only happen
144if no other keys were pressed in the meantime; i.e., the return should
145happen on key up. But if this is not possible, it may return the
146modifier keys on key down (if and only if SP->return_key_modifiers is
147TRUE).
148
149int PDC_modifiers_set(void);
150
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -0800151Called from PDC_return_key_modifiers(). If your platform needs to do
152anything in response to a change in SP->return_key_modifiers, do it
Patrick Georgi3b77b722011-07-07 15:41:53 +0200153here. Returns OK or ERR, which is passed on by the caller.
154
155int PDC_mouse_set(void);
156
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -0800157Called by mouse_set(), mouse_on(), and mouse_off() -- all the functions
158that modify SP->_trap_mbe. If your platform needs to do anything in
159response to a change in SP->_trap_mbe (for example, turning the mouse
160cursor on or off), do it here. Returns OK or ERR, which is passed on by
Patrick Georgi3b77b722011-07-07 15:41:53 +0200161the caller.
162
163void PDC_set_keyboard_binary(bool on);
164
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -0800165Set keyboard input to "binary" mode. If you need to do something to keep
166the OS from processing ^C, etc. on your platform, do it here. TRUE turns
167the mode on; FALSE reverts it. This function is called from raw() and
Patrick Georgi3b77b722011-07-07 15:41:53 +0200168noraw().
169
170
171pdcscrn.c:
172----------
173
174bool PDC_can_change_color(void);
175
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -0800176Returns TRUE if init_color() and color_content() give meaningful
Patrick Georgi3b77b722011-07-07 15:41:53 +0200177results, FALSE otherwise. Called from can_change_color().
178
179int PDC_color_content(short color, short *red, short *green, short *blue);
180
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -0800181The core of color_content(). This does all the work of that function,
Patrick Georgi3b77b722011-07-07 15:41:53 +0200182except checking for values out of range and null pointers.
183
184int PDC_init_color(short color, short red, short green, short blue);
185
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -0800186The core of init_color(). This does all the work of that function,
Patrick Georgi3b77b722011-07-07 15:41:53 +0200187except checking for values out of range.
188
189void PDC_init_pair(short pair, short fg, short bg);
190
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -0800191The core of init_pair(). This does all the work of that function, except
192checking for values out of range. The values passed to this function
193should be returned by a call to PDC_pair_content() with the same pair
194number. PDC_transform_line() should use the specified colors when
Patrick Georgi3b77b722011-07-07 15:41:53 +0200195rendering a chtype with the given pair number.
196
197int PDC_pair_content(short pair, short *fg, short *bg);
198
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -0800199The core of pair_content(). This does all the work of that function,
Patrick Georgi3b77b722011-07-07 15:41:53 +0200200except checking for values out of range and null pointers.
201
202void PDC_reset_prog_mode(void);
203
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -0800204The non-portable functionality of reset_prog_mode() is handled here --
205whatever's not done in _restore_mode(). In current ports: In OS/2, this
206sets the keyboard to binary mode; in Win32, it enables or disables the
Patrick Georgi3b77b722011-07-07 15:41:53 +0200207mouse pointer to match the saved mode; in others it does nothing.
208
209void PDC_reset_shell_mode(void);
210
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -0800211The same thing, for reset_shell_mode(). In OS/2 and Win32, it restores
Patrick Georgi3b77b722011-07-07 15:41:53 +0200212the default console mode; in others it does nothing.
213
214int PDC_resize_screen(int nlines, int ncols);
215
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -0800216This does the main work of resize_term(). It may respond to non-zero
217parameters, by setting the screen to the specified size; to zero
218parameters, by setting the screen to a size chosen by the user at
219runtime, in an unspecified way (e.g., by dragging the edges of the
220window); or both. It may also do nothing, if there's no appropriate
Patrick Georgi3b77b722011-07-07 15:41:53 +0200221action for the platform.
222
223void PDC_restore_screen_mode(int i);
224
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -0800225Called from _restore_mode() in kernel.c, this function does the actual
Patrick Georgi3b77b722011-07-07 15:41:53 +0200226mode changing, if applicable. Currently used only in DOS and OS/2.
227
228void PDC_save_screen_mode(int i);
229
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -0800230Called from _save_mode() in kernel.c, this function saves the actual
Patrick Georgi3b77b722011-07-07 15:41:53 +0200231screen mode, if applicable. Currently used only in DOS and OS/2.
232
233void PDC_scr_close(void);
234
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -0800235The platform-specific part of endwin(). It may restore the image of the
236original screen saved by PDC_scr_open(), if the PDC_RESTORE_SCREEN
237environment variable is set; either way, if using an existing terminal,
238this function should restore it to the mode it had at startup, and move
Patrick Georgi3b77b722011-07-07 15:41:53 +0200239the cursor to the lower left corner. (The X11 port does nothing.)
240
241void PDC_scr_free(void);
242
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -0800243Frees the memory for SP allocated by PDC_scr_open(). Called by
Patrick Georgi3b77b722011-07-07 15:41:53 +0200244delscreen().
245
246int PDC_scr_open(int argc, char **argv);
247
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -0800248The platform-specific part of initscr(). It's actually called from
249Xinitscr(); the arguments, if present, correspond to those used with
250main(), and may be used to set the title of the terminal window, or for
251other, platform-specific purposes. (The arguments are currently used
252only in X11.) PDC_scr_open() must allocate memory for SP, and must
253initialize acs_map[] (unless it's preset) and several members of SP,
254including lines, cols, mouse_wait, orig_attr (and if orig_attr is TRUE,
255orig_fore and orig_back), mono, _restore and _preserve. (Although SP is
256used the same way in all ports, it's allocated here in order to allow
257the X11 port to map it to a block of shared memory.) If using an
258existing terminal, and the environment variable PDC_RESTORE_SCREEN is
259set, this function may also store the existing screen image for later
Patrick Georgi3b77b722011-07-07 15:41:53 +0200260restoration by PDC_scr_close().
261
262
263pdcsetsc.c:
264-----------
265
266int PDC_curs_set(int visibility);
267
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -0800268Called from curs_set(). Changes the appearance of the cursor -- 0 turns
269it off, 1 is normal (the terminal's default, if applicable, as
270determined by SP->orig_cursor), and 2 is high visibility. The exact
Patrick Georgi3b77b722011-07-07 15:41:53 +0200271appearance of these modes is not specified.
272
273
274pdcutil.c:
275----------
276
277void PDC_beep(void);
278
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -0800279Emits a short audible beep. If this is not possible on your platform,
280you must set SP->audible to FALSE during initialization (i.e., from
281PDC_scr_open() -- not here); otherwise, set it to TRUE. This function is
Patrick Georgi3b77b722011-07-07 15:41:53 +0200282called from beep().
283
284void PDC_napms(int ms);
285
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -0800286This is the core delay routine, called by napms(). It pauses for about
287(the X/Open spec says "at least") ms milliseconds, then returns. High
288degrees of accuracy and precision are not expected (though desirable, if
289you can achieve them). More important is that this function gives back
290the process' time slice to the OS, so that PDCurses idles at low CPU
Patrick Georgi3b77b722011-07-07 15:41:53 +0200291usage.
292
293const char *PDC_sysname(void);
294
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -0800295Returns a short string describing the platform, such as "DOS" or "X11".
296This is used by longname(). It must be no more than 100 characters; it
Patrick Georgi3b77b722011-07-07 15:41:53 +0200297should be much, much shorter (existing platforms use no more than 5).
298
299--------------------------------------------------------------------------
300
Stefan Reinauer5bbc5e52015-11-10 09:13:43 -0800301The following functions are implemented in the platform directories, but
302are accessed directly by apps. Refer to the user documentation for their
Patrick Georgi3b77b722011-07-07 15:41:53 +0200303descriptions:
304
305
306pdcclip.c:
307----------
308
309int PDC_clearclipboard(void);
310int PDC_freeclipboard(char *contents);
311int PDC_getclipboard(char **contents, long *length);
312int PDC_setclipboard(const char *contents, long length);
313
314
315pdckbd.c:
316---------
317
318unsigned long PDC_get_input_fd(void);
319
320
321pdcsetsc.c:
322-----------
323
324int PDC_set_blink(bool blinkon);
325void PDC_set_title(const char *title);