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