From 2fcd0535174448803f197ae43d165071c6a0563d Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Mon, 4 May 2020 05:35:59 +0000 Subject: [PATCH] When inkey() receives an ANSI escape sequence it doesn't need to consume, put the consumed characters into the keyboard buffer *ahead* of whatever else is in the keyboard buffer already. Uses new ungetkey() insert mode option. --- src/sbbs3/getkey.cpp | 16 ++++++++++++---- src/sbbs3/inkey.cpp | 16 ++++++++-------- src/sbbs3/sbbs.h | 2 +- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/sbbs3/getkey.cpp b/src/sbbs3/getkey.cpp index fc86c1ab52..c4c385bc8d 100644 --- a/src/sbbs3/getkey.cpp +++ b/src/sbbs3/getkey.cpp @@ -562,13 +562,21 @@ void sbbs_t::pause() /****************************************************************************/ /* Puts a character into the input buffer */ /****************************************************************************/ -void sbbs_t::ungetkey(char ch) +void sbbs_t::ungetkey(char ch, bool insert) { #if 0 /* this way breaks ansi_getxy() */ RingBufWrite(&inbuf,(uchar*)&ch,sizeof(uchar)); #else - keybuf[keybuftop++]=ch; - if(keybuftop==KEY_BUFSIZE) - keybuftop=0; + if(insert) { + if(keybufbot == 0) + keybufbot = KEY_BUFSIZE - 1; + else + keybufbot--; + keybuf[keybufbot] = ch; + } else { + keybuf[keybuftop++]=ch; + if(keybuftop==KEY_BUFSIZE) + keybuftop=0; + } #endif } diff --git a/src/sbbs3/inkey.cpp b/src/sbbs3/inkey.cpp index 44d319ac30..90e2ee63d0 100644 --- a/src/sbbs3/inkey.cpp +++ b/src/sbbs3/inkey.cpp @@ -306,7 +306,7 @@ char sbbs_t::handle_ctrlkey(char ch, long mode) return(ESC); ch=i; if(ch!='[') { - ungetkey(ch); + ungetkey(ch, /* insert: */true); return(ESC); } i=j=0; @@ -363,10 +363,10 @@ char sbbs_t::handle_ctrlkey(char ch, long mode) } break; } - ungetkey('['); - for(j=0;j<i;j++) - ungetkey(str[j]); - ungetkey(ch); + ungetkey(ch, /* insert: */true); + for(j = i; j > 0; j--) + ungetkey(str[j - 1], /* insert: */true); + ungetkey('[', /* insert: */true); return(ESC); } if(ch=='R') { /* cursor position report */ @@ -386,9 +386,9 @@ char sbbs_t::handle_ctrlkey(char ch, long mode) str[i++]=ch; } - ungetkey('['); - for(j=0;j<i;j++) - ungetkey(str[j]); + for(j = i; j > 0; j--) + ungetkey(str[j - 1], /* insert: */true); + ungetkey('[', /* insert: */true); return(ESC); } return(ch); diff --git a/src/sbbs3/sbbs.h b/src/sbbs3/sbbs.h index 569c5632d6..929b937d91 100644 --- a/src/sbbs3/sbbs.h +++ b/src/sbbs3/sbbs.h @@ -784,7 +784,7 @@ public: /* getkey.cpp */ char getkey(long mode); /* Waits for a key hit local or remote */ long getkeys(const char *str, ulong max, long mode = K_UPPER); - void ungetkey(char ch); /* Places 'ch' into the input buffer */ + void ungetkey(char ch, bool insert = false); /* Places 'ch' into the input buffer */ char question[MAX_TEXTDAT_ITEM_LEN+1]; bool yesno(const char *str, long mode = 0); bool noyes(const char *str, long mode = 0); -- GitLab