mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Type escape colon to enter commands in editor(1).
This commit is contained in:
parent
3182471881
commit
1240a44298
3 changed files with 3 additions and 43 deletions
|
@ -39,7 +39,8 @@ Paste.
|
||||||
.El
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
These commands than can be entered after pressing
|
These commands than can be entered after pressing
|
||||||
.Sy ESC :
|
.Sy ESC
|
||||||
|
and a colon:
|
||||||
.Bl -tag -width "12345768"
|
.Bl -tag -width "12345768"
|
||||||
.It Sy language Oo Sy none "|" Sy c "|" Sy c++ "|" Sy diff Oc
|
.It Sy language Oo Sy none "|" Sy c "|" Sy c++ "|" Sy diff Oc
|
||||||
Select syntax highlighting.
|
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,
|
void editor_input_process(struct editor_input* editor_input,
|
||||||
struct editor* editor)
|
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;
|
unsigned char uc;
|
||||||
ssize_t amount_read = read(0, &uc, sizeof(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 ( amount_read != sizeof(uc) )
|
||||||
{
|
|
||||||
if ( was_ambiguous_escape &&
|
|
||||||
(errno == EWOULDBLOCK || errno == EAGAIN) )
|
|
||||||
uc = ':';
|
|
||||||
else
|
|
||||||
return;
|
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
|
|
||||||
|
|
||||||
if ( editor_input->termseq_used < MAX_TERMSEQ_SIZE )
|
if ( editor_input->termseq_used < MAX_TERMSEQ_SIZE )
|
||||||
editor_input->termseq[editor_input->termseq_used++] = (char) uc;
|
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 )
|
if ( partial_match )
|
||||||
{
|
{
|
||||||
editor_input->termseq_seen = editor_input->termseq_used;
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,6 @@ struct editor_input
|
||||||
char termseq[MAX_TERMSEQ_SIZE];
|
char termseq[MAX_TERMSEQ_SIZE];
|
||||||
size_t termseq_used;
|
size_t termseq_used;
|
||||||
size_t termseq_seen;
|
size_t termseq_seen;
|
||||||
bool ambiguous_escape;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void editor_input_begin(struct editor_input* editor_input);
|
void editor_input_begin(struct editor_input* editor_input);
|
||||||
|
|
Loading…
Add table
Reference in a new issue