mmbasic:string_editing_on_screen_for_vt_compatible_terminals
Table of Contents
String editing on-screen for VT compatible Terminals
StrEdit$() allows the user to edit (or enter - start with “”) a string at a given position in a terminal window and constrained to a specified length. It is a more intelligent version of Input in that it performs the same function but is non-blocking (with
Input
, your program loses control while it waits for the user), limits the amount of data, provides nice editing and nice displays reminiscent of the 80s & 90s terminal based input.
Your terminal emulator must be VT compliant to understand the ANSI codes (I use PuTTY)
Dependancies
- Option Base 0
- LTrim and RTrim Functions (VB work-a-like) or the equivalent LTrim RTrim CFunctions (note this latter does not treat TABs as white-space and so are not trimmed).
Example Usage
MyDT$=StrEdit$(MyDT$,10,10,8)
'Edit the string at the position given limited to q characters long Function StrEdit$(l$,h As Integer,v As Integer,q As Integer) Local x$,a$ a$=RTrim$(Left$(l$,q)) SStr a$,h,v Do Do:x$=VTKey$():Loop Until x$<>"" If Len(x$)=1 Then Select Case Asc(x$) Case 32 To 126 If Len(a$)<q Then a$=a$+x$:SStr a$,h,v Case 127,8 If Len(a$) Then a$=Left$(a$,Len(a$)-1):SStr a$,h,v EndIf Case 13 StrEdit$=a$:Exit Function Case Else 'ignore End Select Else If x$="_DL" Then If Len(a$) Then a$=Left$(a$,Len(a$)-1):SStr a$,h,v EndIf EndIf EndIf Loop End Function Sub SStr(a$,h As Integer, v As Integer)' support Sub for StrEdit$() Print At(h,v);a$;" ";:Print At(h,v);a$; End Sub
mmbasic/string_editing_on_screen_for_vt_compatible_terminals.txt · Last modified: 2024/05/25 17:45 by gerry