Description edit on save #1
@@ -11,10 +11,12 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
void ac_file(WINDOW *win, int is_action_w);
|
void ac_file(WINDOW *win, int is_action_w);
|
||||||
|
|
||||||
app_t *app_init(app_t *app) {
|
app_t *app_init(app_t *app) {
|
||||||
|
app->top_text = NULL;
|
||||||
/* get values from terminal size */
|
/* get values from terminal size */
|
||||||
int32_t y_max, x_max;
|
int32_t y_max, x_max;
|
||||||
getmaxyx(stdscr, 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.win = NULL;
|
||||||
app->modal.is_initiated = 0;
|
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 */
|
/* NULL to main_ui */
|
||||||
MAIN_UI_RESET(app);
|
MAIN_UI_RESET(app);
|
||||||
|
|
||||||
@@ -108,15 +103,17 @@ void app_draw_bars(app_t *app) {
|
|||||||
mvwprintw(app->win, app->coordinates.cur_y - 2, i, " ");
|
mvwprintw(app->win, app->coordinates.cur_y - 2, i, " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add content to the top bar */
|
if (app->top_text != NULL) {
|
||||||
if (app->params && app->params->is_connected) {
|
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;
|
int32_t ip_address = app->params->addr;
|
||||||
u_char ip_addr[4];
|
u_char ip_addr[4];
|
||||||
mempcpy(ip_addr, &ip_address, 4);
|
mempcpy(ip_addr, &ip_address, 4);
|
||||||
sprintf(top_text, "Connected to %u.%u.%u.%u, user: %s", ip_addr[0],
|
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);
|
ip_addr[1], ip_addr[2], ip_addr[3], app->params->uname);
|
||||||
}
|
|
||||||
mvwprintw(app->win, 1, 2, "%s", top_text);
|
mvwprintw(app->win, 1, 2, "%s", top_text);
|
||||||
|
}
|
||||||
|
|
||||||
wattroff(app->win, A_REVERSE);
|
wattroff(app->win, A_REVERSE);
|
||||||
|
|
||||||
/* add content to the bottom bar */
|
/* add content to the bottom bar */
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ typedef struct {
|
|||||||
file_args_t *file_args;
|
file_args_t *file_args;
|
||||||
void (*active_callback)(w_cb_args_t *args);
|
void (*active_callback)(w_cb_args_t *args);
|
||||||
void *active_widget;
|
void *active_widget;
|
||||||
|
wchar_t *top_text;
|
||||||
main_window_t main_ui;
|
main_window_t main_ui;
|
||||||
} app_t;
|
} app_t;
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ int main(int argc, char **argv) {
|
|||||||
app.query_args = &q_args;
|
app.query_args = &q_args;
|
||||||
|
|
||||||
main_window_set(&app, mw_fl_server);
|
main_window_set(&app, mw_fl_server);
|
||||||
|
|
||||||
/* init client to connect to the server */
|
/* init client to connect to the server */
|
||||||
app.params->sd = init_client();
|
app.params->sd = init_client();
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
int32_t m_id = 0;
|
int32_t m_id = 0;
|
||||||
|
|
||||||
|
|
||||||
void mini_loop(app_t *app) {
|
void mini_loop(app_t *app) {
|
||||||
w_cb_args_t d_args = {
|
w_cb_args_t d_args = {
|
||||||
.app = app, .element = NULL, .data = NULL, .resp_data.code = cbrc_none};
|
.app = app, .element = NULL, .data = NULL, .resp_data.code = cbrc_none};
|
||||||
@@ -52,7 +51,6 @@ void mini_loop(app_t *app) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
@@ -62,22 +60,23 @@ int main(void) {
|
|||||||
params_t params;
|
params_t params;
|
||||||
p_file_t file;
|
p_file_t file;
|
||||||
|
|
||||||
|
init_query_args(&q_args, app.params);
|
||||||
|
|
||||||
app.params = ¶ms;
|
app.params = ¶ms;
|
||||||
app.query_args = &q_args;
|
app.query_args = &q_args;
|
||||||
app.file_args = &fargs;
|
app.file_args = &fargs;
|
||||||
|
|
||||||
|
app_init_nc();
|
||||||
|
init_params(¶ms);
|
||||||
|
w_alert_init(&app);
|
||||||
|
app_init(&app);
|
||||||
|
|
||||||
q_args.file = &file;
|
q_args.file = &file;
|
||||||
app.query_args->main_ui = &(app.main_ui);
|
app.query_args->main_ui = &(app.main_ui);
|
||||||
|
|
||||||
file.name = "Test file #1";
|
file.name = "Test file #1";
|
||||||
params.is_connected = false;
|
params.is_connected = false;
|
||||||
app.modal.is_initiated = false;
|
app.modal.is_initiated = false;
|
||||||
|
|
||||||
app_init_nc();
|
|
||||||
app_init(&app);
|
|
||||||
init_params(¶ms);
|
|
||||||
init_query_args(&q_args, app.params);
|
|
||||||
w_alert_init(&app);
|
|
||||||
app_init(&app);
|
|
||||||
main_window_set(&app, mw_f_desc);
|
main_window_set(&app, mw_f_desc);
|
||||||
mini_loop(&app);
|
mini_loop(&app);
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ void main_window_set(app_t *app, enum main_window_type type) {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
app_draw_bars(app);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main_window_draw(app_t *app) {
|
void main_window_draw(app_t *app) {
|
||||||
|
|||||||
+32
-6
@@ -7,7 +7,9 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <utils.h>
|
#include <utils.h>
|
||||||
@@ -16,6 +18,8 @@
|
|||||||
#include "text_edit.h"
|
#include "text_edit.h"
|
||||||
#include "widget_core.h"
|
#include "widget_core.h"
|
||||||
|
|
||||||
|
/* TODO: create dynamic array of endline positions */
|
||||||
|
|
||||||
static void w_te_cb(w_cb_args_t *args) {
|
static void w_te_cb(w_cb_args_t *args) {
|
||||||
app_t *app = args->app;
|
app_t *app = args->app;
|
||||||
int32_t key = *((int32_t *)args->data);
|
int32_t key = *((int32_t *)args->data);
|
||||||
@@ -25,6 +29,15 @@ static void w_te_cb(w_cb_args_t *args) {
|
|||||||
case KEY_DL:
|
case KEY_DL:
|
||||||
fui->text[fui->text_len--] = 0;
|
fui->text[fui->text_len--] = 0;
|
||||||
break;
|
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:
|
default:
|
||||||
fui->text[fui->text_len++] = key;
|
fui->text[fui->text_len++] = key;
|
||||||
fui->text[fui->text_len] = 0;
|
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);
|
void w_te_reset_app(void *app);
|
||||||
|
|
||||||
w_te_ui_t *w_te_init_win(app_t *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));
|
w_te_ui_t *fui = malloc(sizeof(w_te_ui_t));
|
||||||
app->main_ui.ui = fui;
|
app->main_ui.ui = fui;
|
||||||
app->main_ui.type = mw_f_desc;
|
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;
|
app->active_callback = w_te_cb;
|
||||||
fui->w.callback = w_te_cb;
|
fui->w.callback = w_te_cb;
|
||||||
w_init(&(fui->w), NULL, &(app->win), "");
|
w_init(&(fui->w), NULL, &(app->win), "");
|
||||||
|
fui->file_ptr = app->query_args->file;
|
||||||
fui->w.sz.x = getmaxx(app->win);
|
fui->w.sz.x = getmaxx(app->win);
|
||||||
fui->w.sz.y = getmaxy(app->win);
|
fui->w.sz.y = getmaxy(app->win);
|
||||||
fui->w.parent_win = &(app->win);
|
fui->w.parent_win = &(app->win);
|
||||||
/* * INIT UI * */
|
/* * INIT UI * */
|
||||||
fui->win = newwin(fui->w.sz.y - 4, fui->w.sz.x - 2, 2, 1);
|
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;
|
return fui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void w_te_reset(w_te_ui_t *fl_ui) {
|
void w_te_reset(w_te_ui_t *fl_ui) {
|
||||||
fl_ui->text[0] = 0;
|
fl_ui->text[0] = 0;
|
||||||
fl_ui->cur_pos.x = 0;
|
fl_ui->cur_shift_pos.x = 0;
|
||||||
fl_ui->cur_pos.y = 0;
|
fl_ui->cur_shift_pos.y = 0;
|
||||||
fl_ui->text_len = 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');
|
wchar_t *nl_ptr = wcschr(cur_ptr, '\n');
|
||||||
|
|
||||||
if (nl_ptr == NULL) {
|
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 {
|
} else {
|
||||||
while (true) {
|
while (true) {
|
||||||
mvwaddnwstr(win, p_y++, p_x, cur_ptr, nl_ptr - cur_ptr);
|
mvwaddnwstr(win, p_y++, p_x, cur_ptr, nl_ptr - cur_ptr);
|
||||||
cur_ptr = nl_ptr + 1;
|
cur_ptr = nl_ptr + 1;
|
||||||
nl_ptr = wcschr(cur_ptr, '\n');
|
nl_ptr = wcschr(cur_ptr, '\n');
|
||||||
if (nl_ptr == NULL) {
|
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;
|
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;
|
p_x = 1;
|
||||||
|
|
||||||
|
|||||||
+10
-5
@@ -5,23 +5,28 @@
|
|||||||
#define W_TEXT_EDIT_H
|
#define W_TEXT_EDIT_H
|
||||||
|
|
||||||
#include "../app.h"
|
#include "../app.h"
|
||||||
#include <stddef.h>
|
|
||||||
#include <wchar.h>
|
|
||||||
#include <widget_core.h>
|
|
||||||
#include <ncursesw/ncurses.h>
|
#include <ncursesw/ncurses.h>
|
||||||
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
#include <widget_core.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
w_t w;
|
w_t w;
|
||||||
WINDOW *win;
|
WINDOW *win;
|
||||||
wchar_t text[INBUFSIZE * 10];
|
wchar_t text[INBUFSIZE * 10];
|
||||||
int text_len;
|
int text_len;
|
||||||
|
int text_cur_pos;
|
||||||
struct {
|
struct {
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
} cur_pos;
|
} cur_shift_pos;
|
||||||
void *file_pt; // TODO: уточнить
|
struct {
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
} cur_abs_pos;
|
||||||
|
p_file_t *file_ptr; // TODO: уточнить
|
||||||
} w_te_ui_t;
|
} w_te_ui_t;
|
||||||
|
|
||||||
void w_te_draw(w_te_ui_t *fl_ui);
|
void w_te_draw(w_te_ui_t *fl_ui);
|
||||||
|
|||||||
Reference in New Issue
Block a user