#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;
}