Community discussions

MikroTik App
 
User avatar
Milkthief
just joined
Topic Author
Posts: 16
Joined: Wed Jan 18, 2017 3:29 pm

Colorize scripting

Mon Dec 05, 2022 9:30 am

Hi,
I think it would be very useful if inside Winbox, where a box permit to enter some scripting code, it would be colorized and with line numbers as in the terminal window.
I often need to modify and debug scripts inside winbox and colors help.
Please, Mikrotik Team, consider to inplement this function that many unoffcial editors have, not your official... ;-)

Image
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Colorize scripting

Mon Dec 05, 2022 12:14 pm

That would help debugging and creating script, so +1
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Colorize scripting

Mon Dec 05, 2022 2:03 pm

I SINCERELY think it's completely useless right now, for two reasons,
first of all the staff should be dedicated to FEATURE EQUALIZATION between RouterOS 7 and previous versions.

Subsequently it would only be an embellishment, and in any case everyone would like it similar to the one they use the most, and it's quicker if everyone uses their own favorite directly.

A generic check can already be had with
"/system scheduler print detail"
or
"/system script print detail"
(adding or not "where name=<SCRIPT_OR_SCHEDULER_NAME>")
 
User avatar
diamuxin
Member
Member
Posts: 319
Joined: Thu Sep 09, 2021 5:46 pm
Location: Alhambra's City

Re: Colorize scripting

Mon Dec 05, 2022 6:28 pm

Interesting.

Rex, what external editor do you use for the scripts? I'm trying Visual Studio Code and it works fine.

Is there a better one?

BR.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Colorize scripting

Mon Dec 05, 2022 8:19 pm

Notepad...
yes, the Windows Notepad... not notepad+... and HomeSite+ 5.5...

About the better editor, I never use something more complex for scripting.
 
User avatar
Milkthief
just joined
Topic Author
Posts: 16
Joined: Wed Jan 18, 2017 3:29 pm

Re: Colorize scripting

Mon Dec 05, 2022 10:30 pm

I SINCERELY think it's completely useless right now, for two reasons,
first of all the staff should be dedicated to FEATURE EQUALIZATION between RouterOS 7 and previous versions.
I think that how to manage and load Mikrotik staff is out of our business. Firmware staff could be different from winbox staff, so nobody subtracts time to nobody.
Subsequently it would only be an embellishment, and in any case everyone would like it similar to the one they use the most, and it's quicker if everyone uses their own favorite directly
Your preferred editor cannot run RouterOS code. So it's not the same. Do you ever wrote a complex huge script?

If colorize the script editor is useless, why is the terminal colorized?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Colorize scripting

Mon Dec 05, 2022 11:03 pm

I think that how to manage and load Mikrotik staff is out of our business
so, this topic, what does it exist for?

Firmware staff could be different from winbox staff, so nobody subtracts time to nobody.
If winbox is to execute the RouterOS code ( «cannot run RouterOS code» ), surely it also needs to interact with other parts, not just the "nice" script editor,
so that already belies the fact that "it only takes one person",
then there are dozens of things that winbox (and also webfig) that they don't do and that are only available via CLI,
so it's better if, as already written, they finish before developing what they have to do to make winbox do everything that is already available.

Your preferred editor cannot run RouterOS code. So it's not the same.
why, writing an "editor" for winbox would it "compile" and "execute" the script before running inside the routerboard?

Do you ever wrote a complex huge script?
well... who knows... just some hundred... ask the others forum members...

If colorize the script editor is useless, why is the terminal colorized?
For the same reason you can open any topic on this forum and add it to the hundreds of useless topic
about requests made to forum users (instead of staff) that mikrotik personnel will never consider.

Even the scripts give such generic errors that often you don't understand what's wrong,
dozens of instructions are absent, like a very stupid "search and replace",
the floating point numbers are missing,
the time and date is inconsistently written in 4 (and more) different ways,
the conversion functions are trivially missing,
already working function are broken and never repaired (like convert a string to ip-prefix)
directory can not be created
the variables are limited to 4k or 62k (depends on case and context)
missing CP1252 (and the other), UTF-8 and UCS-2 support
and I could continue the list for hundreds of other things,
let alone if they are dedicated to "coloring" the code, as if it were the most important thing to do....
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3253
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Colorize scripting

