diff options
Diffstat (limited to 'src/fruits/cmsrv')
| -rw-r--r-- | src/fruits/cmsrv/cmsrv.c | 26 | ||||
| -rw-r--r-- | src/fruits/cmsrv/ui.c | 27 |
2 files changed, 30 insertions, 23 deletions
diff --git a/src/fruits/cmsrv/cmsrv.c b/src/fruits/cmsrv/cmsrv.c index 6f00a05..4cd1691 100644 --- a/src/fruits/cmsrv/cmsrv.c +++ b/src/fruits/cmsrv/cmsrv.c @@ -39,19 +39,19 @@ static u8 server_line_callback(void *userdata, str *line) { struct cmsrv *s = (struct cmsrv *)userdata; struct lia_list *list = al_array_at(s->server.lists, 0); - if (al_str_eq(line, al_str_c(";PAUSE"))) { + if (al_str_eq(line, &al_str_c(";PAUSE"))) { lia_list_toggle_pause(list, LIANA_SEQUENCE_ANY, -1.0); - } else if (al_str_eq(line, al_str_c(";NEXT"))) { + } else if (al_str_eq(line, &al_str_c(";NEXT"))) { lia_list_skip(list, LIANA_SEQUENCE_ANY, 1); - } else if (al_str_eq(line, al_str_c(";PREV"))) { + } else if (al_str_eq(line, &al_str_c(";PREV"))) { lia_list_skip(list, LIANA_SEQUENCE_ANY, -1); - } else if (al_str_eq(line, al_str_c(";SHUFFLE"))) { + } else if (al_str_eq(line, &al_str_c(";SHUFFLE"))) { lia_list_shuffle(list); - } else if (al_str_eq(line, al_str_c(";SORT"))) { + } else if (al_str_eq(line, &al_str_c(";SORT"))) { lia_list_sort(list); - } else if (al_str_eq(line, al_str_c(";REVERSE"))) { + } else if (al_str_eq(line, &al_str_c(";REVERSE"))) { lia_list_reverse(list); - } else if (al_str_eq(line, al_str_c(";CLEAR"))) { + } else if (al_str_eq(line, &al_str_c(";CLEAR"))) { lia_list_clear(list); } else { struct nn_packet *packet = nn_packet_create(); @@ -63,7 +63,7 @@ static u8 server_line_callback(void *userdata, str *line) nn_packet_write_u8(packet, CAMU_RESOURCE_HTTP); #endif #if CACHE_HAVE_CDIO - } else if (al_str_cmp(line, al_str_c("cdda://"), 0, 7) == 0) { + } else if (al_str_cmp(line, &al_str_c("cdda://"), 0, 7) == 0) { nn_packet_write_u8(packet, CAMU_RESOURCE_CDIO); #endif } else { @@ -115,8 +115,8 @@ static s32 log_callback(void *userdata, u8 level, char *message) { struct cmsrv *s = (struct cmsrv *)userdata; (void)level; - cmsrv_ui_push_message(&s->ui, message); - return al_strlen(message); + cmsrv_ui_push_message(&s->ui, al_strndup(message, AL_LOG_MESSAGE_SIZE)); + return al_strnlen(message, AL_LOG_MESSAGE_SIZE); } #endif @@ -172,7 +172,7 @@ s32 wmain(s32 argc, wchar_t **argv) camu_server_init(&s.server, &s.loop); s.server.meta_callback = server_meta_callback; s.server.userdata = &s; - if (!camu_server_listen(&s.server, CAMU_TEST_TYPE, CAMU_TEST_ADDR, CAMU_PORT)) { + if (!camu_server_listen(&s.server, CAMU_TEST_TYPE, &CAMU_TEST_ADDR, CAMU_PORT)) { return EXIT_FAILURE; } @@ -181,9 +181,9 @@ s32 wmain(s32 argc, wchar_t **argv) nn_socket_init(&s.local.sock, NNWT_SOCKET_NONBLOCKING); s.local.cli.callback = server_line_callback; s.local.cli.userdata = &s; - nn_line_processor_init(&s.local.cli, al_str_c("\n")); + nn_line_processor_init(&s.local.cli, &al_str_c("\n")); nn_line_processor_open_socket(&s.local.cli, &s.local.sock); - if (nn_socket_bind(&s.local.sock, CAMU_TEST_CONTROL_PATH, 0) && nn_socket_listen(&s.local.sock)) { + if (nn_socket_bind(&s.local.sock, &CAMU_TEST_CONTROL_PATH, 0) && nn_socket_listen(&s.local.sock)) { nn_line_processor_run(&s.local.cli, &s.loop); } #endif diff --git a/src/fruits/cmsrv/ui.c b/src/fruits/cmsrv/ui.c index ba1f8b3..e64f580 100644 --- a/src/fruits/cmsrv/ui.c +++ b/src/fruits/cmsrv/ui.c @@ -82,15 +82,22 @@ static void render_log(struct cmsrv_ui *ui) u32 max_width = ncplane_dim_x(n) - 2; u32 max_height = ncplane_dim_y(n) - 2; - u64 c = 0; - ncchannels_set_fg_default(&c); - ncplane_rounded_box(n, NCSTYLE_NONE, c, max_height + 1, max_width + 1, 0); - - u32 size = ui->log.messages.size; + u32 size = ui->log.messages.count; u32 index = size > max_height ? size - max_height : 0; for (u32 i = index; i < size; i++) { - ncplane_putnstr_yx(n, (i - index) + 1, 1, max_width, al_array_at(ui->log.messages, i)); + // We can't use putnstr here to control the width because lots of + // these messages will have wide characters. + ncplane_putstr_yx(n, (i - index) + 1, 1, al_array_at(ui->log.messages, i)); + } + for (u32 i = 0; i < index; i++) { + al_free(al_array_at(ui->log.messages, i)); } + al_array_remove_range(ui->log.messages, 0, index); + + u64 c = 0; + ncchannels_set_fg_default(&c); + ncplane_cursor_move_yx(n, 0, 0); + ncplane_rounded_box(n, NCSTYLE_NONE, c, max_height + 1, max_width + 1, 0); } static void layout_lists(struct cmsrv_ui *ui, struct ncplane *parent) @@ -117,7 +124,7 @@ static void erase_lists(struct cmsrv_ui *ui) static void putnwstr_maxwidth_yx(struct ncplane *n, u32 y, u32 x, u32 maxwidth, wstr *w) { ncplane_cursor_move_yx(n, y, x); - u32 end = MIN(w->len, maxwidth); + u32 end = MIN(w->length, maxwidth); for (u32 i = 0; i < end; i++) { ncplane_putwc(n, al_wstr_at(w, i)); } @@ -135,11 +142,11 @@ static void render_lists(struct cmsrv_ui *ui) struct lia_list *list; al_array_foreach(ui->server->lists, i, list) { if (current_line++ >= max_height) break; - for (u32 j = 0; j < MIN(max_width, list->name.len); j++) { + for (u32 j = 0; j < MIN(max_width, list->name.length); j++) { ncplane_putchar_yx(n, i, j, al_str_at(&list->name, j)); } s32 index = MAX(list->current - (entries_per_list / 2), 0); - s32 size = (s32)list->entries.size; + s32 size = (s32)list->entries.count; s32 end = MIN(index + entries_per_list, size); for (s32 j = index; j < end; j++) { struct lia_list_entry *entry = al_array_at(list->entries, j); @@ -197,7 +204,7 @@ static void render_nodes(struct cmsrv_ui *ui) ncplane_putnstr_yx(n, i, 0, max_width, strbuf); struct lia_node_connection *conn; al_array_foreach(node->connections, j, conn) { - al_snprintf(strbuf, sizeof(strbuf), "%u", conn->pool.ready.size); + al_snprintf(strbuf, sizeof(strbuf), "%u", conn->pool.ready.count); ncplane_putnstr_yx(n, i + j + 1, 2, max_width, strbuf); } } |