Refactor uiRead

Centralizes the branching.
weechat-hashes
Curtis McEnroe 2019-02-25 12:51:21 -05:00
parent e8f40a2daf
commit 9d6f9d76c3
No known key found for this signature in database
GPG Key ID: CEA2F97ADCFCD77C
1 changed files with 34 additions and 34 deletions

48
ui.c
View File

@ -444,29 +444,8 @@ static void keyCode(wchar_t code) {
uiStatus();
}
static void keyChar(wchar_t ch) {
static void keyMeta(wchar_t ch) {
struct Window *win = windows.active;
if (ch < 0200) {
enum TermEvent event = termEvent((char)ch);
switch (event) {
break; case TermFocusIn: if (win) windowUnmark(win);
break; case TermFocusOut: if (win) windowMark(win);
break; default: {}
}
if (event) {
uiStatus();
return;
}
}
if (ch == Del) ch = L'\b';
static bool meta;
if (ch == Esc) {
meta = true;
return;
}
if (meta) {
meta = false;
if (ch >= L'0' && ch <= L'9') uiShowNum(ch - L'0', false);
if (!win) return;
switch (ch) {
@ -476,9 +455,10 @@ static void keyChar(wchar_t ch) {
break; case L'd': edit(win->tag, EditKillForeWord, 0);
break; case L'm': uiLog(win->tag, UICold, L"");
}
return;
}
static void keyChar(wchar_t ch) {
struct Window *win = windows.active;
if (ch == CTRL(L'L')) clearok(curscr, true);
if (!win) return;
switch (ch) {
@ -511,10 +491,30 @@ static void keyChar(wchar_t ch) {
void uiRead(void) {
if (ui.hide) uiShow();
static bool meta;
int ret;
wint_t ch;
enum TermEvent event;
while (ERR != (ret = wget_wch(ui.input, &ch))) {
(ret == KEY_CODE_YES ? keyCode(ch) : keyChar(ch));
if (ret == KEY_CODE_YES) {
keyCode(ch);
} else if (ch < 0200 && (event = termEvent((char)ch))) {
struct Window *win = windows.active;
switch (event) {
break; case TermFocusIn: if (win) windowUnmark(win);
break; case TermFocusOut: if (win) windowMark(win);
break; default: {}
}
uiStatus();
} else if (ch == Esc) {
meta = true;
continue;
} else if (meta) {
keyMeta(ch == Del ? '\b' : ch);
} else {
keyChar(ch == Del ? '\b' : ch);
}
meta = false;
}
uiPrompt(false);
}