Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Basic Editor for 300 LOC or so?
#1
Where did I get the idea I could build one for 300 LOC?

I am at 617 LOC and haven't finished Cut/Copy/Paste yet but 3 Color Themes I have already:
Forest
   

Patriot
   

Orange (No Blue!)
   

Ha! gotta get those colors first thing! But also font that is a size easy on eyes. Thanks to Terry for Lucon 18 pixel hieght Mono, my eyes are loving it both in IDE and this Editor (for programs not Word Wrap), Forest is my choice, Orange / No Blue gave me a headache!

So Dav's is OK at 891 LOC plenty of instructions, you can figure it out if you're willing to put up with all that tight packing into a "Pete" Screen Smile
   
You can toggle with Enter key between a Hex thing and a more normal thing.

And we've already commented on Eric's growing monster ;-))

I think I saw one (Editor at 300 LOC) back in mid 90's, Dr Dobbs Journal?, I think.
https://en.wikipedia.org/wiki/Dr._Dobb%27s_Journal
One of those jobs you type from a paper or magazine.
I think I saw one in there for QB, haven't been able to dig it up or anything close to it.

I might have mentioned this before, sure would like to see that code again!

Anyone got anything close to bare bones editor only a few c's of lines ?
b = b + ...
Reply
#2
Does it allow for using the mouse or is everything controlled by the keyboard?
Tread on those who tread on you

Reply
#3
(11-20-2023, 03:29 PM)SpriggsySpriggs Wrote: Does it allow for using the mouse or is everything controlled by the keyboard?

99% most likely no mouse, I remember I had to get a book with Mouse subs (Interrupts) to get mouse functions in my Basic. Did QB4.5 have them? Maybe with some Interrupt / Registers routines.

Mouse will definitely add to LOC, so I'd say no. Plus you probably had to type in Input line your filename to save or load. The journal was only a couple of pages, I don't think they did installments?

I am thinking no Cut/Copy/Paste because highlighting and getting that working really adds to code lines.
Pete had something working pretty well with that but tons of lines!

BTW Aurel informed me that Windows API has 2 Editor Controls! @SpriggsySpriggs have you checked out GUI possibilties through Windows API?
b = b + ...
Reply
#4
Yep. You can definitely do text boxes in Win32. I know how to do it. It's just a pain in the ass. My test Win32 program works in Linux so I might be able to do something.

   
Tread on those who tread on you

Reply
#5
(11-19-2023, 09:04 PM)bplus Wrote: Anyone got anything close to bare bones editor only a few c's of lines ?
How about this?  Based on an old FreeBasic editor I found a while back.  It used linked lists, had a few issues.
I converted it to QB64, used an array of strings instead of the linked list, fixed a few bugs, probably added a few more.  Available commands are in the main sub below.  
Very bare bones! But less than 200 lines, and pretty easy to follow
Does not currently handle horizontal scrolling.

Code: (Select All)
option _explicit

declare function down&
declare function up&
declare function pgdn&
declare function pgup&
declare function cmleft&
declare function cmright&

const c_nlines = 5000, true = -1, false = 0
redim shared linelist(1 to c_nlines) as string

dim shared as long curline, numlines, cx, cy, sy, rows, cols, junk
numlines = 0: cx = 0: cy = 0: sy = 0

rows = _height: cols = _width
rows = rows - 1      ' allow one for a status line

loadfile command$
locate , , 0
main
locate rows + 1, 1, 1
end

sub main
    dim thekey as string
    dim refresh as integer

    redraw
    do
        refresh = true
        thekey = inkey$

        select case thekey
            case chr$(0)+"P":          junk = down
            case chr$(0)+"H":          junk = up
            case chr$(0)+"M":          junk = cmright
            case chr$(0)+"K":          junk = cmleft
            case chr$(0)+"Q":          junk = pgdn
            case chr$(0)+"I":          junk = pgup
            case chr$(0)+"G":          cx = 0                      'home
            case chr$(0)+"O":          cx = len(linelist(curline)) 'end
            case chr$(0)+chr$(118):    while pgdn: wend      'ctrl-pgdn
            case chr$(0)+chr$(132):    while pgup: wend      'ctrl-pgup
            case chr$(13):              enter
            case chr$(8):              backspace
            case chr$(0)+"S":          cdelete
            case chr$(32) to chr$(128): selfinsert thekey
            case else: refresh = false
        end select
        if refresh then redraw
    loop until thekey = chr$(27)
end sub

sub loadfile(f as string)
    linelist(1) = ""
    curline = 1
    if not _fileexists(f) then numlines = 1: exit sub
    open f for input as #1
    do
        numlines = numlines + 1
        if numlines > ubound(linelist) then redim _preserve linelist(ubound(linelist) + c_nlines)
        line input #1, linelist(numlines)
    loop until eof(1)
    close
end sub

function down&
    if curline >= numlines then down = false: exit function
    if cy = rows - 1 then sy = sy + 1 else cy = cy + 1
    curline = curline + 1
    if len(linelist(curline)) < cx then cx = len(linelist(curline))
    down = true
end function

