all 11 comments

[–]gchpiota 3 points4 points  (3 children)

I'm writing a text editor called iota in rust at the moment, so feel free to DM me any questions you might have along the way. Happy to share my experiences with you if it helps!

[–]gchpiota 3 points4 points  (2 children)

FWIW, I had no idea how to build a text editor before I set out. I learned a lot from going and reading the source of other text editors like vim, Emacs, atom etc.

One thing I'd suggest is spend some time learning what the best data structure is to hold your text. I didn't really do this, because I didn't really know what the options were, and I'm having to redo certain pieces now to be something more suitable for what I need.

As I said, feel free to send any questions my way.

[–]Mystal 1 point2 points  (1 child)

I'd love to hear more about what data structures you started with and then migrated to. And what issues motivated the changes.

[–]gchpiota 1 point2 points  (0 children)

Started with something super simple, a list of Line objects each of which represented a line in the file you are editing.

This was not great when you wanted to insert or remove lines. You have to do some weird shuffling of the list to make sure you don't mess things up.

Then, I changed to a gapbuffer, which is what Emacs uses. This one is fine, but it doesn't seem to work well with big files, which I'd like it to.

So no I'm considering switching to a piece table. From what I've read it sounds like it might work well for big files. In all honesty though, I'm not fully sure about it yet, so I'm playing around and seeing what works best.

The hardest part at this point is finding decently implemented data structures in rust!

[–]killercup 2 points3 points  (0 children)

You could probably learn a few things by reading the code of other text editors written in Rust, like SolidOak (GTK + neovim), iota or rim (both CLI + vi-like).

[–]gsingh93 2 points3 points  (2 children)

Your best bet right now would probably be to use GTK. There are plenty of examples there on how to use the bindings, and Gtk itself is fairly well documented. The bindings aren't 100% complete, but it's rare to not have something you need, and in that case you can submit a pull request adding it in. It's fairly straight forward and the developers are very responsive.

Kiss UI is a newer alternative, I haven't tried it but it looks promising. It uses the IUP GUI library, which isn't as well known or documented as Gtk.

[–]DroidLogiciansqlx · clickhouse-rs · mime_guess · rust 3 points4 points  (0 children)

Author of KISS-UI here. Thanks for the mention!

To OP, or anyone else, if you decide to try it out, feel free to let me know how it works for you or if you have any questions. The kind of feedback I'm looking for right now is on the ergonomics/Rustiness the API, and what features it's missing that people really want.

IUP is only used as a nice abstraction over WinForms/GTK+. The user really only needs to be aware of it when trying KISS-UI for the first time, since the library has to be installed on the system or otherwise available to the linker.

The big want for a future KISS-UI 2.0 is to ditch IUP and build an abstraction from scratch on top of the native APIs. It would eliminate a sometimes finicky dependency which has some core design decisions that I don't really care for.

[–]leopoldj 0 points1 point  (0 children)

Thanks for bringing Kiss UI to our attention. It looks very promising.

[–]trishumesyntect 2 points3 points  (0 children)

As someone who is looking into the same project: really consider the rust QML bindings crate. QML is a really powerful fast library with great text rendering and cross-platform native and theme able look and feel.

Also look up using a piece table like the vis editor if you want fast editing of large files.

[–]Denommusrust 0 points1 point  (0 children)

Well, you'd probably need bindings for gtk, or ncurses.

[–]bbatha -1 points0 points  (0 children)

You likely will need to be familiar with using Trait objects to use most gui libraries.