cdk_display(3)

πŸ’… cdk_display(3) β€” Library calls πŸ’…

okay bestie, pull up a chair because cdk_display(3) is the page where Cdk spills all its formatting secrets. it's giving "everything you can do to a string before it hits the screen". let's go πŸ¦‹


πŸŽ€ NAME πŸŽ€

cdk_display β€” Cdk display capabilities


✨ SYNOPSIS ✨

so Cdk ships with a whole bunch of pre-defined display types, and this manual page outlines the following ones:

  • How To Use Colors
  • How To Use Different Character Attributes
  • How To Justify Strings
  • How To Use Special Drawing Characters
  • Edit/Display Type Codes (EDisplayType)

🌈 DESCRIPTION 🌈

Cdk has special formatting commands that you can drop straight into any string, and they add highlights, justification, or even colors to a plain old boring string. and here's the tea: these attributes, once you set them, stay in effect until you explicitly change them again β€” or until the string just... ends. 😭

this page outlines how all of that works and demonstrates it too. periodt.


πŸ“ How To Use Colors πŸ“

Cdk can display colors in almost every string type displayed in a Cdk widget. iconic behavior honestly.

normally, color pairs get accessed via the COLOR_PAIR macro. you can absolutely still do that, but ngl, creating a string with multiple colors that way is tedious. that is literally why the color commands were created. use initCDKColor to create up to 64 color pairs which you can refer to by number right inside your strings. slay.

the color settings are stored directly in the string. when the widget is created or activated, the string gets converted so it can take advantage of any color commands inside it. πŸ’…

  • to turn on a color pair, insert </XX> into the string; where XX is a numeric value from 0 to the maximum color pair.
    • color pair 0 is the standard default color pair for the screen.
    • if you used initCDKColor, the maximum value for XX is 63 for terminals supporting 8 ANSI colors.
    • if you created color pairs directly using init_pair, the maximum value for XX is implementation-dependent, e.g., 63 (for Unix systems) and 255 for ncurses.
    • if the terminal does not support color, Cdk uses the bold attribute.
  • to turn off a color pair, use the format command <!XX> where XX is a numeric value from 0 to the maximum color pair.

the following example demonstrates the use of the color commands. 🫢

#include <cdk/cdk.h>

void main()
{
   CDKSCREEN *cdkscreen;
   CDKLABEL  *demo;
   char      *mesg[4];

   cdkscreen = initCDKScreen (NULL);

   /* Start CDK Colors */
   initCDKColor();

   /* Set the labels up.         */
   mesg[0] = "</31>This line should have a yellow foreground and a cyan background.<!31>";
   mesg[1] = "</05>This line should have a white  foreground and a blue background.<!05>";
   mesg[2] = "</26>This line should have a yellow foreground and a red  background.<!26>";
   mesg[3] = "<C>This line should be set to whatever the screen default is.";

   /* Declare the labels.   */
   demo = newCDKLabel (cdkscreen, CENTER, CENTER, mesg, 4, TRUE, TRUE);

   /* Draw the label        */
   drawCDKLabel (demo, TRUE);
   waitCDKLabel (demo, ' ');

   /* Clean up              */
   destroyCDKLabel (demo);
   destroyCDKScreen (cdkscreen);
   endCDK();
   exit (0);
}

πŸ”₯ How To Use Different Character Attributes πŸ”₯

Cdk also hands you attribute commands so you can show off different character attributes inside a Cdk widget. to use a character attribute, the format command is </X> where X is one of several command characters. to turn an attribute off, use the command <!X>. the following table outlines the command characters:

  • B β€” Bold
  • U β€” Underline
  • K β€” Blink
  • R β€” Reverse
  • S β€” Standout
  • D β€” Dim
  • N β€” Normal

the following example demonstrates the use of character display attributes. ✨

#include <cdk/cdk.h>

