Some changes with the verbosity

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:

  1. When verbosity>0, commands display messages on the console when doing something. Default value is 1 for the CLI interface (gmic), 0 otherwise (e.g. for the libgmic).
  2. Exceptions to rule 1: Commands echo, print and warn display a message for verbosity>=0 (so even when verbosity==0).
  3. When entering a new command, the verbosity level is decreased by 1, automatically.
  4. 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:

$ 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 foo.
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 [0] = 'lena'.
[0] = '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).

as expected.

And rule 4 is awesome :slight_smile: 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 :slight_smile:

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.

1 Like