Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax highlighting #43

Open
vampiebar opened this issue Jan 25, 2021 · 9 comments
Open

Syntax highlighting #43

vampiebar opened this issue Jan 25, 2021 · 9 comments

Comments

@vampiebar
Copy link

Is it possible to make CPP editor widget syntax highlight theme?
what is the most elegant way to do it?

@magiblot
Copy link
Owner

Hi vampiebar,

If you want syntax highlighting so that you can use the editor application regularly, I suggest you take a look at https://github.com/magiblot/turbo instead. But if you are just interested in reusing the TEditor class in your application, that's going to be more difficult.

Cheers.

@vampiebar
Copy link
Author

Thanks for the information,
I will use it with your tvision library.. I will try to merge your tvision with scintilla..
Are they using your tvision?

@magiblot
Copy link
Owner

If you mean whether that application depends on this tvision repository, yes, it does (it is also written by me).

What idea do you have in mind? It'd be great to make the tvision-Scintilla adapter reusable for other projects, but I don't think it should be part of the main Turbo Vision library (this repository).

For your own project, I'm fine if you just copy code from the Turbo text editor. It's not good to have duplicate code among projects, but it will allow you to begin working on your application right away.

@vampiebar
Copy link
Author

If you mean whether that application depends on this tvision repository, yes, it does (it is also written by me). ---> perfect

What idea do you have in mind? It'd be great to make the tvision-Scintilla adapter reusable for other projects, but I don't think it should be part of the main Turbo Vision library (this repository). ---> I want to make rhide / borland c++ 3.5 style editor with "textadept" like lua code completion etc.. with language server protocol..
what do you recommend? https://github.com/magiblot/turbo use this one right ?
I want to make it terminal based app without X dependency.

@magiblot
Copy link
Owner

I want to make rhide / borland c++ 3.5 style editor with "textadept" like lua code completion etc.. with language server protocol..
what do you recommend? https://github.com/magiblot/turbo use this one right ?
I want to make it terminal based app without X dependency.

That's fine. This Turbo Vision port does not depend on X and is well integrated even with the legacy Linux console (GPM mouse support, support for key modifiers, etc). If you try the Turbo text editor you will see it also benefits from this, and so will your application.

I think relying on Scintilla, like Turbo does, is a good idea. There are hundreds of text editors based on Scintilla out there and I'm pretty sure it can be integrated with language servers and other cool features.

@electroly
Copy link
Contributor

electroly commented May 8, 2021

For what it's worth, I have found that basic syntax coloring is surprisingly easy to hack into a TEditor subclass if you already have a lexer. Scintilla/turbo seems to be primarily useful if you want to use its built-in lexers. If you're planning to integrate with an external language server, then you may want to use its lexer for syntax coloring instead. Since I needed to use my own lexer anyway, I decided it was easier to implement syntax coloring in TEditor myself rather than integrating turbo.

Here is an example implementation that implements syntax coloring and system clipboard support (using libclipboard) in a TEditor subclass: https://github.com/electroly/tmbasic/blob/master/src/tmbasic/CodeEditor.cpp ( + .h)

I overrided TEditor::draw(), which allowed me to call my own drawLines(), which calls my own formatLine(), which contains my syntax coloring logic. These functions were copied straight from the TEditor source code and then modified. @magiblot -- it would be nice if formatLine() itself were virtual so I could just override it directly, without needing to start with draw() and copy the tree of functions down to formatLine().

@magiblot
Copy link
Owner

magiblot commented May 9, 2021

Although it costs nothing to make TEditor::formatLine virtual, I don't want to encourage programmers to spend time extending or rewriting TEditor. TEditor is clearly insufficient: you have managed to add syntax coloring without much hassle, but I guess you (or any other programmer) will soon miss a decent undo buffer and other features, and that won't be as easy to add.

One could think of improving TEditor so that it is useful enough to modern users and programmers, but personally I think doing so would be a waste of time. I'd rather put efforts into making Scintilla easily reusable by Turbo Vision applications.

But that's just how I see it, maybe you find adopting Scintilla too much of a burden compared to just hacking TEditor a bit.

@electroly
Copy link
Contributor

It's very possible that you're right. I see what you mean about the undo support; I hadn't tried it out, but yeah, that implementation really only works in the simplest situations. I'd certainly like the ability to undo more than one step, and the ability to redo. I did write an undo manager for my picture editor but I haven't tried to integrate it with TEditor.

The other issue I didn't mention is that my syntax coloring support doesn't work for the current line being edited. As soon as you start typing, the whole line turns gray. It becomes colored again after you navigate to another line. I had filed this under "it's probably fine" but it's among these shortcomings.

Maybe I'll take another look at integrating turbo. With your turbo fixes I got it successfully built and linked into tmbasic and I could pull up the editor window, but I hit a wall when I tried to actually integrate it for use as my code editor. The file handling seems to be integrated directly into the editor, but I want it to operate on in-memory strings and let me handle the file stuff. I also need turbo to able to share my fallback clipboard when running on Linux without X. It seemed like I was heading for a full fork, which I wanted to avoid. Maybe I can try to upstream the changes.

@magiblot
Copy link
Owner

magiblot commented May 9, 2021

It's enough if you share the changes you already did. That'll help me figure out how the responsabilities of each class need to be split.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants