I added "shell" to the TextEditor highlight modes :)

Ask about the individual Gambas components here.
Post Reply
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

I added "shell" to the TextEditor highlight modes :)

Post by BruceSteers »

Hi all.

I've added shell to the highlighting modes of the TextEditor control.
Got it handling most things okay, even comment lines and as sh has no datatype defining i used the datatype colour for commands like echo/read/exit, etc.

I've sent the merge request to github (hopefully i did it right)
https://gitlab.com/bsteers4/gambas

Here it is in action on my Scripting text editor program that is also coming along nicely. I've made a colour theme changer for full customisation (shown in pic) , it has a "run" button that saves the script and runs it in a TerminalView :)

(Yes i know it's a disgusting colour theme but i was testing it out lol)
BruceS
snap.png
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: I added "shell" to the TextEditor highlight modes :)

Post by BruceSteers »

Talk about catch-22 though

I'm a great believer that Gambas is not a single user programming environment and gambas apps should be everywhere and work on all systems.

But now i'm making apps that will currently only work on my gambas as my gambas has been modified :-\
And if my merge requests don't get accepted then i'm in a world of my own.

dag nab it!

:lol:
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: I added "shell" to the TextEditor highlight modes :)

Post by BruceSteers »

And now my friends , you have it too :)
My merge got accepted so TextEditor control now also supports sh/bash shell scripting style/mode :)
So if you're on the master commit you can pull the update now.

Mode wise there was not much i could do, like how gambas auto-capitalises keywords and stuff, that sort of thing wouldn't really work in bash.

Unless some of you can think of anything you would like to happen automatically.
I might look into auto spacing when using angle brackets in if statements [] , stuff like that could work, and help ;)

It works in the following way for highlighting...

The following list is considered Keywords and colour is set with TextEditor1.Styles[Highlight.Keyword].Color
"function", "do", "else", "test", "for", "to", "in", "fi", "if", "elif", "then", "return", "exit", "while", "until", "done", "break", "continue", "select", "case", "esac"

The following list is considered Operators and colour is set with TextEditor1.Styles[Highlight.Operator].Color
"{", "}", "$", "#", "[", "]", "-gt", "-lt", "-ge", "-ne", "-le", "-eq", "<<<", ".", "+", "<<", "=", ">>", "==", "-", ">>", "~", "+=", "(", ",", "!=", "*", "-=", "&=", ";;", ")", "<", "%", "&", "];", "@", "!", ";", ">", "|", "?", "^", "\\", ":", "<=", "/", "`"

As there is no Datatype defining in bash i used for a bunch of built in bash commands using compgen -b
So the following list is classed as Datatypes and colour is set with TextEditor1.Styles[Highlight.Datatype].Color
"echo", "read", "cd", "which", "rm", "cp", "mv", "rmdir", "cat", "grep", "awk", "tr", "sed", "sleep", "clear", "sudo", "su", "source", "eval", "export", "time", "date", "pwd", "set", "unset", "chown", "chmod", "exec", "alias", "unalias", "bg", "bind", "builtin", "caller", "command", "compgen", "complete", "compopt", "declare", "dirs", "disown", "enable", "fc", "fg", "getopts", "hash", "help", "history", "jobs", "kill", "let", "local", "logout", "mapfile", "popd", "printf", "pushd", "readarray", "readonly", "shift", "shopt", "suspend", "test", "times", "trap", "type", "typeset", "ulimit", "umask" "wait"

Numbers are detected just as in gambas highlighting TextEditor1.Styles[Highlight.Number].Color

Most other text will identify as Symbol TextEditor1.Styles[Highlight.Symbol].Color

Note.
For everything except Highlight.Background you can also set ...
Styles[HighlightConst].Bold and Styles[HighlightConst].Underline boolean properties.

It detects function calls by looking for "Word()" or "Word() {" functions are set with TextEditor1.Styles[Highlight.Function].Color

Single quote marks have been added to Strings detection, set with TextEditor1.Styles[Highlight.String].Color

I also made single quotes to do the same stuff as double quotes as they are considered string delimiters in bash unlike gambas where single quote is just used for commenting.

Also selecting some text and pressing single or double quotes will not erase text but put a quote either side like it does for brackets.

Thank you and you're welcome :)
Bruce
If at first you don't succeed , try doing something differently.
BruceS
User avatar
tincho
Posts: 57
Joined: Wednesday 10th July 2019 1:12pm

Re: I added "shell" to the TextEditor highlight modes :)

Post by tincho »

Cool Bruce.
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: I added "shell" to the TextEditor highlight modes :)

Post by BruceSteers »

You will need to compile it but i added it to gambas 3.14 too on a branch on my git page.
It's Gambas 3.14.3 with shell highlighting added to TextEditor.
I also added backward compatibility for 3.15 .project files.
and gb.pdf was broken so imported it from gambas master.
I had to update the gitlab.cy.yml file and fix the gb.db.mysql main.c file

https://gitlab.com/bsteers4/gambas/-/tree/3.14.4

not made many changes yet but will probably add a few fixes/upgrades from 3.15
see the commit list here...
https://gitlab.com/bsteers4/gambas/-/commits/3.14.4
Bruce
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: I added "shell" to the TextEditor highlight modes :)

Post by BruceSteers »

NON beta gambas users...

I have edited and re-compiled 3 gambas controls...
gb.eval.highlight
gb.form.editor
gb.form.terminal.

terminal is recompiled from the latest version and has all the latest official bug-fixes from 3.15.90 (like 'clear' not giving errors)

the other 2 enable shell highlighting for TextEditor.

I've recompiled on Gambas 3.12.2 / 3.14.3 and 3.15.2-stable
Goto here...
https://gitlab.com/bsteers4/gambas3-shell-highlighting
Select the branch relevant to your version and select "Download" not clone or you will clone the whole repo and might not be on the correct branch.
(the whole gambas source files were not really needed but i thought to include them in case anyone wanted to do further modifications)
Download and unpack to a folder.
Each branch contains a bash installer to copy the .gambas components or do it yourself.

Anyone fancy testing it out?
if you find it's not working the install can be quickly restored by typing something like..
sudo apt reinstall gambas3-gb-eval-highlight gambas3-gb-form-editor gambas3-gb-form-terminal

All the best
Bruce
If at first you don't succeed , try doing something differently.
BruceS
Post Reply