summaryrefslogtreecommitdiffstats
path: root/src/ui.c
diff options
context:
space:
mode:
authorsijanec <anton@sijanec.eu>2021-03-16 23:38:00 +0100
committersijanec <anton@sijanec.eu>2021-03-16 23:38:00 +0100
commit1840a7c2ed24c2e4fa731430d36a6c1da597b8ee (patch)
tree387c5d47f4627ed631a6e1272519dd6ac5777bd6 /src/ui.c
parentfinnaly compiles (diff)
downloaddiscord.c-1840a7c2ed24c2e4fa731430d36a6c1da597b8ee.tar
discord.c-1840a7c2ed24c2e4fa731430d36a6c1da597b8ee.tar.gz
discord.c-1840a7c2ed24c2e4fa731430d36a6c1da597b8ee.tar.bz2
discord.c-1840a7c2ed24c2e4fa731430d36a6c1da597b8ee.tar.lz
discord.c-1840a7c2ed24c2e4fa731430d36a6c1da597b8ee.tar.xz
discord.c-1840a7c2ed24c2e4fa731430d36a6c1da597b8ee.tar.zst
discord.c-1840a7c2ed24c2e4fa731430d36a6c1da597b8ee.zip
Diffstat (limited to 'src/ui.c')
-rw-r--r--src/ui.c84
1 files changed, 84 insertions, 0 deletions
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 <stdlib.h>
+#include <stdio.h>
+#include <time.h>
+/* #include <api.c> */
+#include <ncursesw/ncurses.h>
+#include <ncursesw/form.h>
+#include <unistd.h>
+#include <locale.h>
+/* 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;
+}