Flow Control: a programmer's text editor

This is my Zig text editor. It’s my first major Zig project. It is a work-in-progress, but far enough along that I am daily driving it.

Lots more info in the README.md and help.md on github.

https://github.com/neurocyte/flow

23 Likes

Looks cool :slight_smile:

What kind of confused me at first was the zig wrapper, did’t notice it comes with it’s own compiler ^^

Is there a full list of keybindings somewhere?

Keybindings are on the help page (F1 or Ctrl-? on the home screen).

And here is the source for the help page: flow/help.md at master · neurocyte/flow · GitHub

ah thanks, F1 works. ctrl ? doesn’t though, on my German-Layout keyboard (question mark needs the shift key being pressed).

Looks super nice, as long as I can configure helix-like keybindings. Now all we need is a shell, and I can say my whole environment is written in Zig (btw).

1 Like

This is really really impressive. I myself am trying to make a text editor at the moment, though more proof of concept than anything else and am using a Piece Table partly because I am not yet good enough to make a rope, which I see you are using. Would you mind exporting the rope as a package? Due to its usefulness and difficulty making it, it would be a super super valuable addition to the ecosystem!

Hello, a lot of work, well done, it inspires me, I’m going to look at “notcurse”, for my screen generator, once again great work on your part.

The rope is inside the Buffer module which is already a module, but not probably useful yet as a seperate package. The reason being that it has a notcurses dependency which is used for mapping columns to byte offsets, among other things. If that was replaced with something like zyglyph it would be more generally useful and make much more sense as a seperate package. I don’t know when I’ll get around to that though.

Ah okay, that makes sense. Still very very impressive!
How was your experience making it? Did you fail or hit roadblocks, or was it smooth sailing? (Or something in between obv)

Although notcurses is powerful and very fast it does have it’s downsides. It is a C library with quite a few other C dependencies. That can make things a little more complicated. I highly recommend you first checkout libvaxis, which is a pure Zig library providing similar features to notcurses. It has a lot less features right now, but if it’s enough for your needs it might be a much better solution.

2 Likes

Hm okay, thats good to know. What functions was ncurses used for?
Also how was the rope specifically? Im sorry if this im being annoying

ncurses is not used directly, it’s just a dependency of notcurses. I think notcurses uses it for terminfo support.

Your second question I don’t understand.

How hard was it to implement the rope? What were the main pain points? etc. etc.

I don’t if I would call any of it hard, but it’s not the first binary tree structure I’ve written, so I guess I knew what to expect. A rope is really just a binary tree with a few extras. That being said, the insert_chars and del_chars functions contain a lot of unexpected (to me at least) complexity and took significant effort to get right. These function manipulate an arbitrary, possibly large, number of nodes in a single call making them inherently complicated.

hello,
I visited “libvaxis” very interesting, it’s something I will come back to, it is possible to make a very nice console (terminal) for applications

Okay, thank you. You wrote its a piece table / rope hybrid, how so? That sounds really cool, what motivated you to do so and how was it done?

Rope/piece table hybrid is just the shortest description I could come up with. It’s not nearly as hightech or cool as it sounds. :joy:

It’s basically a pretty standard rope type structure. So, a binary tree with some extra weight info stored in the nodes. The only difference to common ropes is that the actual text chunks are not stored directly in the rope nodes. The text is stored in an arena that contains the original text of the file and all additional inserted text. The rope nodes then contain references only. Similar to a piece table. Hence me calling it a hybrid.

The entire thing is persistent because modifications create only new nodes, which is really nice for undo/redo and also multithreaded background processing.

2 Likes

Ah okay, that makes sense!

What’s the main blocker for windows support? I’m new to zig but maybe doing something like this will help my understanding a lot. Doesn’t notcurses support windows?

The biggest difficulty with windows is probably getting a good terminal. If you have a good terminal you can already run flow in WSL. I’m not sure about notcurses on windows though. Windows is listed on the notcurses site, but there are no successful builds as far as I can tell.