#include "../../cmc.h" #include "../ui.h" AL_ASSERT_TYPE_SIZE(wchar_t, 4); //void cmc_sp_init(struct cmc_ui *ui) //{ // al_array_init(ui->sp.tabs); // ui->sp.current = 0; //} // //void cmc_sp_layout(struct cmc_ui *ui, struct ncplane *parent) //{ // if (ui->sp.n) ncplane_destroy(ui->sp.n); // struct ncplane_options nopts = { 0 }; // nopts.rows = ncplane_dim_y(parent) - 1; // nopts.cols = ncplane_dim_x(parent) - 1; // ui->sp.n = ncplane_create(parent, &nopts); // struct cmc_search_tab tab = { // .search = NULL, // }; // nopts.x = 3; // nopts.y = 2; // nopts.rows = 10; // nopts.cols = ncplane_dim_x(ui->sp.n) - 3; // tab.input = ncplane_create(ui->sp.n, &nopts); // tab.cursor = 0; // tab.input_active = false; // tab.input_text = al_wstr_null(); // tab.input_changed = false; // al_array_push(ui->sp.tabs, tab); //} // //void cmc_sp_add_search(struct cmc_ui *ui, struct cmc_search *search) //{ // struct cmc_search_tab tab = { // .search = search, // }; // struct ncplane_options nopts = { 0 }; // nopts.x = 3; // nopts.y = 2; // nopts.rows = 10; // nopts.cols = ncplane_dim_x(ui->sp.n) - 3; // tab.input = ncplane_create(ui->sp.n, &nopts); // tab.cursor = 0; // tab.input_active = false; // tab.input_text = al_wstr_null(); // tab.input_changed = false; // al_array_push(ui->sp.tabs, tab); //} // //static bool handle_text_input(struct cmc_search_tab *tab, struct ncinput *input) //{ // bool entered = false; // // switch (input->id) { // case NCKEY_BACKSPACE: // if (tab->cursor > 0) { // al_wstr_remove_at(&tab->input_text, tab->cursor - 1); // tab->cursor--; // tab->input_changed = true; // } // break; // case NCKEY_LEFT: // if (tab->cursor > 0) { // tab->cursor--; // } // break; // case NCKEY_RIGHT: // if (tab->cursor < tab->input_text.length) { // tab->cursor++; // } // break; // case NCKEY_RETURN: // entered = true; // // fallthrough // case NCKEY_ESC: // tab->input_active = false; // tab->input_changed = true; // Erase text on next render. // break; // default: // if (ncinput_ctrl_p(input)) { // switch (input->id) { // case 'A': // tab->cursor = 0; // break; // case 'E': // tab->cursor = tab->input_text.length; // break; // case 'B': // if (tab->cursor > 0) { // tab->cursor--; // } // break; // case 'F': // if (tab->cursor < tab->input_text.length) { // tab->cursor++; // } // break; // case 'U': // for (u32 i = 1; i <= tab->cursor; i++) { // al_wstr_remove_at(&tab->input_text, tab->cursor - i); // } // tab->cursor = 0; // tab->input_changed = true; // break; // } // break; // } // // if (ncinput_alt_p(input) || nckey_synthesized_p(input->id)) { // break; // } // // al_wstr_insert(&tab->input_text, tab->cursor, &al_wstr_w((wchar_t *)input->eff_text, 0, 1)); // tab->cursor++; // tab->input_changed = true; // // /* // // https://github.com/dankamongmen/notcurses/blob/c11efe877f2245901f5c9ce110de7a2c83cfa2ed/src/lib/reader.c#L404 // for (s32 c = 0; input->eff_text[c] != 0; c++){ // uchar egc[5] = { 0 }; // if (notcurses_ucs32_to_utf8(&input->eff_text[c], 1, egc, 4) >= 0) { // // This probably doesn't work on Windows. // al_wstr_insert(&tab->input_text, tab->cursor, &al_wstr_w((wchar_t *)egc, 0, 1)); // } // } // */ // // break; // } // // tab->visual_cursor = 0; // if (tab->cursor > 0) { // for (u32 i = 0; i < tab->cursor; i++) { // tab->visual_cursor += al_wchar_width(al_wstr_at(&tab->input_text, i)); // } // } // // return entered; //} // //bool cmc_sp_handle_input(struct cmc_ui *ui, struct ncinput *input) //{ // struct cmc_search_tab *tab = NULL; // if (ui->sp.tabs.count > 0) { // tab = &al_array_at(ui->sp.tabs, ui->sp.current); // } // // if (tab) { // if (tab->input_active) { // if (cmc_ui_consider_input(input, true)) { // if (handle_text_input(tab, input)) { // str query; // al_str_from_wstr(&query, &tab->input_text); // camu_client_create_search(&ui->c->client, &al_str_c("youtube"), &query); // al_str_free(&query); // } // if (!tab->input_active) notcurses_cursor_disable(ui->nc); // } // } else { // switch (input->id) { // case 'i': // CONSIDER_INPUT(); // tab->input_active = true; // tab->input_changed = true; // s32 absx = ncplane_abs_x(tab->input); // s32 absy = ncplane_abs_y(tab->input); // notcurses_cursor_enable(ui->nc, absy, absx + tab->visual_cursor); // break; // } // } // } // // return true; //} // //void cmc_sp_erase(struct cmc_ui *ui) //{ // ncplane_erase(ui->sp.n); //} // //void cmc_sp_render(struct cmc_ui *ui) //{ // struct cmc_search_tab *tab = NULL; // if (ui->sp.tabs.count > 0) { // tab = &al_array_at(ui->sp.tabs, ui->sp.current); // } // // if (tab) { // if (tab->input_changed) { // ncplane_erase(tab->input); // if (tab->input_active) { // cmc_ui_putnwstr_yx(tab->input, 0, 0, tab->input_text.length, &tab->input_text); // } // tab->input_changed = false; // } // if (tab->input_active) { // s32 absx = ncplane_abs_x(tab->input); // s32 absy = ncplane_abs_y(tab->input); // notcurses_cursor_enable(ui->nc, absy, absx + tab->visual_cursor); // } // } // // /* // if (ui->overlay_shown) { // ncplane_erase(ui->oln); // u32 max_height = ncplane_dim_y(ui->oln) - 2; // u32 count = ui->c->searches.count; // u32 index = ui->sp.overlay_index - (ui->sp.overlay_index % max_height); // u32 end = MIN(index + max_height, count); // for (u32 i = index; i < end; i++) { // struct cmc_search *search = al_array_at(ui->c->searches, i); // if (i == ui->sp.overlay_index) { // ncplane_set_fg_palindex(ui->oln, 6); // ncplane_putchar_yx(ui->oln, i - index + 1, 2, '>'); // cmc_ui_putstr_maxwidth_yx(ui->oln, i - index + 1, 4, search->query.length, &search->query); // } else { // ncplane_set_fg_default(ui->oln); // cmc_ui_putstr_maxwidth_yx(ui->oln, i - index + 1, 2, search->query.length, &search->query); // } // } // } // */ //}