From 1840a7c2ed24c2e4fa731430d36a6c1da597b8ee Mon Sep 17 00:00:00 2001 From: sijanec Date: Tue, 16 Mar 2021 23:38:00 +0100 Subject: =?UTF-8?q?kon=C4=8Dal=20api,=20"kon=C4=8Dal"=20main,=20za=C4=8Del?= =?UTF-8?q?=20ui?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ui.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/ui.c (limited to 'src/ui.c') diff --git a/src/ui.c b/src/ui.c new file mode 100644 index 0000000..3f8dbaf --- /dev/null +++ b/src/ui.c @@ -0,0 +1,84 @@ +#define _XOPEN_SOURCE 600 +#define _POSIX_C_SOURCE 200809L +#include +#include +#include +/* #include */ +#include +#include +#include +#include +/* link with -lncursesw and -lformw */ +/* int dc_ui_thread (struct * dc_thread_control t) { */ +int main () { + FIELD * field[2]; /* field[0] je polje z besedilom */ + field[1] = NULL; + FORM * form; + int ret, x, y; + wint_t ch; + initscr(); + cbreak(); + noecho(); + nodelay(stdscr, TRUE); + setlocale(LC_ALL, "sl_SI.UTF-8"); + start_color(); + init_pair(0, COLOR_WHITE, COLOR_BLACK); + init_pair(1, COLOR_RED, COLOR_BLACK); + attron(COLOR_PAIR(1)); + keypad(stdscr, TRUE); + getmaxyx(stdscr, y, x); /* to je macro, zato y in x nista kazalca (;: */ + WINDOW * textwin = newwin(y-3, x, 0, 0); + WINDOW * formwin = newwin(2, x, y-2, 0); + scrollok(textwin, TRUE); + field[0] = new_field(2, x, y-2, 0, 5 /* offscreen rows */, 0); + set_field_back(field[0], A_UNDERLINE); + field_opts_off(field[0], O_AUTOSKIP); + form = new_form(field); + set_form_win(form, formwin); + post_form(form); + int i = 0; + wmove(textwin, 0, 0); + time_t last_time = 0; + refresh(); + while (1) { + if (last_time < time(NULL)) { + last_time = time(NULL); + attron(COLOR_PAIR(0)); + wprintw(textwin, "\nvrstica stevilka %d", i); + attron(COLOR_PAIR(1)); + mvprintw(y-3, 0, "#piš-ti-kurc-2 | discord.c | šijanec 2021"); + } + ret = get_wch(&ch); + if (ret != ERR) { + switch (ch) { + case KEY_LEFT: + form_driver(form, REQ_PREV_CHAR); + break; + case KEY_RIGHT: + form_driver(form, REQ_NEXT_CHAR); + break; + case KEY_BACKSPACE: + form_driver(form, REQ_DEL_PREV); + break; + case KEY_DOWN: + form_driver(form, REQ_SCR_FLINE); + break; + case KEY_UP: + form_driver(form, REQ_SCR_BLINE); + break; + default: + form_driver_w(form, ret, ch); + break; + } + } + wnoutrefresh(stdscr); + wnoutrefresh(textwin); + doupdate(); + i++; + } + unpost_form(form); + free_form(form); + free_field(field[0]); + endwin(); + return 1; +} -- cgit v1.2.3