void main()
{
   CDKSCREEN    *cdkscreen;
   CDKLABEL     *demo;
   char         *mesg[4];

   cdkscreen = initCDKScreen (NULL);

   /* Start CDK Colors */
   initCDKColor();

   /* Set the labels up.  */
   mesg[0] = "</B/31>Bold text            yellow foreground / blue background.<!31>";
   mesg[1] = "</U/05>Underlined text      white  foreground / blue background.<!05>";
   mesg[2] = "</K/26>Blinking text        yellow foreground / red  background.<!26>";
   mesg[3] = "<C>This line uses the screen default colors.";

   /* Declare the labels.  */
   demo = newCDKLabel (cdkscreen, CENTER, CENTER, mesg, 4, TRUE, TRUE);

   /* Draw the label */
   drawCDKLabel (demo, TRUE);
   waitCDKLabel (demo, ' ');

   /* Clean up */
   destroyCDKLabel (demo);
   destroyCDKScreen (cdkscreen);
   endCDK();
   exit (0);
}
heads up bestie: color commands and format commands can be mixed inside the same format marker. the above example underlines the label marker, which also sets color pair number 2. πŸ‘‘

πŸ¦‹ How To Justify Strings πŸ¦‹

justification commands can left justify, right justify, or center a string of text. to use a justification format in a string, the command <X> is used. the following table lists the format commands:

  • <L> β€” Left Justified. Default if not stated.
  • <C> β€” Centered text.
  • <R> β€” Right justified.
  • <I=X> β€” Indent the line X characters.
  • <B=X> β€” Bullet. X is the bullet string to use.
  • <F=X> β€” Links in a file where X is the filename. This works only with the viewer widget.

the following example demonstrates how to use the justification commands in a Cdk widget. 🌸

#include <cdk/cdk.h>

void main()
{
   CDKSCREEN    *cdkscreen;
   CDKLABEL     *demo;
   char         *mesg[5];

   cdkscreen = initCDKScreen (NULL);

   /* Start CDK Colors */
   initCDKColor();

   /* Set the labels up.  */
   mesg[0] = "<R></B/31>This line should have a yellow foreground and a blue background.<!31>";
   mesg[1] = "</U/05>This line should have a white  foreground and a blue background.<!05>";
   mesg[2] = "<B=+>This is a bullet.";
   mesg[3] = "<I=10>This is indented 10 characters.";
   mesg[4] = "<C>This line should be set to whatever the screen default is.";

   /* Declare the labels.  */
   demo = newCDKLabel (cdkscreen, CENTER, CENTER, mesg, 5, TRUE, TRUE);

   /* Draw the label */
   drawCDKLabel (demo, TRUE);
   waitCDKLabel (demo, ' ');

   /* Clean up */
   destroyCDKLabel (demo);
   destroyCDKScreen (cdkscreen);
   endCDK();
   exit (0);
}

the bullet format command can take either a single character or a string. the bullet in the above example would look like

+ This is a bullet.

but if we were to use the following command instead

<B=***>This is a bullet.

it would look like

*** This is a bullet.
⚠️ and this part matters: a format command must be at the beginning of the string.

🧚 How To Use Special Drawing Characters 🧚

Cdk has a set of special drawing characters which can be inserted into any ASCII file. these characters are encoded using the format command <#XX> where XX is a two-character name. the char2Chtype and chtype2String functions provide conversion to/from curses chtype data (see cdk_util(3)). πŸ’œ


Okay so boom πŸ’₯ β€” here's the roster of special character commands your CDK display can whip out. Every single one, no gatekeeping:

  • <#UL> β€” Upper Left Corner
  • <#UR> β€” Upper Right Corner
  • <#LL> β€” Lower Left Corner
  • <#LR> β€” Lower Right Corner
  • <#LT> β€” Left Tee
  • <#RT> β€” Right Tee
  • <#TT> β€” Top Tee
  • <#BT> β€” Bottom Tee
  • <#HL> β€” Horizontal Line
  • <#VL> β€” Vertical Line
  • <#PL> β€” Plus Sign
  • <#PM> β€” Plus or Minus Sign
  • <#DG> β€” Degree Sign
  • <#CB> β€” Checker Board
  • <#DI> β€” Diamond
  • <#BU> β€” Bullet
  • <#S1> β€” Scan line 1
  • <#S9> β€” Scan line 9
  • <#LA> β€” Left Arrow
  • <#RA> β€” Right Arrow
  • <#UA> β€” Up Arrow
  • <#DA> β€” Down Arrow

