Browse Source

Shrink definition of brackpaste sequence getch/ungetch

Let a boy have his golf, ok.
master
cancel 5 years ago
parent
commit
23e5e96cc1
  1. 44
      tui_main.c

44
tui_main.c

@ -2437,34 +2437,24 @@ typedef enum {
Brackpaste_seq_end, Brackpaste_seq_end,
} Brackpaste_seq; } Brackpaste_seq;
// Try to getch to complete the sequence of a start or end of brackpet paste
// escape sequence. If it doesn't turn out to be one, unwind it back into the
// event queue with ungetch. Yeah this is golfed let me have fun.
staticni Brackpaste_seq brackpaste_seq_getungetch(WINDOW *win) { staticni Brackpaste_seq brackpaste_seq_getungetch(WINDOW *win) {
int esc1 = wgetch(win); int chs[5], n = 0, begorend; // clang-format off
if (esc1 == '[') { if ((chs[n++] = wgetch(win)) != '[') goto unwind;
int esc2 = wgetch(win); if ((chs[n++] = wgetch(win)) != '2') goto unwind;
if (esc2 == '2') { if ((chs[n++] = wgetch(win)) != '0') goto unwind;
int esc3 = wgetch(win); chs[n++] = begorend = wgetch(win);
if (esc3 == '0') { if (begorend != '0' && begorend != '1') goto unwind;
int esc4 = wgetch(win); if ((chs[n++] = wgetch(win)) != '~') goto unwind;
// Start or end of bracketed paste switch (begorend) {
if (esc4 == '0' || esc4 == '1') { case '0': return Brackpaste_seq_begin;
int esc5 = wgetch(win); case '1': return Brackpaste_seq_end;
if (esc5 == '~') { } // clang-format on
switch (esc4) { unwind:
case '0': while (n > 0)
return Brackpaste_seq_begin; ungetch(chs[--n]);
case '1':
return Brackpaste_seq_end;
}
}
ungetch(esc5);
}
ungetch(esc4);
}
ungetch(esc3);
}
ungetch(esc2);
}
ungetch(esc1);
return Brackpaste_seq_none; return Brackpaste_seq_none;
} }

Loading…
Cancel
Save