CUI

Components / AI interfaces

Composer and model picker

The message box of a chat, with attachments, send and stop, and a menu for choosing the model.

Functions: cui_chat_composer, cui_model_picker

Composer and model picker

Usage

static char draft[4096];
static int model;
int ev = cui_chat_composer(ui, "composer", draft, sizeof draft, .placeholder = "Ask anything", .busy = generating,
                           .attachments = files, .attachment_count = n, .removed = &removed,
                           .models = models, .model_count = 3, .model = &model);
if (ev & CUI_COMPOSER_SEND) send(draft);
if (ev & CUI_COMPOSER_STOP) stop();
if (ev & CUI_COMPOSER_REMOVE) remove_file(removed);

The text area grows with its content up to max_lines, then scrolls. Enter sends and Shift+Enter starts a new line. Send stays disabled while the draft is empty, and while busy it becomes a stop button. The model picker can also be used alone: cui_model_picker(ui, "model", models, n, &model).

Keyboard

  • Enter sends and Shift+Enter starts a new line.

Options of cui_chat_composer

OptionTypeDefaultDescription
.placeholderconst char *Muted text shown while the field is empty.
.busyboola reply is being generated: the send button becomes stop and Enter does not send
.attachmentsconst char *const *names of the attached files, shown as chips above the text, each with an x
.attachment_countintnumber of attachments
.removedint *set to the index of the attachment whose x was clicked (with CUI_COMPOSER_REMOVE)
.modelsconst cui_model *models for a picker beside the attach button; NULL for no picker
.model_countintnumber of models
.modelint *index of the chosen model, read and written
.max_linesint8default 8
.widthcui_sizeWidth: CUI_FILL, CUI_FIT, CUI_PX(n) or CUI_PCT(n); unset uses the component's own.

Options of cui_model_picker

OptionTypeDefaultDescription
.ghostboolno border or fill on the button until hovered, for use inside another control
.placementcui_placementOne of CUI_PLACE_BOTTOM_START, CUI_PLACE_BOTTOM, CUI_PLACE_BOTTOM_END, CUI_PLACE_TOP_START, CUI_PLACE_TOP, CUI_PLACE_TOP_END, CUI_PLACE_RIGHT_START, CUI_PLACE_LEFT_START, CUI_PLACE_RIGHT or CUI_PLACE_LEFT.

cui_model

FieldTypeDescription
nameconst char *shown on the button and as the row's heading in the list
detailconst char *smaller muted line under the name in the list, e.g. what the model is good at
badgeconst char *small accent badge after the name, e.g. "New"; NULL for none
iconconst char *An icon: a CUI_ICON_* constant, or a string from another icon font.

Related