function up&
    if curline <= 1 then up = false: exit function
    if cy = 0 then sy = sy - 1 else cy = cy - 1
    curline = curline - 1
    if len(linelist(curline)) < cx then cx = len(linelist(curline))
    up = true
end function

function cmleft&
    if cx = 0 then
        if curline <= 1 then cmleft = false: exit function
        junk = up: cx = len(linelist(curline))
    else
        cx = cx - 1
    end if
    cmleft = true
end function

function cmright&
    if cx = len(linelist(curline)) then
        if curline >= numlines then cmright = false: exit function
        junk = down: cx = 0
    else
        cx = cx + 1
    end if
    cmright = true
end function

function pgdn&
    dim i as long
    if curline >= numlines then pgdn = false: exit function
    for i = 1 to rows - 1
        if not down then exit for
    next
    pgdn = true
end function

function pgup&
    dim i as long
    if curline <= 1 then pgup = false: exit function
    for i = 1 to rows - 1
        if not up then exit for
    next
    pgup = true
end function

sub enter
    dim as long n
    dim as string s

    numlines = numlines + 1
    if numlines > ubound(linelist) then redim _preserve linelist(ubound(linelist) + c_nlines)
    s = mid$(linelist(curline), cx + 1)
    linelist(curline) = left$(linelist(curline), cx)
    ' move everything after curline down one
    for n = numlines to curline + 1 step -1
        linelist(n) = linelist(n - 1)
    next n
    curline = curline + 1
    linelist(curline) = s
    if cy = rows - 1 then sy = sy + 1 else cy = cy + 1
    cx = 0
end sub

sub backspace
    dim as long line_len, n
    if cx = 0 then
        if curline <= 1 then exit sub
        line_len = len(linelist(curline - 1))
        linelist(curline - 1) = linelist(curline - 1) + linelist(curline)
        ' move everything after curline up one
        for n = curline to numlines - 1
            linelist(n) = linelist(n + 1)
        next n
        numlines = numlines - 1
        cx = line_len
        if cy = 0 then sy = sy - 1 else cy = cy - 1
        curline = curline - 1
    else
        linelist(curline) = left$(linelist(curline), cx - 1) + mid$(linelist(curline), cx + 1)
        cx = cx - 1
    end if
end sub

sub cdelete
    if cx = len(linelist(curline)) then if curline >= numlines then exit sub
    junk = cmright
    backspace
end sub

sub selfinsert(thekey as string)
    linelist(curline) = left$(linelist(curline), cx) + thekey + mid$(linelist(curline), cx + 1)
    cx = cx + 1
end sub

sub redraw
    dim as long y, n

    cls
    n = curline - cy
    if n < 1 then n = 1

    for y = 1 to rows
        locate y, 1
        ? left$(linelist(n), cols);
        if n = numlines then exit for
        n = n + 1
    next

    locate cy + 1, cx + 1
    color 0, 7
    ? chr$(screen(cy + 1, cx + 1));

    locate rows + 1, 1
    ? "Line: "; cy + sy + 1; " of "; numlines; " Col: "; cx + 1;

    color 7, 0
end sub
Reply
#6
Thumbs Up 
That's just the Bare Bones kind of thing I think I saw way back... thankyou Ed. That is under 200 LOC if you remove the unnecessary Declares.

I remember starting with similar and adding on... and on...

I am just over 600 with mouser functions. Just cleared a hurdle of selecting text with mousebutton(1) dragging.
I had arrows or scrolling selecting with Shift but had hell of time doing MouseDown like QB64 IDE does (which is my model I wish to duplicate).

hmm Locate with 3 arguments? gotta look into that. > It's for cursor on/off
b = b + ...
Reply
#7
Might have to redo this in Python if we expect to do a decent text editor in under 600 lines of code. LOL.

Otherwise don't expect anything fancier than "Wizedit", one of the first text editors I've ever witnessed. Raw stuff, hard to believe Nano on Linux is more featured. Also the editor I discovered in one of the old Central Point or McAfee suites for 16-bit computers long ago. For this one, press [ESC] to get a chance to save the document and leave the program. No mouse support in any of those two MS-DOS programs.

These days how kids expect spell-checking in a "simple" code editor... you have to take a look at how Vim has grown.

Earlier this year I played with a text editor called Liritext. It did not allow configuration, just provided a dorky graphics window using a font which was not monospaced. The inability to change the font is a no-go for anything that doesn't act like a full-featured word processor. I wanted to keep this Liritext but it was just too simple for my purposes. :/

Oh yeah and the "sliding" animations that seem to be everywhere, try replicating that on Pete's screen. I'm glad it cannot be! At least in one place I could be succorred from something that has been driving me up the wall about Linux desktop environments!
Reply
#8
I can do this in just 1 line of code.  You guys are overthinking the issue:

Code: (Select All)
SHELL "notepad.exe"
Reply
#9
Smile actually Shell QB64pe.exe might get us closer.
b = b + ...
Reply
#10
With left mouse click a popup menu just like in QB64:
   

Just shy of 700 LOC and plenty of bugs making me squirm Smile
b = b + ...
Reply




Users browsing this thread: 1 Guest(s)