summaryrefslogtreecommitdiffstats
path: root/src/ui.c
blob: 3f8dbafb0fdd6a5d1869dbd314482096a1e812b3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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;
}