Open LouisAtGH opened 1 year ago
Edit: changed markup syntax of issue to Markdown
Thank you for the report. See my comments below:
-j
option to pimctl
for JSON output, similar to what iproute2 in Linux has. I've added the same recently to another project. This would be a LOT easier to parse from Javascript. We only need to agree out the output format. This is in my own interest as well, so I would be able to help out here with actual code changes -- without committing to any timeline.Joachim, pfSense uses PHP, I worked around the issue this way.
I did work around the problem in the following way:
The ANSI controls available in the output where ESC[4m ESC[24m set underline mode ESC[7m ESC[27m set inverse/reverse mode ESC[0m reset all modes (styles and colors) More info in https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797
With as complicating factor that every modified line was terminated by the generic ESC[0m, which forced me to use a generic html termination code as well.
I defined an string array like this
$dictionary = array(
'#[4m' => '
____' ,
'#[24m' => '' ,
'#[7m' => '' ,
'#[27m' => '' ,
'#[0m' => '' ,
);
Where the '#' is an replacement for the original ESC-character
( I do not know how to insert an ESC-character in a static string array)
Then the following line did the job
= str_replace(array_keys($dictionary), $dictionary, str_replace(chr(27),'#', shell_exec('/usr/local/sbin/pimctl show')));
Joachim,
What seems minimal to me is that the formatting is symmetrical / consistent. As example
Sorry, but no. This is not HTML tags, it's ANSI escape sequences, and there's no standard that says one cannot use ESC[0m to disable all formatting. If you go for translating ANSI escape codes you need to handle all these cases. If you do it right, such a function would be useful for parsing output from many other system tools as well.
My recommendation is still to go for an alternate output format, I suggest JSON since that's sort the industry standard at this point.
Btw, I suppose you've seen the pimctl -p
option to disable ANSI escape sequences altogether?
Oeps! I did not notice the -p option, but that surely improves the situation! Thanks for the tip ! (the idea is not great, but the result of my workarround is not even bad)
Whatever if you want to convert e.g. the ANSI escapes to for example html layout controls, than you you need not only the start of the style change but also the end.
I can convert ansi "start bold" to the equivalent html command but than I also have to insert the "stop bold" and it is not a big deal to translate ^ESC[4m^ into start underline and to translate ^ESC[24m^ into stop underline, but there is no way I can do something with ^ESC[0m^. No way to translate that in some equivalent code
State machine. You can always track the latest set of HTML tags you've inserted. It's definitely possible, we did it in javascript for many other applications at my old job, so it should be in other languages as well.
I'm not going to change the ANSI escape sequences.
Joachim,
I compiled the actual code using freebsd 14-currenct in favor of the actual pfSense development release. Works OK, no problem, apart from an layout issue.
pfsense is integrating the pimctl output in its html screens like this
And pimctl reacts with an output intended for a vt100 command line using control like
However that does not fit in an html page :( (see example below)
To solve this the pmctl headers format should be either OK for both command line and html or there should be an option to select 'the formatting format'
I also have been considering two other options:
Below an example of the pimctl output as it shows up in the pfsense gui, and below that some compiler warnings I discovered. Not dramatic however hot really OK as well.
Louis
pimctl output as displayed in an html screen
How formatted headers are shown in an html page:
Compiler warnings