Description edit on save #1

Merged
zheiling merged 14 commits from text_edit_window into main 2026-07-27 19:45:06 +03:00
7 changed files with 78 additions and 50 deletions
Showing only changes of commit 84ab8a3777 - Show all commits
+7 -10
View File
@@ -11,10 +11,12 @@
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <wchar.h>
void ac_file(WINDOW *win, int is_action_w);
app_t *app_init(app_t *app) {
app->top_text = NULL;
/* get values from terminal size */
int32_t y_max, x_max;
getmaxyx(stdscr, y_max, x_max);
@@ -34,13 +36,6 @@ app_t *app_init(app_t *app) {
app->modal.win = NULL;
app->modal.is_initiated = 0;
/* print top and bottom bars */
app->main_ui.b_keys_len = 0;
app_draw_bars(app);
/* here goes box borders */
app_draw_borders(app);
/* NULL to main_ui */
MAIN_UI_RESET(app);
@@ -108,15 +103,17 @@ void app_draw_bars(app_t *app) {
mvwprintw(app->win, app->coordinates.cur_y - 2, i, " ");
}
/* add content to the top bar */
if (app->params && app->params->is_connected) {
if (app->top_text != NULL) {
mvwaddnwstr(app->win, 1, 2, app->top_text, wcslen(app->top_text));
} else if (app->params && app->params->is_connected) {
int32_t ip_address = app->params->addr;
u_char ip_addr[4];
mempcpy(ip_addr, &ip_address, 4);
sprintf(top_text, "Connected to %u.%u.%u.%u, user: %s", ip_addr[0],
ip_addr[1], ip_addr[2], ip_addr[3], app->params->uname);
}
mvwprintw(app->win, 1, 2, "%s", top_text);
}
wattroff(app->win, A_REVERSE);
/* add content to the bottom bar */
+1
View File
@@ -24,6 +24,7 @@ typedef struct {
file_args_t *file_args;
void (*active_callback)(w_cb_args_t *args);
void *active_widget;
wchar_t *top_text;
main_window_t main_ui;
} app_t;
-1
View File
@@ -44,7 +44,6 @@ int main(int argc, char **argv) {
app.query_args = &q_args;
main_window_set(&app, mw_fl_server);
/* init client to connect to the server */
app.params->sd = init_client();
+8 -9
View File
@@ -23,7 +23,6 @@
int32_t m_id = 0;
void mini_loop(app_t *app) {
w_cb_args_t d_args = {
.app = app, .element = NULL, .data = NULL, .resp_data.code = cbrc_none};
@@ -52,7 +51,6 @@ void mini_loop(app_t *app) {
}
}
}
}
int main(void) {
@@ -62,22 +60,23 @@ int main(void) {
params_t params;
p_file_t file;
init_query_args(&q_args, app.params);
app.params = &params;
app.query_args = &q_args;
app.file_args = &fargs;
app_init_nc();
init_params(&params);
w_alert_init(&app);
app_init(&app);
q_args.file = &file;
app.query_args->main_ui = &(app.main_ui);
file.name = "Test file #1";
params.is_connected = false;
app.modal.is_initiated = false;
app_init_nc();
app_init(&app);
init_params(&params);
init_query_args(&q_args, app.params);
w_alert_init(&app);
app_init(&app);
main_window_set(&app, mw_f_desc);
mini_loop(&app);
exit(0);
+1
View File
@@ -25,6 +25,7 @@ void main_window_set(app_t *app, enum main_window_type type) {
default:
break;
}
app_draw_bars(app);
}
void main_window_draw(app_t *app) {
+32 -6
View File
@@ -7,7 +7,9 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <utils.h>
@@ -16,6 +18,8 @@
#include "text_edit.h"
#include "widget_core.h"
/* TODO: create dynamic array of endline positions */
static void w_te_cb(w_cb_args_t *args) {
app_t *app = args->app;
int32_t key = *((int32_t *)args->data);
@@ -25,6 +29,15 @@ static void w_te_cb(w_cb_args_t *args) {
case KEY_DL:
fui->text[fui->text_len--] = 0;
break;
case KEY_UP:
fui->cur_shift_pos.y--;
wchar_t *nl_ptr = NULL;
wchar_t *line_start = fui->text;
break;
case KEY_DOWN:
fui->cur_shift_pos.y++;
break;
default:
fui->text[fui->text_len++] = key;
fui->text[fui->text_len] = 0;
@@ -74,6 +87,8 @@ static int32_t process_user_input(app_t *app, w_cb_args_t *d_args) {
void w_te_reset_app(void *app);
w_te_ui_t *w_te_init_win(app_t *app) {
wchar_t top_text[INBUFSIZE];
int top_text_len = 0;
w_te_ui_t *fui = malloc(sizeof(w_te_ui_t));
app->main_ui.ui = fui;
app->main_ui.type = mw_f_desc;
@@ -86,19 +101,24 @@ w_te_ui_t *w_te_init_win(app_t *app) {
app->active_callback = w_te_cb;
fui->w.callback = w_te_cb;
w_init(&(fui->w), NULL, &(app->win), "");
fui->file_ptr = app->query_args->file;
fui->w.sz.x = getmaxx(app->win);
fui->w.sz.y = getmaxy(app->win);
fui->w.parent_win = &(app->win);
/* * INIT UI * */
fui->win = newwin(fui->w.sz.y - 4, fui->w.sz.x - 2, 2, 1);
top_text_len =
swprintf(top_text, INBUFSIZE, L"Description: %s", fui->file_ptr->name);
app->top_text = malloc(sizeof(wchar_t) * (top_text_len + 1));
wcsncpy(app->top_text, top_text, top_text_len);
app->top_text[top_text_len] = 0;
return fui;
}
void w_te_reset(w_te_ui_t *fl_ui) {
fl_ui->text[0] = 0;
fl_ui->cur_pos.x = 0;
fl_ui->cur_pos.y = 0;
fl_ui->cur_shift_pos.x = 0;
fl_ui->cur_shift_pos.y = 0;
fl_ui->text_len = 0;
}
@@ -132,20 +152,26 @@ void w_te_draw(w_te_ui_t *fui) {
wchar_t *nl_ptr = wcschr(cur_ptr, '\n');
if (nl_ptr == NULL) {
mvwaddnwstr(win, p_y++, p_x, cur_ptr, fui->text_len);
mvwaddnwstr(win, p_y, p_x, cur_ptr, fui->text_len);
p_x += fui->text_len;
} else {
while (true) {
mvwaddnwstr(win, p_y++, p_x, cur_ptr, nl_ptr - cur_ptr);
cur_ptr = nl_ptr + 1;
nl_ptr = wcschr(cur_ptr, '\n');
if (nl_ptr == NULL) {
mvwaddnwstr(win, p_y++, p_x, cur_ptr, wcslen(cur_ptr));
int tlen = wcslen(cur_ptr);
mvwaddnwstr(win, p_y, p_x, cur_ptr, tlen);
p_x += tlen;
break;
}
}
}
fui->cur_pos.y = i;
fui->cur_abs_pos.y = p_y;
fui->cur_abs_pos.x = p_x;
wmove(win, fui->cur_abs_pos.y + fui->cur_shift_pos.y, fui->cur_abs_pos.x + fui->cur_shift_pos.x);
p_x = 1;
+10 -5
View File
@@ -5,23 +5,28 @@
#define W_TEXT_EDIT_H
#include "../app.h"
#include <stddef.h>
#include <wchar.h>
#include <widget_core.h>
#include <ncursesw/ncurses.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
#include <wchar.h>
#include <widget_core.h>
typedef struct {
w_t w;
WINDOW *win;
wchar_t text[INBUFSIZE * 10];
int text_len;
int text_cur_pos;
struct {
int x;
int y;
} cur_pos;
void *file_pt; // TODO: уточнить
} cur_shift_pos;
struct {
int x;
int y;
} cur_abs_pos;
p_file_t *file_ptr; // TODO: уточнить
} w_te_ui_t;
void w_te_draw(w_te_ui_t *fl_ui);