text edit window [initial]

This commit is contained in:
2026-07-13 18:23:52 +03:00
parent 0744a2cbaa
commit 63d56de4c8
5 changed files with 176 additions and 2 deletions
+1 -1
View File
@@ -1,11 +1,11 @@
# TODO: # TODO:
## Current: ## Current:
- [ ] Rewrite cancel download. Use packages and check every time for a confirmation to continue download
- [ ] File upload multiline description (window) - [ ] File upload multiline description (window)
- [ ] Sorting in the file list - [ ] Sorting in the file list
- [ ] Resume download - [ ] Resume download
- [ ] Separate common structures in the common.h - [ ] Separate common structures in the common.h
- [x] Rewrite cancel download. Use packages and check every time for a confirmation to continue download
- [x] Show download/upload progress in percentages - [x] Show download/upload progress in percentages
- [x] Break line automatically in modal widgets - [x] Break line automatically in modal widgets
- [x] Cancel upload/download - [x] Cancel upload/download
+1 -1
View File
@@ -31,7 +31,7 @@ bool connect_to_server(app_t *app) {
return false; return false;
} }
app->query_args->state = S_WAIT_SERVER; app->query_args->state = S_WAIT_SERVER;
app->params->is_connected = TRUE; app->params->is_connected = true;
app->query_args->sd = app->params->sd; app->query_args->sd = app->params->sd;
app_draw_bars(app); app_draw_bars(app);
return true; return true;
+4
View File
@@ -4,6 +4,7 @@
#include "main_window.h" #include "main_window.h"
#include "file_list.h" #include "file_list.h"
#include "fs_file_list.h" #include "fs_file_list.h"
#include "text_edit.h"
void main_window_set(app_t *app, enum main_window_type type) { void main_window_set(app_t *app, enum main_window_type type) {
if (app->main_ui.ui != NULL) { if (app->main_ui.ui != NULL) {
@@ -19,6 +20,7 @@ void main_window_set(app_t *app, enum main_window_type type) {
w_lfl_init_win(app); w_lfl_init_win(app);
break; break;
case mw_f_desc: case mw_f_desc:
w_te_init_win(app);
break; break;
default: default:
break; break;
@@ -34,6 +36,7 @@ void main_window_draw(app_t *app) {
w_lfl_draw((w_lfl_ui_t *)app->main_ui.ui); w_lfl_draw((w_lfl_ui_t *)app->main_ui.ui);
break; break;
case mw_f_desc: case mw_f_desc:
w_te_draw((w_te_ui_t *) app->main_ui.ui);
break; break;
} }
app_draw_bbar(app); app_draw_bbar(app);
@@ -48,6 +51,7 @@ void main_window_destroy(app_t *app) {
w_lfl_destroy((w_lfl_ui_t **)&(app->main_ui.ui)); w_lfl_destroy((w_lfl_ui_t **)&(app->main_ui.ui));
break; break;
case mw_f_desc: case mw_f_desc:
w_te_destroy((w_te_ui_t **) &(app->main_ui.ui));
break; break;
} }
MAIN_UI_RESET(app); MAIN_UI_RESET(app);
+140
View File
@@ -0,0 +1,140 @@
/* SPDX-License-Identifier: MIT */
/* Copyright (c) 2026 Oleksandr Zhylin */
#include <dirent.h>
#include <fcntl.h>
#include <ncursesw/ncurses.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <utils.h>
#include "text_edit.h"
#include "widget_core.h"
static void w_te_cb(w_cb_args_t *args) {
app_t *app = args->app;
int32_t key = *((int32_t *)args->data);
w_te_ui_t *fui = app->query_args->main_ui->ui;
switch (key) {
case '\n':
// TODO: new line case
break;
case '\b':
// TODO: new line case
break;
default:
fui->text[fui->text_len++] = key;
fui->text[fui->text_len] = 0;
}
}
static void w_te_cb_refresh(void *data) {
app_t *app = (app_t *)data;
if (app->main_ui.type != mw_f_desc) {
return;
}
w_te_ui_t *fui = app->main_ui.ui;
wnoutrefresh(fui->win);
}
static struct action_key action_keys[] = {
{.key = "Esc", .title = "Back", .code = '\33'},
{.key = "F9", .title = "Quit", .code = KEY_F(9)},
};
static int32_t process_user_input(app_t *app, w_cb_args_t *d_args) {
int32_t c;
w_te_ui_t *fui = (w_te_ui_t *)app->query_args->main_ui->ui;
c = wgetch(app->win);
switch (c) {
case KEY_F(9):
app_destroy(app, 0);
return OK;
case 'D':
case 'd':
// case '\33': /* ESC key */
// if (!app->modal.is_initiated) {
// server_send_string(app->query_args, "file list %d %d\n",
// fui->max_lines - 1, 1);
// main_window_set(app, mw_fl_server);
// d_args->element = app->main_ui.ui;
// break;
// }
default:
d_args->data = (void *)&c;
app->active_callback(d_args);
break;
}
return OK;
}
void w_te_reset_app(void *app);
w_te_ui_t *w_te_init_win(app_t *app) {
w_te_ui_t *fui = malloc(sizeof(w_te_ui_t));
app->main_ui.ui = fui;
app->main_ui.type = mw_f_desc;
app->main_ui.cb_ui_refresh = w_te_cb_refresh;
app->main_ui.b_keys = action_keys;
app->main_ui.b_keys_len = 2;
app->main_ui.cb_b_press = (w_cb_press_t)process_user_input;
app->main_ui.reset = w_te_reset_app;
app->main_ui.draw = (draw_f_t *)w_te_draw;
app->active_callback = w_te_cb;
fui->w.callback = w_te_cb;
w_init(&(fui->w), NULL, &(app->win), "");
fui->w.sz.x = getmaxx(app->win);
fui->w.sz.y = getmaxy(app->win);
fui->w.parent_win = &(app->win);
/* * INIT UI * */
/* define the width for each sub window */
int32_t left_w_x = app->coordinates.max_x / 10 * 5;
int32_t right_w_x = app->coordinates.max_x - left_w_x - 2;
return fui;
}
void w_te_reset(w_te_ui_t *fl_ui) {
fl_ui->text[0] = 0;
fl_ui->scroll_pos = 0;
fl_ui->text_len = 0;
}
void w_te_reset_app(void *app) {
app_t *_app = app;
w_te_ui_t *fl_ui = (w_te_ui_t *)_app->main_ui.ui;
w_te_reset(fl_ui);
}
void w_te_draw(w_te_ui_t *fui) {
int32_t sz_y, sz_x;
int32_t p_y, p_x;
WINDOW *win = fui->win;
getmaxyx(win, sz_y, sz_x);
int32_t sz_y_f = sz_y - 1; // actual size (without box)
int32_t sz_x_f = sz_x - 1; // actual size (without box)
p_y = 1;
p_x = 1;
for (int i = 0; i < fui->w.sz.y; i++) {
mvwaddnwstr(win, p_y, p_x, fui->text + fui->w.sz.x * i, fui->w.sz.x);
}
box(fui->win, 0, 0);
p_x = 1;
wattroff(win, A_BOLD);
curs_set(false);
}
void w_te_destroy(w_te_ui_t **fui) {
w_te_ui_t *f = *fui;
free(*fui);
*fui = NULL;
}
+30
View File
@@ -0,0 +1,30 @@
/* SPDX-License-Identifier: MIT */
/* Copyright (c) 2026 Oleksandr Zhylin */
#ifndef W_TEXT_EDIT_H /* LOCAL FILE LIST */
#define W_TEXT_EDIT_H
#include "../app.h"
#include <stddef.h>
#include <wchar.h>
#include <widget_core.h>
#include <ncursesw/ncurses.h>
#include <stdint.h>
#include <sys/types.h>
typedef struct {
w_t w;
WINDOW *win;
wchar_t text[INBUFSIZE * 10];
int text_len;
int scroll_pos;
void *file_pt; // TODO: уточнить
} w_te_ui_t;
void w_te_draw(w_te_ui_t *fl_ui);
void w_te_destroy(w_te_ui_t **fui);
void w_te_reset(w_te_ui_t *fl_ui);
w_te_ui_t *w_te_init(WINDOW **win, w_t *w_parent);
w_te_ui_t *w_te_init_win(app_t *app);
#endif