If, like me, you are a G’MIC script writer, then you know how often we had to insert the
verbose command (shortcut
v) here and there, to be able to show some messages (typically when using
echo), and hide others (typically, all other command descriptions), when implementing a new G’MIC function.
That was really annoying.
Next release 2.8.0 changes the way verbosity is managed, and hopefully makes things simpler.
These rules will apply:
verbosity>0, commands display messages on the console when doing something. Default value is
1for the CLI interface (
0otherwise (e.g. for the libgmic).
Exceptions to rule 1: Commands
warndisplay a message for
verbosity>=0(so even when
- When entering a new command, the verbosity level is decreased by 1, automatically.
- When exiting a command, the verbosity level is reset to the level it has before entering the command.
Using these simple rules, I’ve been able to remove 99% of the calls to
verbose in the gmic_stdlib.
Basically, you can write a new command
foo, like this:
foo : e[^-1] "Who cares about verbosity anymore ?" blur 10 mirror x
and call it from the command line, with the CLI tool
$ gmic sp lena foo
Then, the verbosity level in
foo will be equal to
0 , because default value for the CLI is
1, and it has been decreased by
1 when entering
With a verbosity of
0, no command are allowed to output description messages, except
echo, and so the output of the CLI call is:
$ gmic sp lena foo [gmic]-0./ Start G'MIC interpreter. [gmic]-1./ Input sample image 'lena' (1 image 512x512x1x3). [gmic]-1./ Who cares about verbosity anymore ? [gmic]-1./ Display image  = 'lena'.  = 'lena': size = (512,512,1,3) [3072 Kio of floats]. data = (176.415,177.317,178.193,179.018,179.777,180.465,181.087,181.655,182.189,182.71,183.235,183.774,(...),99.0435,95.7627,92.6489,89.7203,86.9871,84.4549,82.1242,79.99,78.0426,76.2712,74.6659,73.2174). min = 23.9194, max = 239.852, mean = 128.226, std = 50.6075, coords_min = (0,46,0,1), coords_max = (21,336,0,0).
And rule 4 is awesome If you want to change the verbosity in a command (for instance, to force
echo writing something, even for a command called with a high depth level, then just start your command with
v 0 and don’t worry about the rest, the verbosity value will be reset to its previous value at the exit).
Now, you can’t mess with the verbosity in all commands, simply because you forget to put a
v - in one of your command. Priceless
Another good point : As you don’t have to put a lot of
v + and
v - everywhere, the G’MIC interpreter doesn’t have to parse them anymore which lead to slightly faster execution.
This has requested some important changes in the code, I’m still testing to make it clean.
Hopefully, I’ll be able to release binary packages for 2.8.0_pre this afternoon.