cdk_fselect(3)

πŸ“¦
version 5.0.20260119 Β· 3 versions
, in debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– cdk_fselect β€” Cdk file selector widget πŸ’–

okay bestie, pull up a chair because we're talking about cdk_fselect, the Cdk file selector widget, from the Library calls section of the manual. it's giving "let your users roam the filesystem from inside your TUI" and honestly? iconic.


✨ NAME ✨

cdk_fselect β€” Cdk file selector widget πŸŽ€


🌸 SYNOPSIS 🌸

first things first, you gotta link the library, no cap:

cc [ flag ... ] file ...  -lcdk [ library ... ]

and obvi you pull in the header:

#include <cdk.h>

then it's function o'clock. here's the whole roster, bestie, every single one:

char *activateCDKFselect (
               CDKFSELECT *fselect,
               chtype *actions);
void deleteFileCB (
               EObjectType objectType,
               void *object,
               void *clientData);
void destroyCDKFselect (
               CDKFSELECT *fselect);
void drawCDKFselect (
               CDKFSELECT *fselect,
               boolean box);
void eraseCDKFselect (
               CDKFSELECT *fselect);
boolean getCDKFselectBox (
               CDKFSELECT *fselect);
char **getCDKFselectContents (
               CDKFSELECT *widget,
               int *size);
int getCDKFselectCurrentItem (
               CDKFSELECT *widget);
char *getCDKFselectDirAttribute (
               CDKFSELECT *fselect);
char **getCDKFselectDirContents (
               CDKFSELECT *fselect,
               int *count);
char *getCDKFselectDirectory (
               CDKFSELECT *fselect);
char *getCDKFselectFileAttribute (
               CDKFSELECT *fselect);
chtype getCDKFselectFillerChar (
               CDKFSELECT *fselect);
chtype getCDKFselectHighlight (
               CDKFSELECT *fselect);
char *getCDKFselectLinkAttribute (
               CDKFSELECT *fselect);
char *getCDKFselectSocketAttribute (
               CDKFSELECT *fselect);
char *injectCDKFselect (
               CDKFSELECT *fselect,
               chtype input);
void moveCDKFselect (
               CDKFSELECT *fselect,
               int xpos,
               int ypos,
               boolean relative,
               boolean refresh);
CDKFSELECT *newCDKFselect (
               CDKSCREEN *cdkscreen,
               int xpos,
               int ypos,
               int height,
               int width,
               const char *title,
               const char *label,
               chtype fieldAttribute,
               chtype fillerCharacter,
               chtype highlight,
               const char *dirAttribute,
               const char *fileAttribute,
               const char *linkAttribute,
               const char *sockAttribute,
               boolean box,
               boolean shadow);
void positionCDKFselect (
               CDKFSELECT *fselect);
void setCDKFselect (
               CDKFSELECT *fselect,
               const char *directory,
               chtype fieldAttribute,
               chtype fillerCharacter,
               chtype highlight,
               const char *dirAttribute,
               const char *fileAttribute,
               const char *linkAttribute,
               const char *sockAttribute,
               boolean box);
void setCDKFselectBackgroundAttrib (
               CDKFSELECT *fselect,
               chtype attribute);
void setCDKFselectBackgroundColor (
               CDKFSELECT *fselect,
               const char * color);
void setCDKFselectBox (
               CDKFSELECT *fselect,
               boolean box);
void setCDKFselectBoxAttribute (
               CDKFSELECT *fselect,
               chtype character);
void setCDKFselectContents (
               CDKFSELECT *widget,
               CDK_CONST char **list,
               int listSize);
void setCDKFselectCurrentItem (
               CDKFSELECT *widget,
               int item);
void setCDKFselectDirAttribute (
               CDKFSELECT *fselect,
               const char *attribute);
int setCDKFselectDirContents (
               CDKFSELECT *fselect);
int setCDKFselectDirectory (
               CDKFSELECT *fselect,
               const char *directory);
void setCDKFselectFileAttribute (
               CDKFSELECT *fselect,
               const char *attribute);
void setCDKFselectFillerChar (
               CDKFSELECT *fselect,
               chtype filler);
void setCDKFselectHighlight (
               CDKFSELECT *fselect,
               chtype highlight);
void setCDKFselectHorizontalChar (
               CDKFSELECT *fselect,
               chtype character);
void setCDKFselectLLChar (
               CDKFSELECT *fselect,
               chtype character);
void setCDKFselectLRChar (
               CDKFSELECT *fselect,
               chtype character);
void setCDKFselectLinkAttribute (
               CDKFSELECT *fselect,
               const char *attribute);
void setCDKFselectSocketAttribute (
               CDKFSELECT *fselect,
               const char *attribute);
void setCDKFselectULChar (
               CDKFSELECT *fselect,
               chtype character);
void setCDKFselectURChar (
               CDKFSELECT *fselect,
               chtype character);
