Changes in uspace/lib/clui/tinput.c [3e6a98c5:9d58539] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/clui/tinput.c
r3e6a98c5 r9d58539 40 40 #include <errno.h> 41 41 #include <assert.h> 42 #include < stdbool.h>42 #include <bool.h> 43 43 #include <tinput.h> 44 44 … … 104 104 static void tinput_display_tail(tinput_t *ti, size_t start, size_t pad) 105 105 { 106 wchar_t *dbuf = malloc((INPUT_MAX_SIZE + 1) * sizeof(wchar_t)); 107 if (!dbuf) 108 return; 106 wchar_t dbuf[INPUT_MAX_SIZE + 1]; 109 107 110 108 size_t sa; … … 148 146 149 147 console_flush(ti->console); 150 151 free(dbuf);152 148 } 153 149 … … 599 595 { 600 596 unsigned int i; 601 /* Determine the maximum width of the completion in chars */602 size_t max_ width = 0;597 /* Determine the maximum length of the completion in chars */ 598 size_t max_length = 0; 603 599 for (i = 0; i < cnum; i++) 604 max_width = max(max_width, str_width(compl[i])); 605 606 unsigned int cols = max(1, (ti->con_cols + 1) / (max_width + 1)); 607 unsigned int padding = 0; 608 if ((cols * max_width) + (cols - 1) < ti->con_cols) { 609 padding = ti->con_cols - (cols * max_width) - (cols - 1); 610 } 611 unsigned int col_width = max_width + padding / cols; 600 max_length = max(max_length, str_length(compl[i])); 601 602 unsigned int cols = max(1, (ti->con_cols + 1) / (max_length + 1)); 603 unsigned int col_width = ti->con_cols / cols; 612 604 unsigned int rows = cnum / cols + ((cnum % cols) != 0); 613 605 … … 615 607 616 608 for (row = 0; row < rows; row++) { 617 unsigned int display_col = 0;609 bool wlc = false; 618 610 for (col = 0; col < cols; col++) { 619 611 size_t compl_idx = col * rows + row; 620 612 if (compl_idx >= cnum) 621 613 break; 622 if (col) {614 if (col) 623 615 printf(" "); 624 display_col++; 616 printf("%s", compl[compl_idx]); 617 size_t compl_len = str_length(compl[compl_idx]); 618 if (col == cols -1) { 619 wlc = (compl_len == max_length); 625 620 } 626 printf("%s", compl[compl_idx]); 627 size_t compl_width = str_width(compl[compl_idx]); 628 display_col += compl_width; 629 if (col < cols - 1) { 630 for (i = compl_width; i < col_width; i++) { 621 else { 622 for (i = compl_len; i < col_width; i++) { 631 623 printf(" "); 632 display_col++;633 624 } 634 625 } 635 626 } 636 if ((display_col % ti->con_cols) > 0) 637 printf("\n"); 638 } 639 fflush(stdout); 627 if (!wlc) printf("\n"); 628 } 640 629 } 641 630
Note:
See TracChangeset
for help on using the changeset viewer.