Changeset f95e606 for root_commands.c


Ignore:
Timestamp:
2016-10-17T04:37:45Z (8 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
b7fec48
Parents:
4466e3e
Message:

chat list: Fix alignment/truncation when utf8 characters are present

By using the str_pad_and_truncate() function I just added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • root_commands.c

    r4466e3e rf95e606  
    13271327}
    13281328
     1329/* some arbitrary numbers */
     1330#define CHAT_TITLE_LEN_MIN 20
     1331#define CHAT_TITLE_LEN_MAX 100
     1332
    13291333void cmd_chat_list_finish(struct im_connection *ic)
    13301334{
    13311335        account_t *acc = ic->acc;
    13321336        bee_chat_info_t *ci;
    1333         char *hformat, *iformat, *topic;
     1337        char *hformat, *iformat, *topic, *padded;
    13341338        GSList *l;
    13351339        guint i = 0;
     1340        long title_len, new_len;
    13361341        irc_t *irc = ic->bee->ui_data;
    13371342
     
    13391344                irc_rootmsg(irc, "No existing chatrooms");
    13401345                return;
     1346        }
     1347
     1348        /* find a reasonable width for the table */
     1349        title_len = CHAT_TITLE_LEN_MIN;
     1350
     1351        for (l = ic->chatlist; l; l = l->next) {
     1352                ci = l->data;
     1353                new_len = g_utf8_strlen(ci->title, -1);
     1354
     1355                if (new_len >= CHAT_TITLE_LEN_MAX) {
     1356                        title_len = CHAT_TITLE_LEN_MAX;
     1357                        break;
     1358                } else if (title_len < new_len) {
     1359                        title_len = new_len;
     1360                }
    13411361        }
    13421362
     
    13451365                iformat = "%u\t%s\t%s";
    13461366        } else {
    1347                 hformat = "%s  %-20s  %s";
    1348                 iformat = "%5u  %-20.20s  %s";
    1349         }
    1350 
    1351         irc_rootmsg(irc, hformat, "Index", "Title", "Topic");
     1367                hformat = "%s  %s  %s";
     1368                iformat = "%5u  %s  %s";
     1369        }
     1370
     1371        padded = str_pad_and_truncate("Title", title_len, NULL);
     1372        irc_rootmsg(irc, hformat, "Index", padded, "Topic");
     1373        g_free(padded);
    13521374
    13531375        for (l = ic->chatlist; l; l = l->next) {
    13541376                ci = l->data;
    13551377                topic = ci->topic ? ci->topic : "";
    1356                 irc_rootmsg(irc, iformat, ++i, ci->title, topic);
     1378
     1379                padded = str_pad_and_truncate(ci->title, title_len, "[...]");
     1380                irc_rootmsg(irc, iformat, ++i, padded, topic);
     1381                g_free(padded);
    13571382        }
    13581383
Note: See TracChangeset for help on using the changeset viewer.