From 5e0d2ef7d2e41984a867e4a715118e33ad51455f Mon Sep 17 00:00:00 2001 From: "Rob Swindell (on ChromeOS)" <rob@synchro.net> Date: Tue, 21 Feb 2023 20:20:04 -0800 Subject: [PATCH] Add input K_TRIM and K_NOSPACE mode flags K_TRIM causes leading and trailing whitespace to be trimmed. K_NOSPACE disallows any whitespace characters to be added to the string. Previously, trailing whitespace was always trimmed. Now, only do that if/when K_TRIM is specified. --- src/uifc/uifc.h | 2 ++ src/uifc/uifc32.c | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/uifc/uifc.h b/src/uifc/uifc.h index b77c9b2181..d40c823b39 100644 --- a/src/uifc/uifc.h +++ b/src/uifc/uifc.h @@ -204,6 +204,8 @@ typedef int64_t uifc_winmode_t; /* And ungets the mouse event. */ #define K_PASSWORD (1L<<16) /* Does not display text while editing */ #define K_FIND (1L<<17) /* Don't set the "changes" flag */ +#define K_TRIM (1L<<23) /* Don't allow leading or trailing wsp */ +#define K_NOSPACE (1L<<26) /* Don't allow any wsp chars */ /* Extra exit flags */ diff --git a/src/uifc/uifc32.c b/src/uifc/uifc32.c index c6b0722f3a..f5c36d254f 100644 --- a/src/uifc/uifc32.c +++ b/src/uifc/uifc32.c @@ -2258,6 +2258,10 @@ int ugetstr(int left, int top, int width, char *outstr, int max, long mode, int pb=NULL; } } + if((mode & K_TRIM) && i < 1 && IS_WHITESPACE(ch)) + continue; + if((mode & K_NOSPACE) && IS_WHITESPACE(ch)) + continue; if(ch==CIO_KEY_MOUSE) { ch=uifc_getmouse(&mevnt); if(ch==0 || (ch==ESC && mevnt.event==CIOLIB_BUTTON_3_CLICK)) { @@ -2476,7 +2480,6 @@ int ugetstr(int left, int top, int width, char *outstr, int max, long mode, int str[j]=0; if(mode&K_EDIT) { - truncspctrl(str); if(!(mode&K_FIND) && strcmp(outstr,str)) api->changes=1; } @@ -2485,6 +2488,8 @@ int ugetstr(int left, int top, int width, char *outstr, int max, long mode, int if(!(mode&K_FIND) && j) api->changes=1; } + if(mode & K_TRIM) + truncspctrl(str); strcpy(outstr,str); cursor=_NOCURSOR; _setcursortype(cursor); -- GitLab