2018-08-04 17:35:29 +00:00
|
|
|
/* Copyright (C) 2018 Curtis McEnroe <june@causal.agency>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define _XOPEN_SOURCE_EXTENDED
|
|
|
|
|
|
|
|
#include <curses.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <locale.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sysexits.h>
|
|
|
|
#include <wchar.h>
|
|
|
|
#include <wctype.h>
|
|
|
|
|
|
|
|
#include "chat.h"
|
2018-08-07 18:11:19 +00:00
|
|
|
#undef uiFmt
|
2018-08-04 17:35:29 +00:00
|
|
|
|
2018-08-05 18:59:51 +00:00
|
|
|
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
|
|
|
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
|
|
|
|
|
|
|
#define CTRL(c) ((c) & 037)
|
|
|
|
|
2018-08-04 17:58:44 +00:00
|
|
|
#ifndef A_ITALIC
|
|
|
|
#define A_ITALIC A_NORMAL
|
|
|
|
#endif
|
|
|
|
|
2018-08-05 18:59:51 +00:00
|
|
|
static void colorInit(void) {
|
|
|
|
start_color();
|
|
|
|
use_default_colors();
|
|
|
|
if (COLORS >= 16) {
|
2018-08-05 22:34:35 +00:00
|
|
|
for (short pair = 0; pair < 0x100; ++pair) {
|
2018-08-05 18:59:51 +00:00
|
|
|
if (pair < 0x10) {
|
|
|
|
init_pair(1 + pair, pair, -1);
|
|
|
|
} else {
|
|
|
|
init_pair(1 + pair, pair & 0x0F, (pair & 0xF0) >> 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2018-08-05 22:34:35 +00:00
|
|
|
for (short pair = 0; pair < 0100; ++pair) {
|
2018-08-05 18:59:51 +00:00
|
|
|
if (pair < 010) {
|
|
|
|
init_pair(1 + pair, pair, -1);
|
|
|
|
} else {
|
|
|
|
init_pair(1 + pair, pair & 007, (pair & 070) >> 3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-08-05 00:54:50 +00:00
|
|
|
|
2018-08-05 18:59:51 +00:00
|
|
|
static attr_t attr8(short pair) {
|
|
|
|
if (COLORS >= 16 || pair < 0) return A_NORMAL;
|
|
|
|
return (pair & 0x08) ? A_BOLD : A_NORMAL;
|
|
|
|
}
|
|
|
|
static short pair8(short pair) {
|
|
|
|
if (COLORS >= 16 || pair < 0) return pair;
|
|
|
|
return (pair & 0x70) >> 1 | (pair & 0x07);
|
|
|
|
}
|
2018-08-04 20:02:43 +00:00
|
|
|
|
2018-08-04 17:35:29 +00:00
|
|
|
static const int TOPIC_COLS = 512;
|
|
|
|
static const int INPUT_COLS = 512;
|
2018-08-04 21:59:43 +00:00
|
|
|
static const int LOG_LINES = 100;
|
2018-08-04 17:35:29 +00:00
|
|
|
|
2018-08-05 00:54:50 +00:00
|
|
|
static int lastLine(void) {
|
|
|
|
return LINES - 1;
|
|
|
|
}
|
|
|
|
static int lastCol(void) {
|
|
|
|
return COLS - 1;
|
|
|
|
}
|
|
|
|
static int logHeight(void) {
|
|
|
|
return LINES - 4;
|
|
|
|
}
|
|
|
|
|
2018-08-05 18:59:51 +00:00
|
|
|
static struct {
|
|
|
|
WINDOW *topic;
|
|
|
|
WINDOW *log;
|
|
|
|
WINDOW *input;
|
|
|
|
int scroll;
|
|
|
|
size_t cursor;
|
|
|
|
} ui;
|
|
|
|
|
2018-08-04 17:35:29 +00:00
|
|
|
void uiInit(void) {
|
|
|
|
setlocale(LC_CTYPE, "");
|
|
|
|
initscr();
|
|
|
|
cbreak();
|
|
|
|
noecho();
|
|
|
|
|
2018-08-05 18:59:51 +00:00
|
|
|
colorInit();
|
2018-08-04 17:35:29 +00:00
|
|
|
|
|
|
|
ui.topic = newpad(2, TOPIC_COLS);
|
|
|
|
mvwhline(ui.topic, 1, 0, ACS_HLINE, TOPIC_COLS);
|
|
|
|
|
2018-08-04 21:59:43 +00:00
|
|
|
ui.log = newpad(LOG_LINES, COLS);
|
|
|
|
wsetscrreg(ui.log, 0, LOG_LINES - 1);
|
|
|
|
scrollok(ui.log, true);
|
2018-08-05 00:54:50 +00:00
|
|
|
wmove(ui.log, LOG_LINES - logHeight() - 1, 0);
|
|
|
|
ui.scroll = LOG_LINES;
|
2018-08-04 17:35:29 +00:00
|
|
|
|
|
|
|
ui.input = newpad(2, INPUT_COLS);
|
|
|
|
mvwhline(ui.input, 0, 0, ACS_HLINE, INPUT_COLS);
|
2018-08-07 02:14:59 +00:00
|
|
|
wmove(ui.input, 1, 0);
|
2018-08-05 00:54:50 +00:00
|
|
|
|
|
|
|
keypad(ui.input, true);
|
2018-08-04 19:04:48 +00:00
|
|
|
nodelay(ui.input, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uiResize(void) {
|
2018-08-04 21:59:43 +00:00
|
|
|
wresize(ui.log, LOG_LINES, COLS);
|
|
|
|
wmove(ui.log, LOG_LINES - 1, COLS - 1);
|
2018-08-04 17:35:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiHide(void) {
|
|
|
|
endwin();
|
2018-08-05 01:23:28 +00:00
|
|
|
printf(
|
|
|
|
"This program is AGPLv3 free software!\n"
|
2018-08-05 15:00:01 +00:00
|
|
|
"The source is available at <" SOURCE_URL ">.\n"
|
2018-08-05 01:23:28 +00:00
|
|
|
);
|
2018-08-04 17:35:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiDraw(void) {
|
2018-08-04 21:08:15 +00:00
|
|
|
pnoutrefresh(
|
|
|
|
ui.topic,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
2018-08-05 00:54:50 +00:00
|
|
|
1, lastCol()
|
2018-08-04 21:08:15 +00:00
|
|
|
);
|
2018-08-04 17:35:29 +00:00
|
|
|
pnoutrefresh(
|
2018-08-04 21:59:43 +00:00
|
|
|
ui.log,
|
2018-08-05 00:54:50 +00:00
|
|
|
ui.scroll - logHeight(), 0,
|
2018-08-04 21:08:15 +00:00
|
|
|
2, 0,
|
2018-08-05 00:54:50 +00:00
|
|
|
lastLine() - 2, lastCol()
|
2018-08-04 17:35:29 +00:00
|
|
|
);
|
2018-08-07 02:14:59 +00:00
|
|
|
int _, x;
|
|
|
|
getyx(ui.input, _, x);
|
2018-08-04 17:35:29 +00:00
|
|
|
pnoutrefresh(
|
|
|
|
ui.input,
|
2018-08-07 04:09:50 +00:00
|
|
|
0, MAX(0, x - lastCol() + 3),
|
2018-08-05 00:54:50 +00:00
|
|
|
lastLine() - 1, 0,
|
|
|
|
lastLine(), lastCol()
|
2018-08-04 17:35:29 +00:00
|
|
|
);
|
|
|
|
doupdate();
|
|
|
|
}
|
|
|
|
|
2018-08-05 18:59:51 +00:00
|
|
|
static void uiRedraw(void) {
|
|
|
|
clearok(curscr, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const short IRC_COLORS[16] = {
|
2018-08-05 17:28:49 +00:00
|
|
|
8 + COLOR_WHITE, // white
|
|
|
|
0 + COLOR_BLACK, // black
|
|
|
|
0 + COLOR_BLUE, // blue
|
|
|
|
0 + COLOR_GREEN, // green
|
|
|
|
8 + COLOR_RED, // red
|
|
|
|
0 + COLOR_RED, // brown
|
|
|
|
0 + COLOR_MAGENTA, // magenta
|
|
|
|
0 + COLOR_YELLOW, // orange
|
|
|
|
8 + COLOR_YELLOW, // yellow
|
|
|
|
8 + COLOR_GREEN, // light green
|
|
|
|
0 + COLOR_CYAN, // cyan
|
|
|
|
8 + COLOR_CYAN, // light cyan
|
|
|
|
8 + COLOR_BLUE, // light blue
|
|
|
|
8 + COLOR_MAGENTA, // pink
|
|
|
|
8 + COLOR_BLACK, // gray
|
|
|
|
0 + COLOR_WHITE, // light gray
|
2018-08-04 17:35:29 +00:00
|
|
|
};
|
|
|
|
|
2018-08-06 18:19:52 +00:00
|
|
|
static const wchar_t *parseColor(short *pair, const wchar_t *str) {
|
2018-08-04 20:36:25 +00:00
|
|
|
short fg = 0;
|
2018-08-06 18:19:52 +00:00
|
|
|
size_t fgLen = MIN(wcsspn(str, L"0123456789"), 2);
|
2018-08-05 17:28:49 +00:00
|
|
|
if (!fgLen) { *pair = -1; return str; }
|
2018-08-04 20:36:25 +00:00
|
|
|
for (size_t i = 0; i < fgLen; ++i) {
|
2018-08-06 18:19:52 +00:00
|
|
|
fg = fg * 10 + (str[i] - L'0');
|
2018-08-04 20:36:25 +00:00
|
|
|
}
|
|
|
|
str = &str[fgLen];
|
|
|
|
|
|
|
|
short bg = 0;
|
2018-08-06 18:19:52 +00:00
|
|
|
size_t bgLen = 0;
|
|
|
|
if (str[0] == L',') bgLen = MIN(wcsspn(&str[1], L"0123456789"), 2);
|
2018-08-04 20:36:25 +00:00
|
|
|
for (size_t i = 0; i < bgLen; ++i) {
|
2018-08-06 18:19:52 +00:00
|
|
|
bg = bg * 10 + (str[1 + i] - L'0');
|
2018-08-04 20:36:25 +00:00
|
|
|
}
|
|
|
|
if (bgLen) str = &str[1 + bgLen];
|
|
|
|
|
2018-08-05 17:28:49 +00:00
|
|
|
if (*pair == -1) *pair = 0;
|
2018-08-05 18:59:51 +00:00
|
|
|
*pair = (*pair & 0xF0) | IRC_COLORS[fg & 0x0F];
|
|
|
|
if (bgLen) *pair = (*pair & 0x0F) | (IRC_COLORS[bg & 0x0F] << 4);
|
2018-08-04 20:36:25 +00:00
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2018-08-06 19:12:13 +00:00
|
|
|
static void wordWrap(WINDOW *win, const wchar_t *str) {
|
|
|
|
size_t len = wcscspn(str, L" ");
|
|
|
|
size_t width = 1;
|
|
|
|
for (size_t i = 0; i < len; ++i) {
|
|
|
|
if (iswprint(str[i])) width += wcwidth(str[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
int _, x, xMax;
|
|
|
|
getyx(win, _, x);
|
|
|
|
getmaxyx(win, _, xMax);
|
|
|
|
|
|
|
|
if (width >= (size_t)(xMax - x)) {
|
|
|
|
waddch(win, '\n');
|
|
|
|
} else {
|
|
|
|
waddch(win, ' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-07 04:09:50 +00:00
|
|
|
enum {
|
|
|
|
IRC_BOLD = 0x02,
|
|
|
|
IRC_COLOR = 0x03,
|
|
|
|
IRC_REVERSE = 0x16,
|
|
|
|
IRC_RESET = 0x0F,
|
|
|
|
IRC_ITALIC = 0x1D,
|
|
|
|
IRC_UNDERLINE = 0x1F,
|
|
|
|
};
|
|
|
|
static const wchar_t IRC_CODES[] = {
|
|
|
|
L' ',
|
|
|
|
IRC_BOLD,
|
|
|
|
IRC_COLOR,
|
|
|
|
IRC_REVERSE,
|
|
|
|
IRC_RESET,
|
|
|
|
IRC_ITALIC,
|
|
|
|
IRC_UNDERLINE,
|
|
|
|
L'\0',
|
|
|
|
};
|
|
|
|
|
2018-08-06 18:19:52 +00:00
|
|
|
static void addIRC(WINDOW *win, const wchar_t *str) {
|
2018-08-04 17:35:29 +00:00
|
|
|
attr_t attr = A_NORMAL;
|
2018-08-05 17:28:49 +00:00
|
|
|
short pair = -1;
|
2018-08-04 17:35:29 +00:00
|
|
|
for (;;) {
|
2018-08-07 04:09:50 +00:00
|
|
|
size_t cc = wcscspn(str, IRC_CODES);
|
2018-08-05 17:28:49 +00:00
|
|
|
wattr_set(win, attr | attr8(pair), 1 + pair8(pair), NULL);
|
2018-08-06 18:19:52 +00:00
|
|
|
waddnwstr(win, str, cc);
|
2018-08-04 17:35:29 +00:00
|
|
|
if (!str[cc]) break;
|
|
|
|
|
|
|
|
str = &str[cc];
|
|
|
|
switch (*str++) {
|
2018-08-07 04:09:50 +00:00
|
|
|
break; case L' ': wordWrap(win, str);
|
|
|
|
break; case IRC_BOLD: attr ^= A_BOLD;
|
|
|
|
break; case IRC_ITALIC: attr ^= A_ITALIC;
|
|
|
|
break; case IRC_UNDERLINE: attr ^= A_UNDERLINE;
|
|
|
|
break; case IRC_REVERSE: attr ^= A_REVERSE;
|
|
|
|
break; case IRC_COLOR: str = parseColor(&pair, str);
|
|
|
|
break; case IRC_RESET: attr = A_NORMAL; pair = -1;
|
2018-08-04 17:35:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-06 18:19:52 +00:00
|
|
|
void uiTopic(const wchar_t *topic) {
|
2018-08-04 17:35:29 +00:00
|
|
|
wmove(ui.topic, 0, 0);
|
2018-08-05 18:59:51 +00:00
|
|
|
addIRC(ui.topic, topic);
|
2018-08-04 17:35:29 +00:00
|
|
|
wclrtoeol(ui.topic);
|
|
|
|
}
|
|
|
|
|
2018-08-06 18:19:52 +00:00
|
|
|
void uiTopicStr(const char *topic) {
|
|
|
|
size_t len = strlen(topic);
|
|
|
|
wchar_t wcs[1 + len];
|
|
|
|
len = mbstowcs(wcs, topic, 1 + len);
|
|
|
|
if (len == (size_t)-1) err(EX_DATAERR, "mbstowcs");
|
|
|
|
uiTopic(wcs);
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiLog(const wchar_t *line) {
|
2018-08-04 21:59:43 +00:00
|
|
|
waddch(ui.log, '\n');
|
2018-08-05 18:59:51 +00:00
|
|
|
addIRC(ui.log, line);
|
2018-08-04 17:35:29 +00:00
|
|
|
}
|
|
|
|
|
2018-08-06 18:19:52 +00:00
|
|
|
void uiFmt(const wchar_t *format, ...) {
|
|
|
|
wchar_t *buf;
|
2018-08-04 17:35:29 +00:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
2018-08-06 18:19:52 +00:00
|
|
|
vaswprintf(&buf, format, ap);
|
2018-08-04 17:35:29 +00:00
|
|
|
va_end(ap);
|
2018-08-06 18:19:52 +00:00
|
|
|
if (!buf) err(EX_OSERR, "vaswprintf");
|
2018-08-04 21:59:43 +00:00
|
|
|
uiLog(buf);
|
2018-08-04 17:35:29 +00:00
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
|
2018-08-06 15:22:45 +00:00
|
|
|
static void logUp(void) {
|
2018-08-05 00:54:50 +00:00
|
|
|
if (ui.scroll == logHeight()) return;
|
|
|
|
ui.scroll = MAX(ui.scroll - logHeight() / 2, logHeight());
|
|
|
|
}
|
2018-08-06 15:22:45 +00:00
|
|
|
static void logDown(void) {
|
2018-08-05 00:54:50 +00:00
|
|
|
if (ui.scroll == LOG_LINES) return;
|
|
|
|
ui.scroll = MIN(ui.scroll + logHeight() / 2, LOG_LINES);
|
|
|
|
}
|
|
|
|
|
2018-08-07 18:14:07 +00:00
|
|
|
enum { BUF_LEN = 512 };
|
2018-08-05 00:54:50 +00:00
|
|
|
static struct {
|
2018-08-07 18:14:07 +00:00
|
|
|
wchar_t buf[BUF_LEN];
|
2018-08-07 02:14:59 +00:00
|
|
|
wchar_t *ptr;
|
|
|
|
wchar_t *end;
|
|
|
|
} line = { .ptr = line.buf, .end = line.buf };
|
2018-08-05 00:54:50 +00:00
|
|
|
|
2018-08-06 15:22:45 +00:00
|
|
|
static void left(void) {
|
2018-08-07 02:14:59 +00:00
|
|
|
if (line.ptr > line.buf) line.ptr--;
|
2018-08-05 00:54:50 +00:00
|
|
|
}
|
2018-08-06 15:22:45 +00:00
|
|
|
static void right(void) {
|
2018-08-07 02:14:59 +00:00
|
|
|
if (line.ptr < line.end) line.ptr++;
|
2018-08-05 00:54:50 +00:00
|
|
|
}
|
2018-08-06 15:22:45 +00:00
|
|
|
static void home(void) {
|
2018-08-07 02:14:59 +00:00
|
|
|
line.ptr = line.buf;
|
2018-08-05 00:54:50 +00:00
|
|
|
}
|
2018-08-06 15:22:45 +00:00
|
|
|
static void end(void) {
|
2018-08-07 02:14:59 +00:00
|
|
|
line.ptr = line.end;
|
2018-08-05 00:54:50 +00:00
|
|
|
}
|
|
|
|
|
2018-08-06 15:22:45 +00:00
|
|
|
static void kill(void) {
|
2018-08-07 02:14:59 +00:00
|
|
|
line.end = line.ptr;
|
2018-08-06 15:22:45 +00:00
|
|
|
}
|
|
|
|
|
2018-08-05 00:54:50 +00:00
|
|
|
static void insert(wchar_t ch) {
|
2018-08-07 02:14:59 +00:00
|
|
|
if (line.end == &line.buf[BUF_LEN - 1]) return;
|
|
|
|
if (line.ptr != line.end) {
|
|
|
|
wmemmove(line.ptr + 1, line.ptr, line.end - line.ptr);
|
2018-08-05 00:54:50 +00:00
|
|
|
}
|
2018-08-07 02:14:59 +00:00
|
|
|
*line.ptr++ = ch;
|
|
|
|
line.end++;
|
2018-08-05 00:54:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void backspace(void) {
|
2018-08-07 02:14:59 +00:00
|
|
|
if (line.ptr == line.buf) return;
|
|
|
|
if (line.ptr != line.end) {
|
|
|
|
wmemmove(line.ptr - 1, line.ptr, line.end - line.ptr);
|
2018-08-05 00:54:50 +00:00
|
|
|
}
|
2018-08-07 02:14:59 +00:00
|
|
|
line.ptr--;
|
|
|
|
line.end--;
|
2018-08-05 00:54:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void delete(void) {
|
2018-08-07 02:14:59 +00:00
|
|
|
if (line.ptr == line.end) return;
|
2018-08-06 15:22:45 +00:00
|
|
|
right();
|
2018-08-05 00:54:50 +00:00
|
|
|
backspace();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void enter(void) {
|
2018-08-07 02:14:59 +00:00
|
|
|
if (line.end == line.buf) return;
|
|
|
|
*line.end = L'\0';
|
2018-08-05 00:54:50 +00:00
|
|
|
input(line.buf);
|
2018-08-07 02:14:59 +00:00
|
|
|
line.ptr = line.buf;
|
|
|
|
line.end = line.buf;
|
2018-08-05 00:54:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void keyChar(wint_t ch) {
|
|
|
|
switch (ch) {
|
2018-08-05 18:59:51 +00:00
|
|
|
break; case CTRL('L'): uiRedraw();
|
2018-08-06 15:22:45 +00:00
|
|
|
break; case CTRL('B'): left();
|
|
|
|
break; case CTRL('F'): right();
|
|
|
|
break; case CTRL('A'): home();
|
|
|
|
break; case CTRL('E'): end();
|
2018-08-05 00:54:50 +00:00
|
|
|
break; case CTRL('D'): delete();
|
|
|
|
break; case CTRL('K'): kill();
|
|
|
|
break; case '\b': backspace();
|
|
|
|
break; case '\177': backspace();
|
|
|
|
break; case '\n': enter();
|
2018-08-07 04:09:50 +00:00
|
|
|
break; case CTRL('C'): insert(IRC_COLOR);
|
|
|
|
break; case CTRL('N'): insert(IRC_RESET);
|
|
|
|
break; case CTRL('O'): insert(IRC_BOLD);
|
|
|
|
break; case CTRL('R'): insert(IRC_COLOR);
|
|
|
|
break; case CTRL('T'): insert(IRC_ITALIC);
|
|
|
|
break; case CTRL('U'): insert(IRC_UNDERLINE);
|
|
|
|
break; case CTRL('V'): insert(IRC_REVERSE);
|
2018-08-07 02:14:59 +00:00
|
|
|
break; default: if (iswprint(ch)) insert(ch);
|
2018-08-05 00:54:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void keyCode(wint_t ch) {
|
|
|
|
switch (ch) {
|
|
|
|
break; case KEY_RESIZE: uiResize();
|
2018-08-06 15:22:45 +00:00
|
|
|
break; case KEY_PPAGE: logUp();
|
|
|
|
break; case KEY_NPAGE: logDown();
|
|
|
|
break; case KEY_LEFT: left();
|
|
|
|
break; case KEY_RIGHT: right();
|
|
|
|
break; case KEY_HOME: home();
|
|
|
|
break; case KEY_END: end();
|
2018-08-05 00:54:50 +00:00
|
|
|
break; case KEY_BACKSPACE: backspace();
|
|
|
|
break; case KEY_DC: delete();
|
|
|
|
break; case KEY_ENTER: enter();
|
|
|
|
}
|
|
|
|
}
|
2018-08-04 17:35:29 +00:00
|
|
|
|
2018-08-05 00:54:50 +00:00
|
|
|
void uiRead(void) {
|
|
|
|
int ret;
|
2018-08-04 17:35:29 +00:00
|
|
|
wint_t ch;
|
2018-08-05 00:54:50 +00:00
|
|
|
while (ERR != (ret = wget_wch(ui.input, &ch))) {
|
|
|
|
if (ret == KEY_CODE_YES) {
|
|
|
|
keyCode(ch);
|
|
|
|
} else {
|
|
|
|
keyChar(ch);
|
2018-08-04 17:35:29 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-07 02:14:59 +00:00
|
|
|
|
2018-08-04 17:35:29 +00:00
|
|
|
wmove(ui.input, 1, 0);
|
2018-08-07 02:14:59 +00:00
|
|
|
|
|
|
|
ch = *line.ptr;
|
|
|
|
*line.ptr = L'\0';
|
|
|
|
addIRC(ui.input, line.buf);
|
|
|
|
*line.ptr = ch;
|
|
|
|
|
|
|
|
int _, x;
|
|
|
|
getyx(ui.input, _, x);
|
|
|
|
|
|
|
|
*line.end = L'\0';
|
|
|
|
addIRC(ui.input, line.ptr);
|
|
|
|
|
2018-08-04 17:35:29 +00:00
|
|
|
wclrtoeol(ui.input);
|
2018-08-07 02:14:59 +00:00
|
|
|
wmove(ui.input, 1, x);
|
2018-08-04 17:35:29 +00:00
|
|
|
}
|