Now bestie, here's the glow-up: you can repeat any of these character formats using an optional numeric repeat value ✨ All you do is slap the repeat count inside parentheses at the end of the character format. Periodt.

Wanna draw ten horizontal-line characters? Say less:

<#HL(10)>

And here's the moment where it gets iconic β€” drawing an actual box inside a label window:

#include <cdk/cdk.h>

void main()
{
   /* Declare variables.  */
   CDKSCREEN    *cdkscreen;
   CDKLABEL     *demo;
   char         *mesg[4];

   cdkscreen = initCDKScreen (NULL);

   /* Start CDK Colors */
   initCDKColor();

   /* Set the labels up.  */
   mesg[0] = "<C><#UL><#HL(26)><#UR>";
   mesg[1] = "<C><#VL></R>This text should be boxed.<!R><#VL>";
   mesg[2] = "<C><#LL><#HL(26)><#LR>";
   mesg[3] = "<C>While this is not.";

   /* Declare the labels.  */
   demo = newCDKLabel (cdkscreen, CENTER, CENTER, mesg, 4, TRUE, TRUE);

   /* Is the label NULL???  */
   if (demo == (CDKLABEL *)NULL)
   {
      /* Clean up the memory.  */
      destroyCDKScreen (cdkscreen);

      /* End curses...  */
      endCDK();

      /* Spit out a message.  */
      printf ("Oops. Can't seem to create the label. Is the window too small?\n");
      exit (1);
   }

   /* Draw the CDK screen.  */
   refreshCDKScreen (cdkscreen);
   waitCDKLabel (demo, ' ');

   /* Clean up */
   destroyCDKLabel (demo);
   destroyCDKScreen (cdkscreen);
   endCDK();
   exit (0);
}

Also worth clocking πŸ‘€ β€” drawn text can be justified too. Yes ma'am, we aligning things around here.

πŸ‘‘ Edit/Display Type Codes (EDisplayType)

Every display type in the game, fr fr:

  • vCHAR β€” Only accepts alphabetic characters.
  • vLCHAR β€” Only accepts alphabetic characters. Maps the character to lower case when a character has been accepted.
  • vUCHAR β€” Only accepts alphabetic characters. Maps the character to upper case when a character has been accepted.
  • vHCHAR β€” Only accepts alphabetic characters. Displays a period (.) when a character has been accepted.
  • vUHCHAR β€” Only accepts alphabetic characters. Displays a period (.) and maps the character to upper case when a character has been accepted.
  • vLHCHAR β€” Only accepts alphabetic characters. Displays a period (.) and maps the character to lower case when a character has been accepted.
  • vINT β€” Only accepts numeric characters.
  • vHINT β€” Only accepts numeric characters. Displays a period (.) when a character has been accepted.
  • vMIXED β€” Accepts any character types.
  • vLMIXED β€” Accepts any character types. Maps the character to lower case when an alphabetic character has been accepted.
  • vUMIXED β€” Accepts any character types. Maps the character to upper case when an alphabetic character has been accepted.
  • vHMIXED β€” Accepts any character types. Displays a period (.) when a character has been accepted.
  • vLHMIXED β€” Accepts any character types. Displays a period (.) and maps the character to lower case when a character has been accepted.
  • vUHMIXED β€” Accepts any character types. Displays a period (.) and maps the character to upper case when a character has been accepted.
  • vVIEWONLY β€” Uneditable field. Look but do not touch energy πŸ’…

🌈 SEE ALSO


That's the whole thing bestie, you ate it up 🫢 Go read your siblings: cdk(3), cdk_binding(3), cdk_screen(3), and cdk_util(3). This page is cdk_display(3), last touched on 2026-01-19 β€” so yeah, it's giving fresh πŸ’–βœ¨ πŸŽ€

πŸ“¦ where this page comes from