tAllow escape from prompt, better line delete handling of cursor - ve - a minimal text editor (work in progress)
 (HTM) git clone git://src.adamsgaard.dk/ve
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 0bcce6ea7409b475034ddaf2e79439468b161869
 (DIR) parent 68ebb8e650025d82f30c96de9564f924c6bfdb37
 (HTM) Author: Anders Damsgaard <anders@adamsgaard.dk>
       Date:   Tue,  6 Aug 2019 21:09:25 +0200
       
       Allow escape from prompt, better line delete handling of cursor
       
       Diffstat:
         M input.c                             |       7 ++++++-
         M io.c                                |       7 ++++++-
         M output.c                            |       9 ++++++---
       
       3 files changed, 18 insertions(+), 5 deletions(-)
       ---
 (DIR) diff --git a/input.c b/input.c
       t@@ -28,7 +28,11 @@ editor_prompt(char *prompt)
                        editor_refresh_screen();
        
                        c = editor_read_key();
       -                if (c == '\r') {
       +                if (c == '\x1b') { /* detect escape */
       +                        editor_set_status_message("");
       +                        free(buf);
       +                        return NULL;
       +                } else if (c == '\r') {
                                if (buflen != 0) {
                                        editor_set_status_message("");
                                        return buf;
       t@@ -171,6 +175,7 @@ editor_process_keypress()
                                        break;
                                case 'd':
                                        editor_row_delete(E.cursor_y);
       +                                editor_move_cursor('h');
                                        break;
        
                                case 'o':
 (DIR) diff --git a/io.c b/io.c
       t@@ -73,8 +73,13 @@ file_save(char *filename)
                int len, fd;
                char *buf;
        
       -        if (filename == NULL)
       +        if (filename == NULL) {
                        filename = editor_prompt("save as: %s");
       +                if (filename == NULL) {
       +                        editor_set_status_message("save aborted");
       +                        return;
       +                }
       +        }
        
                buf = editor_concatenate_rows(&len);
        
 (DIR) diff --git a/output.c b/output.c
       t@@ -52,16 +52,17 @@ editor_draw_status(struct abuf *ab)
        {
                char left_status[512], right_status[512];
                int left_status_len, right_status_len, padding;
       +        int percentage;
        
                left_status_len = 0;
                switch (E.mode) {
                        case 1:
                                left_status_len = snprintf(left_status, sizeof(left_status),
       -                                                   "INSERT > ");
       +                                                   "INSERT ");
                                break;
                        case 2:
                                left_status_len = snprintf(left_status, sizeof(left_status),
       -                                                   "VISUAL > ");
       +                                                   "VISUAL ");
                                break;
                }
                left_status_len += snprintf(left_status + left_status_len,
       t@@ -70,9 +71,11 @@ editor_draw_status(struct abuf *ab)
                                            E.filename ? E.filename : "[unnamed]",
                                            E.file_changed ? "[+] " : "");
        
       +        percentage = (int)((float)(E.cursor_y)/(E.num_rows-1)*100);
       +        if (percentage < 0) percentage = 0;
                right_status_len = snprintf(right_status, sizeof(right_status),
                                            "%d%% < %d:%d",
       -                                    abs((int)((float)(E.cursor_y)/(E.num_rows-1)*100)),
       +                                    percentage,
                                            E.cursor_x+1, E.cursor_y+1);
        
                if (left_status_len > E.screen_columns)