From 1240a44298dd5592436f0610f38483be22f9c107 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sun, 20 Nov 2016 17:54:04 +0100 Subject: [PATCH] Type escape colon to enter commands in editor(1). --- editor/editor.1 | 3 ++- editor/input.c | 42 +----------------------------------------- editor/input.h | 1 - 3 files changed, 3 insertions(+), 43 deletions(-) diff --git a/editor/editor.1 b/editor/editor.1 index 0b9d7416..95ffa17d 100644 --- a/editor/editor.1 +++ b/editor/editor.1 @@ -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. diff --git a/editor/input.c b/editor/input.c index 8c1b7dae..fa9f8eaa 100644 --- a/editor/input.c +++ b/editor/input.c @@ -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; } diff --git a/editor/input.h b/editor/input.h index c2662e83..6caeb3d8 100644 --- a/editor/input.h +++ b/editor/input.h @@ -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);