Skip to content
Myr

render: add support for rendering a prompt prefix

Before adoption: this commit came in with the history the project adopted, so no landing records it.

I.e. instead of rendering an empty input field, we can now render a prompt string, like "> ", or "$ ".

authored by Daniel Eklöf · committed by Daniel Eklöf · parent 54f43d1 · Browse files · 3 files+24 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+24 added−2 removed

  • other:+24 added−2 removed

3 files+24 added−2 removed

modified:main.c+2 added
1303 unmodified lines
1304 struct context c = {1305 .status = KEEP_RUNNING,1306 .wl = {0},1307 .prompt = {1308 .prompt = strdup("> "),1309 .text = calloc(1, 1),1310 .cursor = 01311 },1312 .repeat = {
196 unmodified lines
15091510 render_destroy(c.render);1511 shm_fini();15121513 free(c.prompt.prompt);1514 free(c.prompt.text);1515 for (size_t i = 0; i < c.applications.count; i++) {1516 struct application *app = &c.applications.v[i];1517
58 unmodified lines
modified:render.c+21 added-2 removed
72 unmodified lines
7374 cairo_font_extents_t fextents;75 cairo_font_extents(buf->cairo, &fextents);7677 const char *const text = prompt->text;77 /* Text to render is the prompt followed by the entered text */78 char text[strlen(prompt->prompt) + strlen(prompt->text) + 1];79 strcpy(text, prompt->prompt);80 strcat(text, prompt->text);8182 cairo_glyph_t *glyphs = NULL;83 cairo_text_cluster_t *clusters = NULL;84 cairo_text_cluster_flags_t cluster_flags;
29 unmodified lines
114 * *character| position */115 size_t cursor = 0;116 size_t cursor_at_glyph = 0;117118 const size_t prompt_len = strlen(prompt->prompt);119 const size_t text_len = strlen(prompt->text);120121 /* Count glyphs that make up the prompt */122 for (size_t i = 0; i < prompt_len;) {123 int clen = mblen(&prompt->prompt[i], MB_CUR_MAX);124 if (clen < 0) {125 LOG_ERRNO("prompt: %s", prompt->prompt);126 break;127 }128129 i += clen;130 cursor_at_glyph++;131 }132133 /* Count glyphs *before* the cursor */115 while (cursor < prompt->cursor) {134 while (cursor < prompt->cursor && cursor < text_len) {135 int clen = mblen(&prompt->text[cursor], MB_CUR_MAX);136 if (clen < 0) {137 LOG_ERRNO("prompt: %s", prompt->text);138 break;
255 unmodified lines
modified:render.h+1 added
22 unmodified lines
23 struct rgba selection_color;24};2526struct prompt {27 char *prompt;28 char *text;29 size_t cursor;30};31
13 unmodified lines