home · contact · privacy
7DRL: Extend EMPATHY display with actors' current actions.
[plomrogue] / src / client / draw_wins.c
1 /* src/client/draw_wins.c
2  *
3  * This file is part of PlomRogue. PlomRogue is licensed under the GPL version 3
4  * or any later version. For details on its copyright, license, and warranties,
5  * see the file NOTICE in the root directory of the PlomRogue source package.
6  */
7
8 #define _POSIX_C_SOURCE 200809L /* strdup() */
9 #include "draw_wins.h"
10 #include <ncurses.h> /* attr_t, chtype, init_pair(), A_REVERSE, COLOR_PAIR() */
11 #include <stddef.h> /* NULL */
12 #include <stdint.h> /* uint8_t, uint16_t, uint32_t, UINT16_MAX, UINT32_MAX */
13 #include <stdio.h> /* sprintf() */
14 #include <stdlib.h> /* free() */
15 #include <string.h> /* memset(), strcmp(), strchr(), strdup/(), strlen() */
16 #include "../common/rexit.h" /* exit_err(), exit_trouble() */
17 #include "../common/try_malloc.h" /* try_malloc() */
18 #include "keybindings.h" /* struct KeyBindingDB, get_keyname_to_keycode() */
19 #include "windows.h" /* yx_uint16, Win */
20 #include "world.h" /* global world */
21
22
23
24 /* Apply to the winmap of Win "w" the new sizes "new_size_y" and "new_size_x"
25  * to the degree that they extend it. Re-shape the window content accordingly.
26  */
27 static void try_resize_winmap(struct Win * w, int new_size_y, int new_size_x);
28
29 /* In Win "w", write "ch" to coordinate "y"/"x". */
30 static void set_ch_on_yx(struct Win * w, int y, int x, chtype ch);
31
32 /* Add "line" into window "w" with "attri" set on all chars. add_line() selects
33  * one of the other three functions based on the "win"->linebreak mode.
34  *
35  * "wide" writes lines to full width without in-between breaks. "long" breaks
36  * lines on the right window border. "compact" replaces newlines with printable
37  * separator characters. "offset" and "last" are only relevant to the "compact"
38  * mode. "offset" reports the horizontal offset at which the line is drawn from
39  * the lowest existing winmap line on; it is updated to the next offset after
40  * the new line, to be used by the next add_line_compact() call. "last" marks
41  * the line to add as the last in the window, so no further separator is added.
42  */
43 static void add_line(struct Win * win, char * line, attr_t attri,
44                      uint16_t * offset, uint8_t last);
45 static void add_line_wide(struct Win * win, char * line, attr_t attri);
46 static void add_line_long(struct Win * win, char * line, attr_t attri);
47 static void add_line_compact(struct Win * win, char * line, attr_t attri,
48                              uint16_t * offset, uint8_t last);
49
50 /* Add linebreaks-containing "text" to "win", formatted as per "win"->linebreak.
51  *
52  * draw_text_from_bottom() prepends empty lines to "text" to push its last line
53  * to the low frame edge when the frame is of greater height than the winmap
54  * would be otherwise; else, set "win"->center.y to the winmap's lowest line.
55  */
56 static void add_text_with_linebreaks(struct Win * win, char * text);
57 static void draw_text_from_bottom(struct Win * win, char * text);
58
59 /* Draw from line "start" on config view for keybindings defined at "kb". */
60 static void draw_keybinding_config(struct Win * win, struct KeyBindingDB * kbdb,
61                                    uint16_t offset);
62
63 /* String building helper functions to draw_winconf_geometry(). */
64 static char * get_keyname_to_command(char * command_name);
65 static char * winconf_geom_helper(struct Win * win, char axis, char * sep,
66                                   char * newlines, char * value_prefix);
67
68
69
70 /* try_resize_winmap() only realloc's Win->winmap if this is set. Use this to
71  * skip inflationary malloc's by successive try_resize_winmap() calls when the
72  * memory needed can be pre-calculated.
73  */
74 static uint8_t do_realloc_winmap = 1;
75
76
77
78 static void try_resize_winmap(struct Win * win, int new_size_y, int new_size_x)
79 {
80     if (win->winmap_size.y >= new_size_y && win->winmap_size.x >= new_size_x)
81     {
82         return;
83     }
84     if      (win->winmap_size.y > new_size_y)
85     {
86         new_size_y = win->winmap_size.y;
87     }
88     else if (win->winmap_size.x > new_size_x)
89     {
90         new_size_x = win->winmap_size.x;
91     }
92     if (do_realloc_winmap)
93     {
94         chtype * old_winmap = win->winmap;
95         uint32_t new_size = sizeof(chtype) * new_size_y * new_size_x;
96         win->winmap = try_malloc(new_size, __func__);
97         uint16_t y, x;
98         for (y = 0; y < new_size_y; y++)
99         {
100             for (x = 0; y < win->winmap_size.y && x < win->winmap_size.x; x++)
101             {
102                 chtype ch = old_winmap[(y * win->winmap_size.x) + x];
103                 win->winmap[(y * new_size_x) + x] = ch;
104             }
105             for (; x < new_size_x; x++)
106             {
107                 win->winmap[(y * new_size_x) + x] = ' ';
108             }
109         }
110         free(old_winmap);
111     }
112     win->winmap_size.y = new_size_y;
113     win->winmap_size.x = new_size_x;
114 }
115
116
117
118 static void set_ch_on_yx(struct Win * win, int y, int x, chtype ch)
119 {
120     win->winmap[(y * win->winmap_size.x) + x] = ch;
121 }
122
123
124
125 static void add_line(struct Win * win, char * line, attr_t attri,
126                      uint16_t * offset, uint8_t last)
127 {
128     exit_err(strlen(line) > UINT16_MAX, "Line in add_line() too big.");
129     if      (0 == win->linebreak)
130     {
131         add_line_long(win, line, attri);
132     }
133     else if (1 == win->linebreak)
134     {
135         add_line_wide(win, line, attri);
136     }
137     else if (2 == win->linebreak)
138     {
139         add_line_compact(win, line, attri, offset, last);
140     }
141 }
142
143
144
145 static void add_line_wide(struct Win * win, char * line, attr_t attri)
146 {
147     uint16_t y_start = win->winmap_size.y;
148     uint16_t len_line = strlen(line);
149     try_resize_winmap(win, y_start + 1, win->frame_size.x);
150     try_resize_winmap(win, y_start + 1, len_line);
151     uint16_t x;
152     for (x = 0; x < len_line; x++)
153     {
154         set_ch_on_yx(win, y_start, x, line[x] | attri);
155     }
156     if (attri)
157     {
158         for (; x < win->frame_size.x; x++)
159         {
160             set_ch_on_yx(win, y_start, x, ' ' | attri);
161         }
162     }
163 }
164
165
166
167 static void add_line_long(struct Win * win, char * line, attr_t attri)
168 {
169     uint16_t y_start = win->winmap_size.y;
170     uint16_t len_line = strlen(line);
171     try_resize_winmap(win, y_start + 1, win->frame_size.x);
172     uint16_t x, y, z;
173     for (z = 0, y = y_start; z < len_line; y++)
174     {
175         for (x = 0; x < win->winmap_size.x && z < len_line; x++, z++)
176         {
177             set_ch_on_yx(win, y, x, line[z] | attri);
178         }
179         if (z < len_line)
180         {
181             try_resize_winmap(win, y + 1 + 1, win->winmap_size.x);
182         }
183     }
184 }
185
186
187
188 static void add_line_compact(struct Win * win, char * line, attr_t attri,
189                              uint16_t * offset, uint8_t last)
190 {
191     uint16_t y_start = win->winmap_size.y - (win->winmap_size.y > 0);
192     try_resize_winmap(win, y_start + 1, win->frame_size.x);
193     uint16_t len_line = strlen(line);
194     char * separator = last ? "" : " / ";
195     uint32_t len_line_new = len_line + strlen(separator);
196     char * line_new = try_malloc(len_line_new + 1, __func__);
197     int test = sprintf(line_new, "%s%s", line, separator);
198     exit_trouble(test < 0, __func__, "sprintf");
199     uint16_t x = 0;
200     uint16_t y;
201     uint32_t z;
202     for (z = 0, y = y_start; z < len_line_new; y++)
203     {
204         for (x = * offset; x < win->winmap_size.x && z < len_line_new; x++, z++)
205         {
206             set_ch_on_yx(win, y, x, line_new[z] | attri);
207             if (z + 1 == (uint32_t) len_line)
208             {
209                attri = 0;
210             }
211         }
212         * offset = 0;
213         if (z < len_line_new)
214         {
215             try_resize_winmap(win, y + 1 + 1, win->winmap_size.x);
216         }
217     }
218     free(line_new);
219     *offset = x;
220 }
221
222
223
224 static void add_text_with_linebreaks(struct Win * win, char * text)
225 {
226     char * limit;
227     uint16_t offset = 0;
228     char * text_copy = strdup(text);
229     char * start = text_copy;
230     while (NULL != (limit = strchr(start, '\n')))
231     {
232         (* limit) = '\0';
233         add_line(win, start, 0, &offset, 0);
234         start = limit + 1;
235     }
236     add_line(win, start, 0, &offset, 1);
237     free(text_copy);
238 }
239
240
241
242 static void draw_text_from_bottom(struct Win * win, char * text)
243 {
244     add_text_with_linebreaks(win, text);
245     if (win->winmap_size.y > win->frame_size.y)
246     {
247         win->center.y = win->winmap_size.y - 1;
248     }
249     else if (win->winmap_size.y < win->frame_size.y)
250     {
251         uint16_t new_y_start = win->frame_size.y - win->winmap_size.y;
252         memset(&win->winmap_size, 0, sizeof(struct yx_uint16));
253         free(win->winmap);
254         win->winmap = NULL;
255         do
256         {
257             add_line_wide(win, " ", 0);
258         }
259         while (new_y_start > win->winmap_size.y);
260         if (2 == win->linebreak) /* add_text_with_linebreaks() will start not */
261         {                        /* after, but within the last line then.     */
262             add_line_wide(win, " ", 0);
263         }
264         add_text_with_linebreaks(win, text);
265     }
266 }
267
268
269
270 static void draw_keybinding_config(struct Win * win, struct KeyBindingDB * kbdb,
271                                    uint16_t offset)
272 {
273     if (0 == kbdb->n_of_kbs)
274     {
275         add_line(win, "(none)", 0, &offset, 0);
276         return;
277     }
278     uint8_t kb_n;
279     for (kb_n = 0; kb_n < kbdb->n_of_kbs; kb_n++)
280     {
281         attr_t attri = 0;
282         if (kb_n == kbdb->select)
283         {
284             attri = A_REVERSE;
285             if (1 == kbdb->edit)
286             {
287                 attri = attri | A_BLINK;
288             }
289             win->center.y = win->winmap_size.y;
290         }
291         struct KeyBinding kb = kbdb->kbs[kb_n];
292         char * keyname = get_keyname_to_keycode(kb.keycode);
293         uint16_t size = strlen(keyname) + 3 + strlen(kb.command->dsc_long) + 1;
294         char * kb_line = try_malloc(size, __func__);
295         int test = sprintf(kb_line, "%s - %s", keyname, kb.command->dsc_long);
296         exit_trouble(test < 0, __func__, "sprintf");
297         free(keyname);
298         add_line(win, kb_line, attri, &offset, (kbdb->n_of_kbs == kb_n + 1));
299         free(kb_line);
300     }
301 }
302
303
304
305 static char * get_keyname_to_command(char * command_name)
306 {
307     uint8_t i = 0;
308     for (i = 0; i < world.kb_wingeom.n_of_kbs; i++)
309     {
310         if (!strcmp(world.kb_wingeom.kbs[i].command->dsc_short, command_name))
311         {
312             return get_keyname_to_keycode(world.kb_wingeom.kbs[i].keycode);
313         }
314     }
315     return "UNDEFINED";
316 }
317
318
319
320 static char * winconf_geom_helper(struct Win * win, char axis, char * sep,
321                                   char * newlines, char * value_prefix)
322 {
323     char * p0 = 'v'==axis? "Height" : "Width";
324     char * p1 = " to save (grow/shrink/toggle positivity with ";
325     char * p2 = get_keyname_to_command('v'==axis? "grow_v" : "grow_h");
326     char * p4 = get_keyname_to_command('v'==axis? "shri_v" : "shri_v");
327     char * p6 = get_keyname_to_command('v'==axis? "to_height_t" : "to_width_t");
328     char p8[6 + 1];                            /* 6: int16_t value max strlen */
329     int test = sprintf(p8,"%d", 'v'==axis?win->target_height:win->target_width);
330     exit_trouble(test < 0, __func__, "sprintf");
331     char * p9 = " (";
332     char * p10 = "in_cells";
333     if (1 == ('v'==axis? win->target_height_type : win->target_width_type))
334     {
335         p10 = "non-positive diff: cells to screen maximum";
336     }
337     char * p11 = ")";
338     uint8_t size =   strlen(p0) + strlen(p1) + strlen(p2) + strlen(sep)
339                    + strlen(p4) + strlen(sep) + strlen(p6) +strlen(value_prefix)
340                    + strlen(p8) + strlen(p9) + strlen(p10) + strlen(p11)
341                    + strlen(newlines) + 1;
342     char * msg = try_malloc(size, __func__);
343     sprintf(msg, "%s%s%s%s%s%s%s%s%s%s%s%s%s", p0, p1, p2, sep, p4, sep, p6,
344             value_prefix, p8, p9, p10, p11, newlines);
345     return msg;
346 }
347
348
349
350 extern void draw_win_log(struct Win * win)
351 {
352     if (!world.log)
353     {
354         return;
355     }
356     uint32_t x, i, n_postbreak_lines;
357     for (i = 0, x = 0, n_postbreak_lines = 1; i < strlen(world.log); i++)
358     {
359         exit_err(i == UINT32_MAX, "Log too large.");
360         x++;
361         if (x > win->frame_size.x || '\n' == world.log[i])
362         {
363             n_postbreak_lines++;
364             x = 1;
365         }
366     }
367     if (n_postbreak_lines > win->frame_size.y)
368     {
369         uint32_t size = n_postbreak_lines * (win->frame_size.x + 1);
370         win->winmap = try_malloc(sizeof(chtype) * size, __func__);
371         for (i = 0; i < size; win->winmap[i] = ' ', i++);
372         /* TODO: This should only be done with "long" line break style. */
373         do_realloc_winmap = 0;
374         draw_text_from_bottom(win, world.log);
375         do_realloc_winmap = 1;
376         return;
377     }
378     draw_text_from_bottom(win, world.log);
379 }
380
381
382
383 extern void draw_win_map(struct Win * win)
384 {
385     uint16_t x, y;
386     init_pair(1, COLOR_WHITE, COLOR_WHITE); //
387     init_pair(2, COLOR_BLUE, COLOR_WHITE); //
388     init_pair(3, COLOR_RED, COLOR_WHITE); //
389     init_pair(4, COLOR_WHITE, COLOR_BLUE); //
390     init_pair(5, COLOR_BLUE, COLOR_RED); //
391     init_pair(6, COLOR_BLACK, COLOR_RED); //
392     init_pair(7, COLOR_BLUE, COLOR_GREEN); //
393     init_pair(8, COLOR_BLUE, COLOR_YELLOW); //
394     init_pair(9, COLOR_BLACK, COLOR_MAGENTA); //
395     init_pair(18, COLOR_WHITE, COLOR_CYAN); //
396     init_pair(10, COLOR_BLACK, COLOR_CYAN); //
397     init_pair(11, COLOR_WHITE, COLOR_BLACK); //
398     init_pair(12, COLOR_BLUE, COLOR_BLACK); //
399     init_pair(13, COLOR_RED, COLOR_BLACK); //
400     init_pair(14, COLOR_GREEN, COLOR_BLACK); //
401     init_pair(15, COLOR_YELLOW, COLOR_BLACK); //
402     init_pair(16, COLOR_CYAN, COLOR_BLACK); //
403     init_pair(17, COLOR_MAGENTA, COLOR_BLACK); //
404     // attr_t attr_mem = COLOR_PAIR(12);
405     // attr_t attr_sha = COLOR_PAIR(1);
406     attr_t col_unknown = COLOR_PAIR(1); //
407     attr_t col_mem = COLOR_PAIR(4); //
408     attr_t col_mem_obstacle = COLOR_PAIR(2); //
409     attr_t col_mem_altar = COLOR_PAIR(18); //
410     try_resize_winmap(win, world.map.length, world.map.length * 2 + 1);
411     for (y = 0; y < world.map.length; y++)
412     {
413         for (x = 0; x < world.map.length; x++)
414         {
415             char c_m = world.mem_map[y * world.map.length + x]; //
416             attr_t a = col_mem; //
417             if (c_m == ' ') //
418             { //
419                 a = col_unknown; //
420             } //
421             else if (c_m == 'X' || c_m == '|') //
422             { //
423                 a = col_mem_obstacle; //
424             } //
425             else if (c_m == '_')
426             { //
427                 a = col_mem_altar; //
428             } //
429             // attr_t a=' '==world.mem_map[y*world.map.length+x]?attr_sha:attr_mem;
430             char c = world.mem_map[y*world.map.length + x];
431             set_ch_on_yx(win, y, x * 2 + (y % 2),     c   | a);
432             chtype depth = ' ' | a;  //
433             if (world.meta_map_0[y * world.map.length + x] == '2')  //
434             {  //
435                 depth = '+' | col_mem; //
436             }  //
437             set_ch_on_yx(win, y, x * 2 + (y % 2) + 1, depth);
438         }
439     }
440     attr_t col_plant = COLOR_PAIR(11); //
441     attr_t col_altar = COLOR_PAIR(10); //
442     attr_t col_tool = COLOR_PAIR(16); //
443     attr_t col_dirt = COLOR_PAIR(17); //
444     attr_t col_unkraut = COLOR_PAIR(14); //
445     attr_t col_animal = COLOR_PAIR(6); //
446     attr_t col_player = COLOR_PAIR(3); //
447     attr_t col_ground = COLOR_PAIR(15); //
448     attr_t col_obstacle = COLOR_PAIR(9); //
449     attr_t col_health_good = COLOR_PAIR(7); //
450     attr_t col_health_middle = COLOR_PAIR(8); //
451     attr_t col_health_bad = COLOR_PAIR(5); //
452     attr_t col_lumber = COLOR_PAIR(13); //
453     attr_t col_water = COLOR_PAIR(12); //
454     attr_t col_stack = COLOR_PAIR(11); //
455     for (y = 0; y < world.map.length; y++)
456     {
457         for (x = 0; x < world.map.length; x++)
458         {
459             char c = world.map.cells[y*world.map.length + x]; //
460             if (' ' != c) //
461             // if (' ' != world.map.cells[y*world.map.length + x])
462             {
463                 attr_t a = col_water; //
464                 if ('.' == c || ':' == c) //
465                 { //
466                     a = col_ground; //
467                 } //
468                 else if ('@' == c) //
469                 { //
470                     a = col_player; //
471                 } //
472                 else if ('a' == c || 'd' == c || 'b' == c) //
473                 { //
474                     a = col_animal; //
475                 } //
476                 else if ('#' == c) //
477                 { //
478                     a = col_unkraut; //
479                 } //
480                 else if ('$' == c) //
481                 { //
482                     a = col_dirt; //
483                 } //
484                 else if ('m' == c || '/' == c || '-' == c) //
485                 { //
486                     a = col_tool; //
487                 } //
488                 else if ('X' == c || '|' == c) //
489                 { //
490                     a = col_obstacle; //
491                 } //
492                 else if ('_' == c) //
493                 { //
494                     a = col_altar; //
495                 } //
496                 else if ('%' == c || '*' == c) //
497                 { //
498                     a = col_plant; //
499                 } //
500                 else if ('=' == c) //
501                 { //
502                     a = col_lumber; //
503                 } //
504                 // char c = world.map.cells[y*world.map.length + x];
505                 set_ch_on_yx(win, y, x * 2 + (y % 2),     c | a); //
506                 chtype meta = ' ' | a;  //
507                 char metamap0val = world.meta_map_0[y*world.map.length+x]; //
508                 if (metamap0val == '2')  //
509                 {  //
510                     meta = '+' | col_stack;  //
511                 }  //
512                 else if (metamap0val != '0' && metamap0val != '1') //
513                 { //
514                     char c = world.meta_map_1[y*world.map.length+x];
515                     if (metamap0val == 'a') //
516                     { //
517                         meta = c | col_health_bad; //
518                     } //
519                     else if (metamap0val == 'b') //
520                     { //
521                         meta = c | col_health_middle; //
522                     } //
523                     else if (metamap0val == 'c') //
524                     { //
525                         meta = c | col_health_good; //
526                     } //
527                 } //
528                 set_ch_on_yx(win, y, x * 2 + (y % 2) + 1, meta); //
529                 // set_ch_on_yx(win, y, x * 2 + (y % 2),     c);
530                 // set_ch_on_yx(win, y, x * 2 + (y % 2) + 1, ' ');
531             }
532         }
533     }
534     if (world.look)
535     {
536         y = world.look_pos.y;
537         x = world.look_pos.x;
538         char c = world.map.cells[y * world.map.length + x];
539         c = ' ' == c ? world.mem_map[y * world.map.length + x] : c;
540         set_ch_on_yx(win, y, x * 2 + (y % 2),     c   | A_REVERSE);
541         set_ch_on_yx(win, y, x * 2 + (y % 2) + 1, '?' | A_REVERSE);
542     }
543 }
544
545
546
547 extern void draw_win_info(struct Win * win)
548 {
549     char * dsc_turn      = "Turn: ";
550     char * dsc_hitpoints = "\nHitpoints: ";
551     char * dsc_satiation = "\nSatiation: ";
552     char * dsc_godsmood  = "\nGod's mood: "; // 7DRL
553     char * dsc_godsfavor = "\nGod's favor: "; // 7DRL
554     uint16_t maxl =   strlen(dsc_turn) + 5 + strlen(dsc_hitpoints) + 3 //
555                     + strlen(dsc_satiation) + 6 + strlen(dsc_godsmood) + 6 //
556                     + strlen(dsc_godsfavor) + 6; //
557     char * text = try_malloc(maxl + 1, __func__);
558     int test = sprintf(text, "%s%d%s%d%s%d%s%d%s%d", dsc_turn, world.turn,
559                        dsc_hitpoints, world.player_lifepoints, dsc_satiation,
560                        world.player_satiation, dsc_godsmood, world.godsmood, //
561                        dsc_godsfavor, world.godsfavor); //
562     exit_trouble(test < 0, __func__, "sprintf");
563     add_text_with_linebreaks(win, text);
564     free(text);
565 }
566
567
568
569 extern void draw_win_inventory(struct Win * win)
570 {
571     char * limit;
572     char * text_copy = strdup(world.player_inventory);
573     char * start = text_copy;
574     uint8_t i = 0;
575     uint8_t found_selection = 0;
576     uint16_t offset = 0;
577     while (NULL != (limit = strchr(start, '\n')))
578     {
579         (* limit) = '\0';
580         attr_t attri = 0;
581         if (i == world.player_inventory_select)
582         {
583             found_selection = 1;
584             attri = A_REVERSE;
585             win->center.y = win->winmap_size.y;
586         }
587         add_line(win, start, attri, &offset, 0);
588         start = limit + 1;
589         i++;
590     }
591     win->center.y = !found_selection ? win->winmap_size.y : win->center.y;
592     add_line(win, start, !found_selection * A_REVERSE, &offset, 1);
593     free(text_copy);
594 }
595
596
597
598 extern void draw_win_terrain_stack(struct Win * win)
599 {
600     char * wait_response = "(polling)";
601     char * text = world.things_here ? world.things_here : wait_response;
602     add_text_with_linebreaks(win, text);
603     win->center.y = world.things_here_scroll + (win->frame_size.y / 2);  //
604 }
605
606
607
608 extern void draw_win_keybindings_global(struct Win * win)
609 {
610     win->center.y = world.kb_global.select;
611     draw_keybinding_config(win, &world.kb_global, 0);
612 }
613
614
615
616 extern void draw_win_keybindings_winconf_geometry(struct Win * win)
617 {
618     win->center.y = world.kb_wingeom.select;
619     draw_keybinding_config(win, &world.kb_wingeom, 0);
620 }
621
622
623
624 extern void draw_win_keybindings_winconf_keybindings(struct Win * win)
625 {
626     win->center.y = world.kb_winkeys.select;
627     draw_keybinding_config(win, &world.kb_winkeys, 0);
628 }
629
630
631
632 extern void draw_winconf_keybindings(struct Win * win)
633 {
634     char * title = "Window's keys:";
635     uint16_t offset = 0;
636     add_line(win, title, 0, &offset, 0);
637     add_line(win, " ", 0, &offset, 0);
638     draw_keybinding_config(win, &win->kb, offset);
639 }
640
641
642
643 extern void draw_winconf_geometry(struct Win * win)
644 {
645     char * sep = "/";
646     char * newlines = "\n\n";
647     char * value_prefix = "): ";
648     char * title = "Window's geometry:\n\nShift up/down with ";
649     char * key_shift_b = get_keyname_to_command("shift_b");
650     char * key_shift_f = get_keyname_to_command("shift_f");
651     char * height = winconf_geom_helper(win, 'v', sep, newlines, value_prefix);
652     char * width = winconf_geom_helper(win, 'h', sep, newlines, value_prefix);
653     char * breaks_title = "Linebreak type (toggle with ";
654     char * key_to_break = get_keyname_to_command("to_break");
655     char * breaks_type = "long";
656     if (win->linebreak)
657     {
658         breaks_type = (1 == win->linebreak) ? "wide" : "compact";
659     }
660     uint16_t text_size =   strlen(title) + strlen(key_shift_b) + strlen(sep)
661                          + strlen(key_shift_f) + strlen(newlines)
662                          + strlen(height) + strlen(width)
663                          + strlen(breaks_title) + strlen(key_to_break)
664                          + strlen(value_prefix) + strlen(breaks_type);
665     char * text = try_malloc(text_size + 1, __func__);
666     int test = sprintf(text, "%s%s%s%s%s%s%s%s%s%s%s", title, key_shift_b, sep,
667                        key_shift_f, newlines, height, width, breaks_title,
668                        key_to_break, value_prefix, breaks_type);
669     free(height);
670     free(width);
671     exit_trouble(test < 0, __func__, "sprintf");
672     add_text_with_linebreaks(win, text);
673     free(text);
674 }