! gettext.tes - Macro to collect a text string This macro assumes that a text window has been setup with a prompt in it. this will preserve the state of ET and all Q-Registers that it uses. We also assume that the pointer is positioned after the prompt and that no text follows the pointer. Data entry accepts all characters except Ctrl-Enter or the specified delimiter which terminates data entry. Arrow keys (Left and Right) as well as Home, End and Delete are functional. When complete we position the pointer after the end of the entered text and return in "current number" the -length of text entered which is also in ^S. Also note that entry of Return implies entry of LineFeed. However if Return is the delimiter then Return/LineFeed will NOT be entered into the buffer. Call: :EIgettext$ (gets text up to Ctrl-Enter) or n:EIgettext$ (gets text up to char whose value is n or Ctrl-Enter) e.g 13:EIgettext$ would get text up to Return (Enter) or Ctrl-Enter.! !gettext.tec! [X [1 [2 [C [T ! save Q-registers that we will use ! +0UX ! Exit character value to X.num (nothing=0) ! ET+( ! get current value of ET and push onto stack ! ! Note, this pushes only number where as [q ! ! pushes Q-reg num and text ! 0,8ET ! echo off ! .U1 ! pointer to the front of the entered text ! .U2 ! pointer to the back of the entered text ! ::CUC ! calculate and save the current column # ! < ! loop ! W ! refresh the screen ! ^TUT ! get a char, place code in T.num ! QT"E ! if char is 0 then it is a function/arrow ! ::^T/256&255UT ! re-read full scan code, get 2nd byte into T ! QT-75"E ! if Left Arrow ! .-Q1"G R ' ! iif after starting position, backup ! ::CUC ! read current column insert in C.num ! F< ! continue ! ' ! endif Left Arrow ! QT-77"E ! if Right Arrow ! .-Q2"L C ' ! iif before last character, advance ! ::CUC ! read current column insert in C.num ! F< ! continue ! ' ! endif Right Arrow ! QT-83"E ! if Delete ! .-Q2"N ! if in front of last character entered ! D ! delete next char ! -1%2$ ! decriment last char entered position ! ' ! endif in front of last character entered ! F< ! continue ! ' ! endif Delete ! QT-71"E ! if Home ! Q1J ! jump to starting position ! ::CUC ! read current column insert in C.num ! F< ! continue ! ' ! end if Home ! QT-79"E ! if End ! Q2J ! jump to ending position ! ::CUC ! read current column insert in C.num ! F< ! continue ! ' ! endif End ! ' ! endif function/arrow key ! QT-QX"E 0; ' ! iif Exit character exit loop ! QT-127"E ! if Rubout ! .-Q1"G ! if to right of first character ! -D ! delete character to left ! -1%2$ ! decriment right limit, throw out result ! ' ! endif to right of first character ! ::CUC ! read current column insert in C.num ! F< ! continue ! ' ! endif Rubout ! QT-21"E ! if ^U (Ctrl-U) ! Q1,Q2K ! kill all that had been entered ! Q1U2 ! reset ending position ! ::CUC ! read current column insert in C.num ! F< ! continue ! ' ! endif ^U ! QT-13"E ! if Enter ! ^O ! set octal radix ! ::^T&3000000"N ! if scan code says left or right Ctrl ! ^D ! set decimal radix ! 0; ! exit loop ! ' ! endif scan code says left or right Ctrl ! ^D ! set decimal radix ! ' ! endif Enter ! QT@I%% ! none of the above, insert the character ! %2$ ! incriment the right most limit ! QT-13"E ! if character was ! 10@I%% ! insert ! %2$ ! incriment right most limit ! ' ! endif character was ! ::CUC ! read curretn column insert in C.num ! > ! end loop ! ! Note, we are still in the expression ET+( let's set expression inside ! ! the ( ) to 0 so we end up with ET+(0)ET so we can restore ET mode ! 0) ET ! ET restored ! Q1,Q2XT ! collect text entered (even collect NULL) ! ZJ ! go to end of buffer ! GT ! get the text entered. this sets into ^S the ! ! -length of last "insert" for use by caller ! ^SD ! delete the text (^S length is set) ! Q2J ! return the pointer at end of text entered ! ]T ]C ]2 ]1 ]X ! restore Q-Registers to their original state ! ^S ! exit with -length of insert !