Shop OBEX P1 Docs P2 Docs Learn Events
mvi & svi text editor — Parallax Forums

mvi & svi text editor

RaymanRayman Posts: 13,851
edited 2021-02-12 14:43 in Propeller 2

Was able to compile this simple version of vi with FlexSpin C:
https://github.com/byllgrim/mvi

Used curses.h that made to run Rogue game and mostly worked without modification.
Only thing really missing was a cursor.
Here, I just changed the colors of the current location to be block cursor.

Seems to be in a kind of working state. Gets messed up by tabs, have to fix that...
Also, doesn't seem to behave properly when you go beyond the bottom of the screen or off to the right.
Haven't tried saving yet.

But, it's an on chip text editor :)

Comments

  • Cool, how big was the binary with the editor?

  • RaymanRayman Posts: 13,851
    edited 2021-02-11 15:51

    Here's the current code with binary. It's 224 kB. A lot of that is reserved heap. Maybe it needs more, maybe less, not sure yet.

    This is in the "this might actually work" state at the moment. Probably needs a lot of work.

    It is supposed to handle UTF-8. I think that means unicode. Might have to try that...

    This is configured for the Eval board with A/V accessory on basepin 0 and the file "hello.txt" on the uSD card of the Eval board.

  • RaymanRayman Posts: 13,851

    You control it at the moment via computer keyboard and the FlexProp terminal window.
    The controls are the same as the original, although I haven't tried them all:

    :d        - delete line
    :q        - quit
    :q!       - force quit
    :w [file] - write to file
    h,j,k,l   - left, down, up, right
    i         - insert mode
    ESC       - normal mode
    
  • RaymanRayman Posts: 13,851
    edited 2021-02-12 17:58

    I just got the svi (more advanced version) to run. https://github.com/byllgrim/svi

    It adds some useful things like searching:

    /[term]   - search for term
    :[num]    - move to line num
    :d        - delete line
    :q        - quit
    :q!       - force quit
    :w [file] - write to file
    A         - append at end of line
    I         - insert at start of line
    h,j,k,l   - left, down, up, right
    i         - insert mode
    n         - search downwards
    ESC       - normal mode
    

    Tested out search and write to file, appears to work (although search is case sensitive).

    So, really just need to fix tabs (or replace them with spaces) to have a working editor...

    To test this, just run this svi.c in place of mvi.c of the above zip.

    c
    c
    11K
  • @Rayman , good work on porting the vi code to the P2. I have to try it out when I get a chance.

    I had three different editors that ran under spinix on the P1. They were ted, ed and vi. ed is the standard unix line editor. I added a Vn command to ed that would print out "n" lines every time a command was entered. ted is a simpler version of ed with just a few basic commands. My vi editor was fairly complete. It supported yank and push, searches and string replacement. According to my documentation it also supported most of the commands when in the ex mode. It was written in C, but I used CSPIN to convert it to Spin for spinix. I made some attempt to get it to run on the P2, but I don't recall how far I got. I'll have to take a look at it again. Oh, and it supported three different terminal types -- PST, ANSI and dumb terminal.

  • RaymanRayman Posts: 13,851

    @"Dave Hein" Looking at your P1 code may have been an easier way to do this...

    But, I'm also doing this to learn how to do things in low level C and how other C code from Github works...

    I may take this and build it into an editor for my 1080p tile driver with USB keyboard and mouse support.
    (or, I may not).

    Got a little hung up on UTF-8 and unicode such. Think I understand it now, at least a little.
    Think my approach would be to convert the input file from multi-byte to a simple 8-bit representation for use with the P1 font from the tile driver.
    This simplifies the code a lot. It could be saved back as multi-byte though as an option.
    This would just lose any characters that aren't in the P1 font.

  • RaymanRayman Posts: 13,851
    edited 2021-02-12 20:11

    tabs mess everything up too... Might just convert tabs to spaces...

    and also have to deal with \n and/or \r..

  • The \n and/or \r thing is fairly easy to handle. When you read in a file you can keep track of which format it uses, and then use the same format when you write it out. The editor's internal representation can use a different format, such a just null-terminated strings without any \n's or \r's.

    Handling tabs is a messing thing. You could assume tabs are aligned on every eighth columns, but that may not be how the file was created. I think in my editors I treat tabs as space, but I might be mistaken about that.

Sign In or Register to comment.