curs_slk(3X)
π curs_slk β library calls π
hiii bestie π so this page is curs_slk(3X) from the library calls chapter of the ncurses manual, and it's literally all about the soft label keys β the little function-key labels chillin' at the bottom of your screen. it's giving group chat energy but for terminal labels. let's go β¨
β¨ NAME β¨
slk_init, slk_set, slk_wset, slk_refresh, slk_noutrefresh, slk_label, slk_clear, slk_restore, slk_touch, slk_attron, slk_attrset, slk_attroff, slk_attr_on, slk_attr_set, slk_attr_off, slk_attr, slk_color, extended_slk_color β the curses soft label key routines π·οΈ
π¦ SYNOPSIS π¦
#include <curses.h>
int slk_init(int fmt);
int slk_set(int labnum, const char *label, int align);
int slk_wset(int labnum, const wchar_t *label, int align);
char *slk_label(int labnum);
int slk_refresh(void);
int slk_noutrefresh(void);
int slk_clear(void);
int slk_restore(void);
int slk_touch(void);
int slk_attron(const chtype attrs);
int slk_attroff(const chtype attrs);
int slk_attrset(const chtype attrs);
int slk_attr_on(attr_t attrs, void *opts);
int slk_attr_off(const attr_t attrs, void *opts);
int slk_attr_set(const attr_t attrs, short pair, void*opts);
/* extension */
attr_t slk_attr(void);
int slk_color(short pair);
/* extension */
int extended_slk_color(int pair);
πΈ DESCRIPTION πΈ
okay so these functions are the whole girlboss squad that manipulates the soft function key labels that some hardware terminals support. not every terminal has them tho β and for the ones that don't, curses just takes over the bottom line of stdscr for itself, reducing its vertical size and the value of LINES by one. rude but necessary π
by default, curses uses eight labels of up to eight characters each.
ncurses also supports a whole other mode β twelve labels of up to five characters each β following a convention associated with the IBM PC/AT keyboard. ncurses simulates this mode by taking over up to two lines at the bottom of the screen; it does not try to use any hardware support for this mode. no cap.
π§ Initialization
slk_init must be called before initscr or newterm β like, non-negotiable, bestie. if initscr eventually uses a line from stdscr to emulate the soft labels, then fmt decides how the labels are arranged on the screen:
0β indicates a 3-2-3 arrangement of the labels.1β indicates a 4-4 arrangement.2β indicates the PC-like 4-4-4 mode.3β is again the PC-like 4-4-4 mode, but in addition an index line is generated, helping the user to associate each label with its numbered function key.LINESand the vertical size ofstdscrare further reduced.
π·οΈ Labels
you populate the labels with normal strings (slk_set) or wide-character strings (slk_wset). each function takes three parameters:
labnumβ is the label number, from1to8(12iffmtinslk_initis2or3);labelβ is be the string to put on the label, up to eight (five iffmtinslk_initis2or3) characters in length. an empty string or a null pointer sets up a blank label.alignβ is0,1, or2, aligninglabelto the left, center, or right, respectively, within the 8 (5) character cells housing it.
slk_label obtains the string assigned to label number labnum, with any leading and trailing blanks stripped. so fresh β¨
π₯οΈ Screen Updates
slk_refresh and slk_noutrefresh affect the soft key label lines the same way wrefresh and wnoutrefresh do the curses window.
the slk_clear routine clears the soft labels from the screen.
the slk_restore routine restores the soft labels to the screen after a slk_clear has been performed. it's giving comeback era π«Ά
the slk_touch routine forces all the soft labels to be output the next time a slk_noutrefresh is performed.
π¨ Video Attributes
the slk_attron, slk_attrset, slk_attroff, and slk_attr routines correspond to attron, attrset, attroff, and attr_get, respectively. they have an effect only if soft labels are simulated on the bottom line of the screen. the default highlight for soft key labels is A_STANDOUT (as in System V curses, which does not document this fact). iykyk π
π Colors
the slk_color routine corresponds to color_set. it has an effect only if soft labels are simulated on the bottom line of the screen.
because slk_color accepts only short (signed 16-bit integer) values, this implementation provides extended_slk_color, which accepts an int value of at least 32 bits. glow-up behavior fr fr π
π RETURN VALUE π
functions that return integers return ERR upon failure and OK upon success.
in ncurses:
slk_attrβ returns the attribute used for the soft keys.slk_attroff,slk_attron,slk_clear,slk_noutrefresh,slk_refresh,slk_touchβ returnERRif the terminal or the softkeys were not initialized.slk_attrsetβ returnsERRif the terminal or the softkeys were not initialized.slk_attr_setβ returnsERRif the terminal or the softkeys were not initialized, or the color pair is outside the range0..COLOR_PAIRS-1.slk_colorβ returnsERRif the terminal or the softkeys were not initialized, or the color pair is outside the range0..COLOR_PAIRS-1.slk_initβ returnsERRif the format parameter is outside the range0..3.slk_labelβ returnsNULLon error.slk_setβ returnsERRif the terminal or the softkeys were not initialized, or thelabnumparameter is outside the range of label counts, or if the format parameter is outside the range0..2, or if memory for the labels cannot be allocated.
π NOTES π
most applications would use slk_noutrefresh because a wrefresh is likely to follow soon. efficient queen behavior π
π EXTENSIONS π
X/Open Curses documents the opts argument as reserved for future use, saying that it must be a null pointer. the ncurses 6 ABI uses it for the functions that accept a color pair parameter to support extended color pairs.
for functions which modify the color, e.g., slk_attr_set, if opts is set it is treated as a pointer to int, and used to set the color pair instead of the short pair parameter. sneaky but iconic π
π PORTABILITY π
X/Open Curses Issue 4 describes these functions. it specifies no error conditions for them.
SVr4 describes a successful return value only as βan integer value other than ERRβ.
- X/Open added functions like the SVr4 attribute-manipulation functions
slk_attron,slk_attroff, andslk_attrset, but which useattr_tparameters (rather thanchtype), along with a reservedoptsparameter.- two of these new functions (unlike the SVr4 functions) have no provision for color:
slk_attr_onandslk_attr_off. - the third function (
slk_attr_set) has a color pair parameter.
- two of these new functions (unlike the SVr4 functions) have no provision for color:
- it added
constqualifiers to parameters (unnecessarily), and - it added
slk_color.
although slk_start is declared in the curses header file, it was not documented by SVr4 other than its presence in a list of libtermlib.so.1 symbols. reading the source code (i.e., Illumos):
slk_starthas two parameters:ng(number of groups) andgp(group pointer).
- soft-key groups are an array of
ngintegers. - in SVr4,
slk_initcallsslk_startpassing a null forgp. for this case,slk_startuses the number of groupsng(3 for the 3-2-3 layout, 2 for the 4-4 layout) whichslk_initprovided. ifngis neither 2 or 3,slk_startchecks the terminfofln(label_format) capability, interpreting that as a comma-separated list of numbers, e.g., β3,2,3β for the 3-2-3 layout. finally, if there is noflncapability,slk_startreturnsERR. - if
slk_startis given a non-nullgp, it copies thengelements of the group of soft-keys, up to 16. if there are more than 16 elements,slk_startreturnsERR. - the format codes
2and3forslk_initwere added by ncurses in 1996. PDCurses 2.4 added this feature in 2001.
the function slk_attr was added by ncurses in 1996.
X/Open Curses does not specify a limit for the number of colors and color pairs which a terminal can support. however, in its use of short for the parameters, it carries over SVr4's implementation detail for the compiled terminfo database, which uses signed 16-bit numbers. this implementation provides extended versions of those functions which use int parameters, allowing applications to use larger color- and pair-numbers. growth mindset β¨
π HISTORY π
SVr3 introduced these functions:
slk_clearslk_initslk_labelslk_noutrefreshslk_refreshslk_restoreslk_setslk_touch
SVr4 added these functions:
slk_attroffslk_attronslk_attrsetslk_start
X/Open Curses added these:
slk_attr_offslk_attr_onslk_attr_setslk_colorslk_wset
π SEE ALSO π
curses(3X), curs_attr(3X), curs_initscr(3X), curs_refresh(3X), curs_variables(3X)
and that's the whole page bestie, no notes, we ate π this was written against ncurses 6.6 and dated 2025-01-18 β go forth and label those soft keys, mwah πππ¦
π¦ where this page comes from
- alpine 3.24: ncurses-doc 6.6_p20260516-r0 Β· X11
- arch rolling: ncurses 6.6-2 Β· MIT-open-group
- fedora 44: ncurses-devel 6.6-1.fc44 Β· MIT-open-group
- fedora 44: ncurses-devel 6.6-1.fc44 Β· MIT-open-group
- Copyright 2018-2024,2025 Thomas E. Dickey
- Copyright 1998-2016,2017 Free Software Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms