Changeset dc5aa568 in mainline for uspace/lib
- Timestamp:
- 2012-08-16T15:18:44Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ebbc8a74
- Parents:
- 80d8885 (diff), 13c4fe0 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- uspace/lib
- Files:
-
- 3 edited
-
c/generic/str.c (modified) (1 diff)
-
c/include/str.h (modified) (1 diff)
-
clui/tinput.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/str.c
r80d8885 rdc5aa568 397 397 398 398 return len; 399 } 400 401 /** Get character display width on a character cell display. 402 * 403 * @param ch Character 404 * @return Width of character in cells. 405 */ 406 size_t chr_width(wchar_t ch) 407 { 408 return 1; 409 } 410 411 /** Get string display width on a character cell display. 412 * 413 * @param str String 414 * @return Width of string in cells. 415 */ 416 size_t str_width(const char *str) 417 { 418 size_t width = 0; 419 size_t offset = 0; 420 wchar_t ch; 421 422 while ((ch = str_decode(str, &offset, STR_NO_LIMIT)) != 0) 423 width += chr_width(ch); 424 425 return width; 399 426 } 400 427 -
uspace/lib/c/include/str.h
r80d8885 rdc5aa568 73 73 extern size_t wstr_nlength(const wchar_t *str, size_t size); 74 74 75 extern size_t chr_width(wchar_t ch); 76 extern size_t str_width(const char *str); 77 75 78 extern bool ascii_check(wchar_t ch); 76 79 extern bool chr_check(wchar_t ch); -
uspace/lib/clui/tinput.c
r80d8885 rdc5aa568 595 595 { 596 596 unsigned int i; 597 /* Determine the maximum length of the completion in chars */598 size_t max_ length = 0;597 /* Determine the maximum width of the completion in chars */ 598 size_t max_width = 0; 599 599 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));600 max_width = max(max_width, str_width(compl[i])); 601 602 unsigned int cols = max(1, (ti->con_cols + 1) / (max_width + 1)); 603 603 unsigned int padding = 0; 604 if ((cols * max_ length) + (cols - 1) < ti->con_cols) {605 padding = ti->con_cols - (cols * max_ length) - (cols - 1);606 } 607 unsigned int col_width = max_ length + padding / cols;604 if ((cols * max_width) + (cols - 1) < ti->con_cols) { 605 padding = ti->con_cols - (cols * max_width) - (cols - 1); 606 } 607 unsigned int col_width = max_width + padding / cols; 608 608 unsigned int rows = cnum / cols + ((cnum % cols) != 0); 609 609 … … 611 611 612 612 for (row = 0; row < rows; row++) { 613 bool wlc = false;613 unsigned int display_col = 0; 614 614 for (col = 0; col < cols; col++) { 615 615 size_t compl_idx = col * rows + row; 616 616 if (compl_idx >= cnum) 617 617 break; 618 if (col) 618 if (col) { 619 619 printf(" "); 620 display_col++; 621 } 620 622 printf("%s", compl[compl_idx]); 621 size_t compl_len = str_length(compl[compl_idx]); 622 if (col == cols -1) { 623 wlc = (compl_len == max_length); 624 } 625 else { 626 for (i = compl_len; i < col_width; i++) { 623 size_t compl_width = str_width(compl[compl_idx]); 624 display_col += compl_width; 625 if (col < cols - 1) { 626 for (i = compl_width; i < col_width; i++) { 627 627 printf(" "); 628 display_col++; 628 629 } 629 630 } 630 631 } 631 if (!wlc) printf("\n"); 632 } 632 if ((display_col % ti->con_cols) > 0) printf("\n"); 633 } 634 fflush(stdout); 633 635 } 634 636
Note:
See TracChangeset
for help on using the changeset viewer.
