diff options
| author | Louis Burda <quent.burda@gmail.com> | 2024-03-13 19:33:30 +0100 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2024-03-13 19:33:42 +0100 |
| commit | bba6cce573d46b02dbb207b005721b370cab1698 (patch) | |
| tree | 8af38b347b29aee7bac14e61db29f89a3a1f98d8 /src/tui.c | |
| parent | 7146f1c08cf06c5865181f6e45b70505ca89d7a2 (diff) | |
| download | tmus-bba6cce573d46b02dbb207b005721b370cab1698.tar.gz tmus-bba6cce573d46b02dbb207b005721b370cab1698.zip | |
Add initial rudimentary grapheme support
Diffstat (limited to 'src/tui.c')
| -rw-r--r-- | src/tui.c | 39 |
1 files changed, 30 insertions, 9 deletions
@@ -1,4 +1,3 @@ -#include <stdbool.h> #define NCURSES_WIDECHAR 1 #define _GNU_SOURCE @@ -16,6 +15,7 @@ #include "strbuf.h" #include "util.h" +#include "grapheme.h" #include <ncurses.h> #include <unistd.h> @@ -56,6 +56,7 @@ static void seek_next_selected_tag(void); static void delete_current_tag(void); static bool tag_name_cmp(const void *p1, const void *p2, void *user); static void sort_visible_tags(void); +static void select_all_tags(void); static bool tag_pane_input(wint_t c); static void tag_pane_vis(struct pane *pane, int sel); @@ -435,6 +436,20 @@ sort_visible_tags(void) LIST_OFFSET(struct tag, link), NULL); } +void +select_all_tags(void) +{ + struct list_link *link; + struct tag *tag; + + list_clear(&tags_sel); + for (LIST_ITER(&tags, link)) { + tag = LIST_UPCAST(link, struct tag, link); + list_insert_back(&tags_sel, &tag->link_sel); + } + playlist_outdated = true; +} + bool tag_pane_input(wint_t c) { @@ -475,6 +490,9 @@ tag_pane_input(wint_t c) case KEY_CTRL(L's'): sort_visible_tags(); break; + case KEY_CTRL(L'a'): + select_all_tags(); + break; default: return false; } @@ -950,7 +968,7 @@ cmd_pane_input(wint_t c) case KEY_RIGHT: inputln_right(history->sel); break; - case KEY_CTRL('w'): + case KEY_CTRL(L'w'): inputln_del(history->sel, history->sel->cur); break; case KEY_UP: @@ -1012,7 +1030,7 @@ cmd_pane_input(wint_t c) break; default: /* TODO: wide char input support */ - if (!isprint(c)) return 0; + if (c <= 0) break; inputln_addch(history->sel, c); completion_reset = 1; break; @@ -1117,9 +1135,14 @@ cmd_pane_vis(struct pane *pane, int sel) if (sel) { /* show cursor in text */ ATTR_ON(pane->win, A_REVERSE); - wmove(pane->win, 2, offset + cmd->cur); - waddch(pane->win, cmd->cur < cmd->len - ? cmd->buf[cmd->cur] : L' '); + wmove(pane->win, 2, offset + cmd->curpos); + if (cmd->cur >= cmd->len) { + waddch(pane->win, ' '); + } else { + size_t n = grapheme_next_character_break_utf8( + cmd->buf + cmd->cur, cmd->len - cmd->cur); + waddnstr(pane->win, cmd->buf + cmd->cur, n); + } ATTR_OFF(pane->win, A_REVERSE); } } else if (user_status && user_status_uptime) { @@ -1204,11 +1227,9 @@ main_input(wint_t c) pane_sel = pane_after_cmd; break; case KEY_LEFT: - if (!player.loaded) break; player_seek(player.time_pos - 10); break; case KEY_RIGHT: - if (!player.loaded) break; player_seek(player.time_pos + 10); break; case L'o': @@ -1356,7 +1377,7 @@ tui_resize(void) leftw = 0; for (LIST_ITER(&tags, link)) { tag = LIST_UPCAST(link, struct tag, link); - leftw = MAX(leftw, strlen(tag->name)); + leftw = MAX(leftw, text_width(tag->name, strlen(tag->name))); } leftw = MAX(leftw + 1, 0.2f * scrw); |
