^D is the opposite of ^U in vi (the ^D/^U pair is the half-screen
version of ^F/^B). ^C is unbound in vi. It's pretty surprising for these
to cause toybox vi to exit, and it's annoying as long as toybox vi
unconditionally exits rather than checks whether there are unsaved
modifications!

(I'm tempted to implement ^D/^U and ^F/^B, but I don't want to make
Jarno's rebase of his in-progress changes any harder.)
---
 toys/pending/vi.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
From 92e736a6f637698c463b9b0452d878f6cd2ccb0f Mon Sep 17 00:00:00 2001
From: Elliott Hughes <e...@google.com>
Date: Tue, 14 Jan 2020 14:19:32 -0800
Subject: [PATCH] vi: don't exit on ^C or ^D.

^D is the opposite of ^U in vi (the ^D/^U pair is the half-screen
version of ^F/^B). ^C is unbound in vi. It's pretty surprising for these
to cause toybox vi to exit, and it's annoying as long as toybox vi
unconditionally exits rather than checks whether there are unsaved
modifications!

(I'm tempted to implement ^D/^U and ^F/^B, but I don't want to make
Jarno's rebase of his in-progress changes any harder.)
---
 toys/pending/vi.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/toys/pending/vi.c b/toys/pending/vi.c
index 9906ca93..2fb6d442 100644
--- a/toys/pending/vi.c
+++ b/toys/pending/vi.c
@@ -909,9 +909,11 @@ void vi_main(void)
 
 
   draw_page();
-  while(1) {
+  for (;;) {
     int key = scan_key(keybuf, -1);
 
+    if (key == -1) goto cleanup_vi;
+
     terminal_size(&TT.screen_width, &TT.screen_height);
     TT.screen_height -= 2; //TODO this is hack fix visual alignment
 
@@ -926,12 +928,6 @@ void vi_main(void)
       continue;
     }
 
-    switch (key) {
-      case -1:
-      case 3:
-      case 4:
-        goto cleanup_vi;
-    }
     if (TT.vi_mode == 1) { //NORMAL
       switch (key) {
         case '/':
-- 
2.25.0.rc1.283.g88dfdc4193-goog

_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to