Mon Dec 05, 2022 11:20 pm

Gotta love the minimalism of notepad. However, I like color coding too! In fact one reason I don't use the "edit" in the CLI because of that. Personally I end up using with VS Code since it offers both RSC colors and VIM (plus helpful plugins for SSH/SCP, "prettier", JSON viewer/checker, etc. etc.) – everyone's different.

AFAIK, RouterOS is "nano" (or some other pico clone), which does support syntax coloring. So this largely involve "translating" the numerous colorizers from vim to VS Code already out there – these "syntax of the syntax" is just some regex that can easily be copied to the specific format required for the "Mikrotik editor".

See nano's docs, it's doesn't look hard from specs:
https://www.nano-editor.org/dist/latest ... ghlighting
or examples of it:
https://github.com/scopatz/nanorc

Unlike your "offline editor" choice, the one on the RouterOS isn't something you can change yourself... so don't think it's unreasonable request.
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3253
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Colorize scripting

Mon Dec 05, 2022 11:39 pm

I SINCERELY think it's completely useless right now, for two reasons,
first of all the staff should be dedicated to FEATURE EQUALIZATION between RouterOS 7 and previous versions.
I think that how to manage and load Mikrotik staff is out of our business. Firmware staff could be different from winbox staff, so nobody subtracts time to nobody.
I have no idea how MT prioritizes things, or decides new features – feel more random than it should... And, can't imagine this be high on the list either given v7 still has some growing pains.

But if important to you, probably should file a "Feature Request" in JIRA: https://help.mikrotik.com/servicedesk/s ... 1/create/6

Likely no greater urgency, but at least tracked likely there main list of these things.
 
User avatar
Milkthief
just joined
Topic Author
Posts: 16
Joined: Wed Jan 18, 2017 3:29 pm

Re: Colorize scripting

Mon Dec 05, 2022 11:49 pm

Gotta love the minimalism of notepad. However, I like color coding too! In fact one reason I don't use the "edit" in the CLI because of that. Personally I end up using with VS Code since it offers both RSC colors and VIM (plus helpful plugins for SSH/SCP, "prettier", JSON viewer/checker, etc. etc.) – everyone's different.

AFAIK, RouterOS is "nano" (or some other pico clone), which does support syntax coloring. So this largely involve "translating" the numerous colorizers from vim to VS Code already out there – these "syntax of the syntax" is just some regex that can easily be copied to the specific format required for the "Mikrotik editor".

See nano's docs, it's doesn't look hard from specs:
https://www.nano-editor.org/dist/latest ... ghlighting
or examples of it:
https://github.com/scopatz/nanorc

Unlike your "offline editor" choice, the one on the RouterOS isn't something you can change yourself... so don't think it's unreasonable request.
I totally agree. Unfortunately the wisdom of those who are too good to use only notepad (I haven't used windows for 20 years and unfortunately I can't experiment with this wonderful technique) do not consider that most of the others are less good than him, and that the tools need to be calibrated for them. This is demonstrated by the fact that all development IDEs use colors and that all developers on the planet use IDEs, not notepad. It would be appropriate to ask what is normal and what is not. But I know the "saccenza" of some Italians, because unfortunately I am part of their people. I won't give any more answers on this kind of philosophy, because fueling a flame is not why I wrote.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Colorize scripting

Tue Dec 06, 2022 1:25 am

because fueling a flame is not why I wrote.
In fact, fueling it no, but starting it yes...
The usual Scandinavian troll.


There you go: you've added yourself to the list of Italians to be ashamed of.
 
Sob
Forum Guru
Forum Guru
Posts: 9119
Joined: Mon Apr 20, 2009 9:11 pm

Re: Colorize scripting

Tue Dec 06, 2022 3:54 am

Colors? Come on! What will be next? Reporting syntax errors instead of "silent death"? It would ruin the experience!

I'm kidding, of course. But after it being like this for so many years, I do sometimes think that the general unfriendliness of RouterOS scripting might be by design for some reason.
 
User avatar
Milkthief
just joined
Topic Author
Posts: 16
Joined: Wed Jan 18, 2017 3:29 pm

