Changeset 96e01fbc in mainline for uspace/lib/clui/tinput.c


Ignore:
Timestamp:
2012-08-31T17:30:29Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2be2506a
Parents:
e0d5bc5 (diff), 0d57c3e (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.
Message:

Merge mainline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/clui/tinput.c

    re0d5bc5 r96e01fbc  
    595595{
    596596        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;
    599599        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;
     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        unsigned int padding = 0;
     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;
    604608        unsigned int rows = cnum / cols + ((cnum % cols) != 0);
    605609       
     
    607611       
    608612        for (row = 0; row < rows; row++) {
    609                 bool wlc = false;
     613                unsigned int display_col = 0;
    610614                for (col = 0; col < cols; col++) {
    611615                        size_t compl_idx = col * rows + row;
    612616                        if (compl_idx >= cnum)
    613617                                break;
    614                         if (col)
     618                        if (col) {
    615619                                printf(" ");
     620                                display_col++;
     621                        }
    616622                        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++) {
     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++) {
    623627                                        printf(" ");
     628                                        display_col++;
    624629                                }
    625630                        }
    626631                }
    627                 if (!wlc) printf("\n");
    628         }
     632                if ((display_col % ti->con_cols) > 0)
     633                        printf("\n");
     634        }
     635        fflush(stdout);
    629636}
    630637
Note: See TracChangeset for help on using the changeset viewer.