void setCDKFselectVerticalChar (
               CDKFSELECT *fselect,
               chtype character);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so the Cdk file selector widget? it literally creates a widget which allows a user to interact with the Unix file system. that's the whole vibe. your user gets to traverse the file system β€” like, walk around it, browse it, poke at it β€” and it can even delete files. bestie. DELETE FILES. that is a lot of power in one little widget and we are not being chill about it.

⚠️ heads up, the deleting-files situation has its own lore β€” go read the NOTES section below (coming in a later part of this page, iykyk) for more information before you let anyone go feral with this thing. πŸ™ˆ

to be continued, bestie β€” more sections incoming πŸ’…

🫢 AVAILABLE FUNCTIONS 🫢

okay bestie, here's the whole roster of functions, and I'm not skipping a single one. every param, every return, every lil caveat. lock in πŸ’…


  • activateCDKFselect β€” wakes the file selector widget up and lets the user actually interact with it.
    • the parameter fselect is a pointer to a non-NULL file selector widget.
    • if the actions parameter gets passed a non-NULL value, the characters in that array get injected into the widget.

to activate the widget interactively, pass in a NULL pointer for actions.

if the character entered into this widget is RETURN or TAB, then this function returns a char * representing the info typed into the widget, and the widget data exitType gets set to vNORMAL.

if the character entered was ESCAPE, the function returns a NULL pointer and the widget data exitType is set to vESCAPE_HIT.

  • deleteFileCB β€” prompts the user to confirm, and deletes the current item in the file-list. 😭 (yes it really does that, be careful)
  • destroyCDKFselect β€” removes the widget from the screen and frees the memory the object used. bye bestie, gone for real πŸ¦‹
  • drawCDKFselect β€” draws the fselect widget on the screen. if the box option is true, the widget is drawn with a box. πŸ“¦
  • eraseCDKFselect β€” removes the widget from the screen. this does NOT destroy the widget. it's just hiding, not ghosting ✨
  • getCDKFselectBox β€” returns true if the widget will be drawn with a box around it.
  • getCDKFselectContents β€” returns the directory-contents (which are formatted), and sets the number of entries via the size parameter.
  • getCDKFselectCurrentItem β€” returns the current position in the scroll-widget.
  • getCDKFselectDirAttribute β€” returns the attribute that directories are drawn with in the scrolling region of the widget.
  • getCDKFselectDirContents β€” returns the list of files and the corresponding count as a side-effect. if no files are found, this function returns zero, otherwise one.
  • getCDKFselectDirectory β€” returns the current directory of the widget.
  • getCDKFselectFileAttribute β€” returns the attribute that plain files are drawn with in the scrolling region of the widget.
  • getCDKFselectFillerChar β€” returns the character being used as the filler character in the entry field portion of the widget.
  • getCDKFselectHighlight β€” returns the attribute of the highlight bar of the scrolling list portion of the widget. the moment πŸ’…
  • getCDKFselectLinkAttribute β€” returns the attribute that symbolic links are drawn with in the scrolling region of the widget.
  • getCDKFselectSocketAttribute β€” returns the attribute that sockets are drawn with in the scrolling region of the widget.
  • injectCDKFselect β€” injects a single character into the widget. the parameter fselect is a pointer to a non-NULL file selector widget. the parameter character is the character to inject into the widget. the return value and the side-effect (setting the widget data exitType) depend on which character you injected:
    • RETURN or TAB β€” the function returns a char * representing the info typed into the widget. the widget data exitType is set to vNORMAL.
    • ESCAPE β€” the function returns a NULL pointer. the widget data exitType is set to vESCAPE_HIT.
    • otherwise β€” unless it got modified by preprocessing, postprocessing or key bindings, the function returns a NULL pointer. the widget data exitType is set to vEARLY_EXIT.
  • moveCDKFselect β€” moves the given widget to the given position. 🚚
    • the parameters xpos and ypos are the new position of the widget.
    • the parameter xpos may be an integer or one of the pre-defined values TOP, BOTTOM, and CENTER.
    • the parameter ypos may be an integer or one of the pre-defined values LEFT, RIGHT, and CENTER.
    • the parameter relative states whether the xpos/ypos pair is a relative move or an absolute move.

for example, if xpos = 1 and ypos = 2 and relative = TRUE, then the widget would move one row down and two columns right. if the value of relative was FALSE, then the widget would move to the position (1,2). do not use the values TOP, BOTTOM, LEFT, RIGHT, or CENTER when relative = TRUE. (weird things may happen). πŸ™ˆ

  • the final parameter refresh is a boolean value which states whether the widget will get refreshed after the move.
  • newCDKFselect β€” creates an fselect widget and returns a pointer to it. parameters:
    • the screen parameter is the screen you wish this widget to be placed in.
    • the parameter xpos controls the placement of the object along the horizontal axis. this parameter may be an integer or one of the pre-defined values LEFT, RIGHT, and CENTER.
    • ypos controls the placement of the object along the vertical axis. it may be an integer value or one of the pre-defined values TOP, BOTTOM, and CENTER.
    • height and width control the height and width of the widget. if you provide a value of zero for either of the height or the width, the widget will be created with the full width and height of the screen. if you provide a negative value, the widget will be created the full height or width minus the value provided.
    • title is the string which will be displayed at the top of the widget. the title can be more than one line; just provide a carriage return character at the line break.
    • label is the text to use as the label of the file selector.
    • fieldAttribute is the attribute of the entry field at the top of the widget;
    • fillerCharacter is the filler character for the entry field.
    • highlight is the highlight attribute on the scrolling list.
    • dirAttribute, fileAttribute, linkAttribute and sockAttribute are the attributes of directories, files, links, and sockets found in the directory list.
    • box is true if the widget should be drawn with a box around it.
    • shadow turns the shadow on or off around this widget.

