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)
DependanciesExample UsageMyDT$=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