martanne / vis

A vi-like editor based on Plan 9's structural regular expressions
Other
4.27k stars 262 forks source link

Separation of Core and UI #262

Open critiqjo opened 8 years ago

critiqjo commented 8 years ago

Assumptions: Single window, single file

Concerns of Core

TODO

critiqjo commented 8 years ago

@martanne I'm ready to work on this during the coming June. What are your thoughts? If you don't have any plans to separate the UI out, then do mention and close this issue...

critiqjo commented 8 years ago

Although I'd say that before attempting this, a proper test suite have to be ready.

martanne commented 8 years ago

What are your thoughts?

I think the current code base is already mostly structured that way, I certainly tried to keep separate things separate. vis.h specifies a "high level" editor interface, view.[ch] is your viewport, ui.h defines an abstract interface currently implemented by one concrete backend ui-curses.[ch].

There certainly exist some warts. A general ui should not directly have to depend on libtermkey (as is currently the case). Also the rendering code in view.[ch] has become somewhat of a mess and is quite limited. Basically you can only specify a starting position from which it will render text content until the available space is filled up. There is currently no way to display/attach arbitrary data (such as compiler error messages) inline. Also the displayed text has to be contiguous i.e. no support for folds etc (not that I miss them, but they should in principle be possible). The Lua based syntax coloring should also be moved out of it, view.[ch] should not depend on Lua. It should be possible to run multiple lexers (e.g. a language specific one followed by one highlighting trailing white spaces etc) on the same view.

Feel free to improve it. While I personally don't have an interest in alternative GUIs, trying to add an EFL (or GTK) based UI would surely highlight some more deficits of the current architecture. Also the necessary integration into a proper main loop could prove to be useful for async I/O related activities.

Also the most interesting section of your post, the "Core API" is marked as TODO ...

critiqjo commented 8 years ago

I think the current code base is already mostly structured that way

Great!! :+1:

While I personally don't have an interest in alternative GUIs

Neither do I, but that may be because I haven't found one that integrates with terminals the way I would like.

"Core API" is marked as TODO ...

That needs a lot of thinking. I'm getting a few ideas but it doesn't seem general enough (considering that it should work across languages). For single-file single-view part may not be that hard, but we'll have to support multiple files & windows at some level. If the design fundamentally cannot accommodate inter-widow interactions (same-file-multi-views, diff-mode, locked-scrolling etc.), then it would be a lot of pain to change it in future.

One major thing I noticed is that the pieces are presented as a linked list. I loved the design, but linked lists are not a great choice when you consider sharing access. I've been thinking about writing a CoW Binary tree with some specific properties to keep track of line numbers. But I would be a madman to try making it in C (it would literally take years to make it memory&thread-safe). I'm referring to Rust, of course. And thinking further, I'm actually interested in rewriting this in Rust (which would actually make me a madman!)...

mcepl commented 8 months ago

OK, what is this ticket good for? Does anybody work towards it?