Author Topic: Line Editor  (Read 4428 times)

0 Members and 1 Guest are viewing this topic.

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Line Editor
« on: February 08, 2021, 01:01:11 am »

What I got so far

There are bugs for sure.   Basic line editor with APPEND, INSERT, DELETE and BACKSPACE

Have to add Backspace yet.   

Code: QB64: [Select]
  1. _TITLE " LINE EDITOR   Press ESC to exit"
  2.  
  3. DIM oldcp AS INTEGER
  4.  
  5.  
  6. oldcp = 25
  7. cp = 25
  8. LOCATE 26, cp, 1, 31, 31
  9.  
  10.     DO
  11.         kh& = _KEYHIT
  12.  
  13.         IF kh& > 0 THEN EXIT DO
  14.  
  15.     LOOP
  16.  
  17.     ' PRINT kh
  18.     ' END
  19.  
  20.     IF kh = 27 THEN EXIT DO
  21.  
  22.     IF kh < 256 AND cp - oldcp = LEN(t) THEN 'APPEND
  23.         t = t + CHR$(kh)
  24.         LOCATE 26, 25: PRINT t
  25.         cp = cp + 1
  26.         LOCATE 26, cp, 1, 31, 31
  27.     END IF
  28.  
  29.     IF kh < 256 AND cp - oldcp < LEN(t) THEN 'INSERT
  30.         t = LEFT$(t, cp - oldcp) + CHR$(kh) + RIGHT$(t, (LEN(t) - (cp - oldcp)))
  31.         LOCATE 26, 25: PRINT t; "                                    "
  32.         cp = cp + 1
  33.         LOCATE 26, cp, 1, 31, 31
  34.     END IF
  35.  
  36.     IF kh = 21248 THEN 'DELETE
  37.         t = LEFT$(t, cp - oldcp) + RIGHT$(t, (LEN(t) - (cp - oldcp)) - 1)
  38.         LOCATE 26, 25: PRINT t; "                                    "
  39.         LOCATE 26, cp, 1, 31, 31
  40.     END IF
  41.  
  42.     'left arrow
  43.     IF kh = 19200 AND cp > oldcp THEN
  44.         cp = cp - 1
  45.         LOCATE 26, cp, 1, 31, 31
  46.     END IF
  47.  
  48.     'right arrow
  49.     IF kh = 19712 AND cp - oldcp < LEN(t) THEN
  50.         cp = cp + 1
  51.         LOCATE 26, cp, 1, 31, 31
  52.     END IF
  53.  
  54.  
« Last Edit: February 08, 2021, 01:36:01 am by NOVARSEG »

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Line Editor
« Reply #1 on: February 08, 2021, 02:18:05 am »
Added Home, Back space,  End

Code: QB64: [Select]
  1. _TITLE " LINE EDITOR    Press ESC to exit"
  2.  
  3.  
  4. DIM oldcp AS INTEGER
  5.  
  6.  
  7. oldcp = 25
  8. cp = 25
  9. LOCATE 26, cp, 1, 0, 3
  10.  
  11.     DO
  12.         _LIMIT 100
  13.         kh& = _KEYHIT
  14.  
  15.         IF kh& > 0 THEN EXIT DO
  16.  
  17.     LOOP
  18.  
  19.     'PRINT kh
  20.     'END
  21.  
  22.     IF kh = 27 THEN EXIT DO
  23.  
  24.     IF kh = 8 AND cp > oldcp THEN 'BACKSPACE
  25.         cp = cp - 1
  26.         t = LEFT$(t, cp - oldcp) + RIGHT$(t, (LEN(t) - (cp - oldcp)) - 1)
  27.         LOCATE 26, 25: PRINT t; " "
  28.         LOCATE 26, cp, 1, 31, 31
  29.         GOTO LL1
  30.     END IF
  31.  
  32.     IF kh = 8 AND cp = oldcp THEN GOTO LL1 ' To avoid inserting or appending the back space character
  33.  
  34.  
  35.     IF kh < 256 AND cp - oldcp = LEN(t) THEN 'APPEND
  36.         t = t + CHR$(kh)
  37.         LOCATE 26, 25: PRINT t
  38.         cp = cp + 1
  39.         LOCATE 26, cp, 1, 31, 31
  40.     END IF
  41.  
  42.     IF kh < 256 AND cp - oldcp < LEN(t) THEN 'INSERT
  43.         t = LEFT$(t, cp - oldcp) + CHR$(kh) + RIGHT$(t, (LEN(t) - (cp - oldcp)))
  44.         LOCATE 26, 25: PRINT t
  45.         cp = cp + 1
  46.         LOCATE 26, cp, 1, 31, 31
  47.     END IF
  48.  
  49.     LL1:
  50.  
  51.     IF kh = 21248 THEN 'DELETE
  52.         t = LEFT$(t, cp - oldcp) + RIGHT$(t, (LEN(t) - (cp - oldcp)) - 1)
  53.         LOCATE 26, 25: PRINT t; " "
  54.         LOCATE 26, cp, 1, 31, 31
  55.     END IF
  56.  
  57.  
  58.     IF kh = 20224 THEN 'END
  59.         LOCATE 26, 25: PRINT t
  60.         cp = LEN(t) + oldcp
  61.         LOCATE 26, cp, 1, 31, 31
  62.     END IF
  63.  
  64.     IF kh = 18176 THEN 'HOME
  65.         LOCATE 26, 25: PRINT t
  66.         cp = oldcp
  67.         LOCATE 26, cp, 1, 31, 31
  68.     END IF
  69.  
  70.     'left arrow
  71.     IF kh = 19200 AND cp > oldcp THEN
  72.         cp = cp - 1
  73.         LOCATE 26, cp, 1, 31, 31
  74.     END IF
  75.  
  76.     'right arrow
  77.     IF kh = 19712 AND cp - oldcp < LEN(t) THEN
  78.         cp = cp + 1
  79.         LOCATE 26, cp, 1, 31, 31
  80.     END IF
  81.  
  82.  
  83.  