Re: Colorize scripting

Tue Dec 06, 2022 8:27 am

because fueling a flame is not why I wrote.
In fact, fueling it no, but starting it yes...
The usual Scandinavian troll.


There you go: you've added yourself to the list of Italians to be ashamed of.
You fail to understand how a company works and that it is divided into departments. You'd be able to accuse the graphics Mikrotik guys of wasting time redoing the logo instead of fixing the firmware. So you started judging and being offensive. I'm the one who's ashamed!
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Colorize scripting

Tue Dec 06, 2022 11:56 am

You'd be able to...
What a silly way to counter by writing "then you'd be able to do this or that", is worth absolutely nothing.
 
d412s
just joined
Posts: 17
Joined: Fri May 08, 2020 1:32 pm
Location: Ukraine

Re: Colorize scripting

Sat Apr 29, 2023 12:17 am

Maybe someone can tell which tool I can use for formatting?
Because it`s complicated to support code style in notepad, example:
/interface ethernet monitor ether1 once do={
:if ($"rate" != "11Gbps") do={ 
:log error "ether1 is NOT  $"rate""
:local 1Gbit "$error $deviceName%0A$deviceDate $deviceTime : %0A%0Aether1 == $"rate""
$TGSendMessage Token=$TelegramBotToken ChatID=$TelegramChatID Text=$1Gbit


/interface ethernet set ether1 disabled=yes
:delay 3
/interface ethernet set ether1 disabled=no


:log warning "ether1 is $"rate""

	}

:if ($"status" == "link-ok") do={
:local 1Gbit "$success  $deviceName%0A$deviceDate $deviceTime : %0A%0Aether1 == $"rate""
$TGSendMessage Token=$TelegramBotToken ChatID=$TelegramChatID Text=$1Gbit
}
}
For highlights at least I can use VScode, but I did not find formatter tool.

I am Java developer and write script on routerOs is really painful, no debugging, syntax highlights, no formatter, just copy/paste by little pieces and execute... I use it really rare, but I don`t understand why no one else bothers it.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Colorize scripting

Sat Apr 29, 2023 3:09 am

[...] but I don`t understand why no one else bothers it.
Because "no one else" want first "abbelishment" than a long-term v7...

11Gbps ???

Try to write easily and correctly the code, less time...

untested but reformatted same code

/interface ethernet
:local if      "ether1"
:local mon     [monitor $if as-value once]
:local rate    ($mon->"rate")
:local status  ($mon->"status")
:local message "$deviceName%0A$deviceDate $deviceTime : %0A%0A$if = $rate"

# 11Gbps \?\?\?
:if ($rate != "11Gbps") do={
    :log error "$if is NOT $rate"
    [$TGSendMessage Token=$TelegramBotToken ChatID=$TelegramChatID Text=("$error $message")]
    disable $if
    :delay 3s
    enable $if
    :log warning "$if is $rate"
}

:if ($status = "link-ok") do={
    [$TGSendMessage Token=$TelegramBotToken ChatID=$TelegramChatID Text=("$success $message")]
}
For test the script on terminal, put all the script between { }
Last edited by rextended on Sat Apr 29, 2023 4:13 am, edited 1 time in total.
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3253
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Colorize scripting

Sat Apr 29, 2023 3:49 am

FWIW, on the topic, I believe they add colors to the built-in editor in latest V7 now. At least for "/system/script edit [find] source". It won't do syntax coloring using an .rsc file and /file edit contents however.
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3253
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Colorize scripting

Sat Apr 29, 2023 3:54 am

I am Java developer and write script on routerOs is really painful, no debugging, syntax highlights, no formatter, just copy/paste by little pieces and execute... I use it really rare, but I don`t understand why no one else bothers it.
Yeah there is no formatter plugin. Although, there is "style guide" and many preference.

The only option for debugging is copy script as file to RouterOS, then using "/import <scriptfile> verbose=yes". Dispute the same "import", it really run code in a file, but offer the verbose=yes option which will show a line-by-line output. This can be helpful to spot parsing errors. No debugger, but helpful sometimes.

Who is online

Users browsing this forum: UkRainUa and 18 guests