if the widget could not be created then a NULL pointer is returned. πŸ’€

  • positionCDKFselect β€” allows the user to move the widget around the screen via the cursor/keypad keys. see cdk_position (3) for key bindings.
  • setCDKFselect β€” lets the programmer modify certain elements of an existing fselect widget. the parameter names correspond to the same parameter names listed in the newCDKFselect function.
  • setCDKFselectBackgroundAttrib β€” sets the background attribute of the widget. the parameter attribute is a curses attribute, e.g., A_BOLD.
  • setCDKFselectBackgroundColor β€” sets the background color of the widget. the parameter color is in the format of the Cdk format strings. see cdk_display (3). 🌈
  • setCDKFselectBox β€” sets whether the widget will be drawn with a box around it.
  • setCDKFselectBoxAttribute β€” sets the attribute of the box.
  • setCDKFselectContents β€” sets the contents of the widget.
  • setCDKFselectCurrentItem β€” set the current position in the scroll-widget.
  • setCDKFselectDirAttribute β€” sets the attribute that directories will be drawn with in the scrolling region of the widget.
  • setCDKFselectDirContents β€” this creates a list of the files in the current directory. see getCDKFselectDirContents.
  • setCDKFselectDirectory β€” sets the current directory of the widget.
  • setCDKFselectFileAttribute β€” sets the attribute that plain files will be drawn with in the scrolling region of the widget.
  • setCDKFselectFillerChar β€” sets the character to use when drawing the entry field portion of the widget.
  • setCDKFselectHighlight β€” sets the attribute of the highlight bar of the scrolling list portion of the widget.
  • setCDKFselectHorizontalChar β€” sets the horizontal drawing character for the box to the given character.
  • setCDKFselectLLChar β€” sets the lower left hand corner of the widget's box to the given character.
  • setCDKFselectLRChar β€” sets the lower right hand corner of the widget's box to the given character.
  • setCDKFselectLinkAttribute β€” sets the attribute that symbolic links will be drawn with in the scrolling region of the widget.
  • setCDKFselectSocketAttribute β€” sets the attribute that sockets will be drawn with in the scrolling region of the widget.
  • setCDKFselectULChar β€” sets the upper left hand corner of the widget's box to the given character.
  • setCDKFselectURChar β€” sets the upper right hand corner of the widget's box to the given character.
  • setCDKFselectVerticalChar β€” sets the vertical drawing character for the box to the given character.

✨ KEY BINDINGS ✨

okay so when the widget gets activated, there's a whole set of default key bindings ready to help you enter or manipulate info fast πŸ’…. and because this widget is literally built from both the scrolling list widget and the entry field widget, the key bindings are the same for the respective fields 🫢. the extra key bindings are the ones listed below, bestie:

  • CTRL-^ β€” shows you stats about the current filename πŸ“Š
  • Tab β€” tries to complete the current filename ✨
  • Up Arrow β€” scrolls the scrolling list up one line ⬆️
  • Down Arrow β€” scrolls the scrolling list down one line ⬇️
  • Page Up β€” scrolls the scrolling list up one page πŸ“„
  • CTRL-B β€” scrolls the scrolling list up one page πŸ“„
  • Page Down β€” scrolls the scrolling list down one page πŸ“„
  • CTRL-F β€” scrolls the scrolling list down one page πŸ“„
  • Return β€” returns the filename in the entry field of the file selector. it also sets the widget data exitType to vNORMAL πŸ‘‘
  • Escape β€” exits the widget and returns a NULL pointer. it also sets the widget data exitType to vESCAPE_HIT πŸ’€

🌸 NOTES 🌸

this widget is created from the scrolling list widget, and the entry field widget πŸ¦‹. it's lowkey a great example of how to build your own widgets using the base widgets provided in this distribution β€” main character energy fr fr πŸ‘‘

so, in order for you to delete files using the file selector, you must add the following call into your program. (the character X is the character you wish to use to tell the file selector you want to delete a file.) πŸ—‘οΈ

bindCDKObject (vSCROLL, fselect->filelist, X, deleteFile, fselect);

where fselect is a pointer to the object. this was originally turned on, but I thought it better to put the control of file deletion on an 'as-need' basis πŸ™ˆ


πŸ‘€ SEE ALSO πŸ‘€


and that's the whole page bestie, we ate and left no crumbs πŸ’–βœ¨ this one's from 2024-03-28 and it lives at cdk_fselect(3) β€” go forth and select files, icon πŸ’…πŸŒˆ