« Last Edit: February 08, 2021, 02:19:40 am by NOVARSEG »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Line Editor
« Reply #2 on: February 08, 2021, 12:04:44 pm »
Your on you way to remaking GW Basic :)

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Line Editor
« Reply #3 on: February 08, 2021, 01:15:01 pm »
LOL


Trying to get it to work in other screen modes.


« Last Edit: February 08, 2021, 01:17:42 pm by NOVARSEG »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Line Editor
« Reply #4 on: February 08, 2021, 01:34:28 pm »
LOL


Trying to get it to work in other screen modes.

I have that, Steve just posted one, I think (ExtendedInput Sub or Function)?

I'd show mine if you want but more fun to struggle with it yourself, good practice.

In other screens all you have to watch is Locate, it throws error if not inside screen, 2nd problem screen starts scrolling past Printing 2 lines before bottom unless you use Print with ;

Then there are the problems of the line going past the width of screen.

(Just ran your code) Oh man don't test this in full screen until works in regular one is my suggestion.
Hey I thought you were trying SCREEN _NEWIMAGE(yourWidth, yourHeight, 32)?
I don't think the cursor thing is going to work outside SCREEN 0 but I never tried. You could draw a cursor and blink it with graphics if extended LOCATE doesn't work.
« Last Edit: February 08, 2021, 01:46:50 pm by bplus »

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Line Editor
« Reply #5 on: February 08, 2021, 05:35:14 pm »
Ok need a font library that can work with a cursor.  The font position and cursor position are independent. Maybe something that duplicates what text mode already has and then scale the size

Did you run the latest code?
« Last Edit: February 08, 2021, 05:52:32 pm by NOVARSEG »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Line Editor
« Reply #6 on: February 08, 2021, 06:00:56 pm »
Yes I ran code of Screen 0 in _FULLSCREEN mode.

For Fonts can you do Fonts in Screen 0?  I never tried, maybe through a _Newimage trick.

Screens from _NewImage provide way more flexibility.



Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Line Editor
« Reply #7 on: February 08, 2021, 08:16:06 pm »
Just to give you a heads up, when you get to all the bells and whistles, you are looking at a few thousand lines of code. If you are thinking about going the wp route with a working GUI, it's around 6000+. It's fun stuff, but quite a commitment if you have other projects you want to get to.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Line Editor
« Reply #8 on: February 08, 2021, 08:17:12 pm »
Yes I ran code of Screen 0 in _FULLSCREEN mode.

For Fonts can you do Fonts in Screen 0?  I never tried, maybe through a _Newimage trick.

Screens from _NewImage provide way more flexibility.

Fonts work in Screen 0, as long as they’re monospaced.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Line Editor
« Reply #9 on: February 08, 2021, 09:45:41 pm »
Thanks but if something is good enough for fonts, I would likely want more flexibility than Screen 0.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Line Editor
« Reply #10 on: February 09, 2021, 12:17:44 am »
More flexibility than SCREEN 0? For what? So you can bend over and kiss your ascii goodbye?

Pete

SCREEN 0, because anything else is just a waste of good pixels.
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Line Editor
« Reply #11 on: February 09, 2021, 02:22:27 am »
Working on a calculator that calculates mortgages etc anyone interested?

HaH you say  - what about the online ones???

Good point :)

114 lines of code so far

FULLSCREEN is nice but how do you minimize it?. It takes up the WHOLE screen.  It would be nice to have a say, 1024 * 768 pixel screen with big font.   Is there a universal screen that does everything? without 6000 lines of code


« Last Edit: February 09, 2021, 02:38:56 am by NOVARSEG »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Line Editor
« Reply #12 on: February 09, 2021, 10:32:20 am »
You need to learn the _FONT command.

SCREEN _NEWIMAGE(1024, 768, 32)
_FONT _LOADFONT(“courbd.ttf”, 48, “monospace”
PRINT “Hello World”
SLEEP
SYSTEM
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Line Editor
« Reply #13 on: February 09, 2021, 02:08:58 pm »
When I was 18, I went to bankers, to find out how amortization was calculated. Every loan officer I spoke with had the same answer, we look in this book. Frustrated with these replies, I went home, and started fiddling around with various methods to make a formula to calculate amortization. I had success using geometric progressions. I used the same technique two years later, when I got my T.I. 4A computer. It was correct within one or two pennies of "The Book." That was fun. I might have something similar on some old stored hard drive from a ghosted  computer, but these days, I would suspect you can search that algorithm online... unless it returns Buy this book now at ScAmazon.con. 

Good luck with it, and you might want to search "calculator" for some ideas already posted to these forums.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Line Editor
« Reply #14 on: February 09, 2021, 02:29:42 pm »
I just looked up the forumla:
Quote
A=P * (  i(1+i)^n) / ((1+i)^n-1)  )
A   =   periodic payment amount
P   =   amount of principal, net of initial payments
i   =   periodic interest rate
n   =   total number of payments

Look OK?

« Last Edit: February 09, 2021, 02:34:30 pm by bplus »