Commit 1240a442 authored by Jonas Termansen's avatar Jonas Termansen

Type escape colon to enter commands in editor(1).

parent 31824718
......@@ -39,7 +39,8 @@ Paste.
.El
.Pp
These commands than can be entered after pressing
.Sy ESC :
.Sy ESC
and a colon:
.Bl -tag -width "12345768"
.It Sy language Oo Sy none "|" Sy c "|" Sy c++ "|" Sy diff Oc
Select syntax highlighting.
......
......@@ -260,38 +260,11 @@ void editor_input_begin(struct editor_input* editor_input)
void editor_input_process(struct editor_input* editor_input,
struct editor* editor)
{
bool was_ambiguous_escape = editor_input->ambiguous_escape;
editor_input->ambiguous_escape = false;
if ( was_ambiguous_escape )
fcntl(0, F_SETFL, fcntl(0, F_GETFL, (void*) NULL) | O_NONBLOCK);
unsigned char uc;
ssize_t amount_read = read(0, &uc, sizeof(uc));
if ( was_ambiguous_escape )
fcntl(0, F_SETFL, fcntl(0, F_GETFL, (void*) NULL) &~ O_NONBLOCK);
if ( amount_read != sizeof(uc) )
{
if ( was_ambiguous_escape &&
(errno == EWOULDBLOCK || errno == EAGAIN) )
uc = ':';
else
return;
}
#if 0
if ( 1 <= uc && uc <= 26 )
fprintf(stderr, "Input: ^%c\n", 'A' + uc - 1);
else if ( uc == '\e' )
fprintf(stderr, "Input: ^[\n");
else
fprintf(stderr, "Input: '%c'\n", uc);
#endif
#if 0
fputc(uc, stderr);
#endif
return;
if ( editor_input->termseq_used < MAX_TERMSEQ_SIZE )
editor_input->termseq[editor_input->termseq_used++] = (char) uc;
......@@ -352,19 +325,6 @@ void editor_input_process(struct editor_input* editor_input,
if ( partial_match )
{
editor_input->termseq_seen = editor_input->termseq_used;
// HACK: We can't reliably tell an actual escape press apart from
// the beginning of an escape sequence. However, we could use
// timing to get close to the truth, through the assumption
// that a following non-blocking read will fail only if this
// was a single escape press.
if ( editor_input->termseq_used == 1 &&
editor_input->termseq[0] == '\e' )
{
editor_input->ambiguous_escape = true;
return editor_input_process(editor_input, editor);
}
continue;
}
......
......@@ -48,7 +48,6 @@ struct editor_input
char termseq[MAX_TERMSEQ_SIZE];
size_t termseq_used;
size_t termseq_seen;
bool ambiguous_escape;
};
void editor_input_begin(struct editor_input* editor_input);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment