Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 18:36 10 May 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Line Editor question (obsolete statement, workaround?)

Author Message
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 529
Posted: 01:05pm 01 Apr 2025
Copy link to clipboard 
Print this post

Hello,

I found a really good program / function that fits my needs, but it uses an obsolete font statement:



Example1()

'
' Edit a string until ENTER with LineEdit:
'
Sub Example1
 a$ = "text to edit"
 Do: k = LineEdit(a$): Loop Until k = 13 ' until ENTER
End Sub

' LineEdit(a$, [cur [, key [, max [, win ]]]]) edit string a$ at position cur,
' use key parameter (when provided) to make the next edit of a$ and update cur, and
' return new key press, or if key press not provided (zero) keep editing until
' ESC, ENTER or special key such as F1, UP/DOWN etc. where max is the maximum
' string length and win is the "window" size. Use LEFT/RIGHT/HOME/END to
' navigate the line, BACKSPACE/DEL to delete a character.
'
' Supports three editing modes: key=0 (default) edit until ENTER or other
' special key, key=-1 wait for key and make one edit, returning the key value,
' key=X to pass a key press to LineEdit to make one edit, returning the key
' value.
'
' Curser position cur parameter is passed in and updated by LineEdit
'
' Use the max parameter when the string has a maximum length smaller than 255
'
' To edit within a smaller window, use the win parameter
'
Function LineEdit(a$, cur, key, max, win)
 Local x, y, size, from, done
 x = MM.HPos: y = MM.VPos
 If max <= 0 Then max = 255
 If win <= 0 Then win = 255
 size = Len(a$)
 If cur < 0 Then
   cur = 0
 ElseIf cur > size Then
   cur = size
 EndIf
 done = key
 Do
   If key >= 32 And key < 127 Then
     If size < max Then
       a$ = Left$(a$, cur) + Chr$(key) + Mid$(a$, cur + 1)
       cur = cur + 1
       size = size + 1
     EndIf
   ElseIf key = 8 Then
     If cur > 0 Then
       cur = cur - 1
       a$ = Left$(a$, cur) + Mid$(a$, cur + 2)
       size = size - 1
     EndIf
   ElseIf key = 127 Then
     If cur < size Then
       a$ = Left$(a$, cur) + Mid$(a$, cur + 2)
       size = size - 1
     EndIf
   ElseIf key = 130 Then
     If cur > 0 Then cur = cur - 1
   ElseIf key = 131 Then
     If cur < size Then cur = cur + 1
   ElseIf key = 134 Then
     cur = 0
   ElseIf key = 135 Then
     cur = size
   ElseIf key > 0 Then
     ' done editing, so print a clean line
     Print @(x,y) Left$(a$, win);
     ' remove the cursor from the end of the line
     If cur = size And size < win Then Print " ";
     Exit
   EndIf
   ' cursor cannot move beyond string max length
   If cur >= max Then cur = max - 1
   ' cursor is offset from window start
   If cur >= win Then from = cur - win + 2 Else from = 1
   If cur = size Then
     ' print the line constrained to the window size
     Print @(x,y) Mid$(a$, from);
     ' put the cursor at the end
     Font 1,,1: Print " ";: Font 1,,0
     ' BACKSPACE may require removing the cursor from the end of the line
     If key = 8 Then
       If cur + 1 < win And size < win Then Print " ";
     EndIf
   Else
     ' print the line constrained to window size
     Print @(x,y) Mid$(a$, from, cur - from + 1);
     ' invert character at the cursor
     Font 1,,1: Print Mid$(a$, cur + 1, 1);: Font 1,,0
     ' print the rest of the line
     Print Mid$(a$, cur + 2, win - cur + from - 2);
     If cur < win And size < win Then Print " ";
   EndIf
   ' if this is a non-blocking call then exit
   If done > 0 Then Exit
   ' wait on key press
   Do: key = Asc(Inkey$): Loop Until key
   done = -done
 Loop
 ' move cursor back to the start of the line before returning
 Print @(x,y);
 LineEdit = key
End Function



It is a program to edit lines found on the FOTS. I managed to get it working with replacing all

font 1,,1

and

font 1,,0


with (both)

font 1,1


Problem now is, of course, it doesn't invert the character anymore. I took a look at the manual and searched for "cursor" and "invert" also for the font statement - no luck to find what the previous (obsolete code) really did.

Maybe this is a quick one for you, but I have no idea how to do this.

Greetings
Daniel
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1526
Posted: 01:15pm 01 Apr 2025
Copy link to clipboard 
Print this post

Hi Daniel,
I can only recommend you try the "InputE" routine from the Javavi File Manager (my version).

Kind regards
Michael

Features:
- You can use it to process a predefined string, or no string at all.

- You can specify the maximum length.

- You can abort with ESC.

- You can switch to overwrite mode.

- For example, you can only allow numbers as input.

The default program is for HDMI in Mode 1. I haven't tested any others yet. There's a VT100 version in the FMVT100 thread.


My old LineEdit looked like this, based on my version for Maximites.

BTW: Check out the Print @() function for inverting characters!

The @(x,y) function will automatically suppress the automatic line wrap
normally performed when the cursor goes beyond the right screen margin.
If 'm' is specified the mode of the video operation will be as follows:
m = 0 Normal text (white letters, black background)
m = 1 The background will not be drawn (ie, transparent)
m = 2 The video will be inverted (black letters, white background)
m = 5 Current pixels will be inverted (transparent background)

Edited 2025-04-01 23:31 by twofingers
causality ≠ correlation ≠ coincidence
 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 529
Posted: 01:42pm 01 Apr 2025
Copy link to clipboard 
Print this post

Hello Michael,

I took a look at your suggested version of the File Manager, but I am completely lost to reverse engineer this code at my level of experience to just take out the snippet I need.

But thank you for the hint with the Print @() function ! I will take a look at this :)

Greetings
Daniel
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1526
Posted: 01:48pm 01 Apr 2025
Copy link to clipboard 
Print this post

  Amnesie said   to just take out the snippet I need.


Would that help?

On error skip'
If Bound(C(),1)<>15 Then
 Dim integer c(15)=(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
 Colour Map c(),c()
EndIf
Print inputE$("Test",10)
End

'INPUT+ESCape-------- NEW --------------
Function InputE$(inString$,maxLen,ovrOn,N_only)
Local s$=inString$,k$ length 1
Local gk,delflg,tLen=Len(s$),x=MM.Info(hPos),y=MM.Info(vPos)
Local cPos=tLen,bc=MM.Info(BCOLOUR)
Local cSet(1,1)=(32,127,48,58)
Do
 Print @(x,y);Left$(s$,cPos);
 Color c(0),c(15-ovrOn*5)
 Print Mid$(s$,cPos+1,1);
 Color c(15),bc
 Print Mid$(s$,cPos+2);
 If cpos>=tLen Then Color c(0),c(15-ovrOn*5)
 Print " ";
 Color c(15),bc
 If delflg Then Print " ";:delflg=0
 gk=getkey()
 k$=Chr$(gk)
 If gk=13  Then Exit Do
 If gk=27  Then InputE$=inString$:maxLen=-1:Exit Function
 If gk=130 And  cPos >0 Then Inc cPos,-1
 If gk=131 And  cPos <tLen Then Inc cPos
 If gk=132 Then ovrOn=ovrOn=0
 If gk=134 Then cPos =0 'HOME
 If gk=135 Then cPos =tLen 'END
 If gk=127 And cPos<tLen Then
   s$=Left$(s$,cPos) +Mid$(s$,cPos+2)
   Inc tLen,-1:delflg=1
 EndIf
 If gk=8 And tLen>0 And cPos>0 Then
   s$=Left$(s$,cPos -1) +Mid$(s$,cPos+1)
   Inc cPos,-1:Inc tLen,-1:delflg=1
 EndIf
 If gk>=cSet(0,N_only) And gk<cSet(1,N_only) Then
   If cPos<tLen And ovrOn Then
     s$=Left$(s$,cPos) +k$ +Mid$(s$,cPos+2)
     Inc cPos
   ElseIf tLen<maxLen Then
     s$=Left$(s$,cPos) +k$ +Mid$(s$,cPos+1)
     Inc cPos:Inc tLen
   EndIf
 EndIf
Loop
InputE$=s$
Color c(15),bc
Print @(x,y);
End Function


I should probably mention that there are two versions of the InputE routine. My version of the FM contains a completely new development, and I've only kept the function name to make it easier to integrate into the FM.



Only the first parameter is not optional.
A simple call could therefore look like this:

Print inputE$("Test")
or something like this
Print inputE$("",10)

Edited 2025-04-02 00:07 by twofingers
causality ≠ correlation ≠ coincidence
 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 529
Posted: 02:04pm 01 Apr 2025
Copy link to clipboard 
Print this post

  twofingers said  
  Amnesie said   to just take out the snippet I need.


Would that help?



Sadly not, it don't know how to use this function. in the "LineEdit" example it is easy, just go to the example sub and it works. Do I need to define some global variables first and create some Do Until Loop?

Argh..  


Ah I see you updated the code, I try it again.

Greetings
Daniel
Edited 2025-04-02 00:06 by Amnesie
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1526
Posted: 02:11pm 01 Apr 2025
Copy link to clipboard 
Print this post

The code is actually designed for use in the FM. But it can easily be adapted to run autonomously.

Perhaps a candidate for FOTs?
causality ≠ correlation ≠ coincidence
 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 529
Posted: 02:14pm 01 Apr 2025
Copy link to clipboard 
Print this post

If I run the above code there is an error:


[18] gk=getkey()
Error: Dimensions

Yes I think it would be very usefull, since the normal Input is really limited...  

Greetings
Daniel
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1526
Posted: 02:18pm 01 Apr 2025
Copy link to clipboard 
Print this post

  Amnesie said  If I run the above code there is an error:


[18] gk=getkey()
Error: Dimensions


This should be enough for your purposes:

Function getKey(msg$) As integer
 Do :getKey=Asc(Inkey$):Loop While getKey=0
End Function

causality ≠ correlation ≠ coincidence
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1526
Posted: 02:21pm 01 Apr 2025
Copy link to clipboard 
Print this post

I will probably make a zip package with this function once everything is clarified.
causality ≠ correlation ≠ coincidence
 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 529
Posted: 02:22pm 01 Apr 2025
Copy link to clipboard 
Print this post

HA!!!    

Now it works! This is exactly what I was looking for! Isn't this a good idea to hardcode into MMBASIC, I mean it handles extensive string modification, but is lacking Input processing. Just a thought. I know I know.. where is the fun, if everything is there by "default". Peter & Geoff did such an amazing job, don't get me wrong - was just a thought. I think there is a good reason why MMBASIC can't do such things by default. Whatever, thank you Michael! Now I can analyze your code to get an deeper understanding.

Greetings
Daniel
Edited 2025-04-02 00:31 by Amnesie
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1526
Posted: 02:46pm 01 Apr 2025
Copy link to clipboard 
Print this post

  Amnesie said  ... Just a thought. I know I know.. where is the fun, if everything is there by "default". ...

That's my opinion too. It's already too much...

One more tip: if you want to determine whether the test was aborted with ESC, you should enter the maximum length (ml) as a variable:
ml = 10
? InputE("Test",ml)
...
if ml=-1 then ? "Abort with ESC!"

If InputE is aborted with ESC, ml is set to -1.
Edited 2025-04-02 00:48 by twofingers
causality ≠ correlation ≠ coincidence
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1526
Posted: 09:59am 08 Apr 2025
Copy link to clipboard 
Print this post

Hi Daniel,

as promised, here are three more versions in a package.
INPUT_A.BAS is a revised version of the one described above for VGA/HDMI.

INPUT_B.BAS is an enhanced version for VGA/HDMI. The blinking cursor is new.
I haven't decided yet which is better.

INPUT_VT.BAS is for VT100 terminals.
I haven't yet integrated the option to enter only numbers here. This version is intended for programs in bare Pico moduls.

It was tested with PicoMites 2350 (Pico 2). Timing adjustments may be necessary for Pico 1 (blinking frequency). A small demo program is included.

Inpute.zip

The routine is actually a contribution to the File Manager (Javavis FM).
You are welcome to upload the package to FOTS.

Regards
Michael
causality ≠ correlation ≠ coincidence
 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 529
Posted: 11:02am 08 Apr 2025
Copy link to clipboard 
Print this post

Michael,

thank you a lot. I will have a look when I am home.
Greetings
Daniel
Edited 2025-04-15 07:13 by Amnesie
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025