[GRASS-dev] howto rewrite r.colors using G_message and G_warning
Glynn Clements
glynn at gclements.plus.com
Tue Sep 26 12:14:43 EDT 2006
Jachym Cepicky wrote:
> i have question considering replacing fprintf functions with
> G_message and G_warning in GRASS modules.
>
> Currently, i come to r.colors, which structure is very complicated. This
> module can be also run in interactive mode:
>
> r.colors pokus color=rules
> Enter rules, "end" when done, "help" if you need it.
> Data range is 1 to 683
> >
>
> I'm not shure, if these strings should be printed using G_message or if
> they should stay untouched. I'm also not shure, if the module needs this
> interactive mode at all - if it should not better be removed (and the
> structure of the module would be simplified).
It isn't necessarily an "interactive" mode; you can just as easily
read the rules from a file by redirecting stdin (in which case, the
text and prompts won't be displayed).
[However, r.colors probably should have a file= option; this would
probably be more useful from a GUI. Alternatively, there should be
some way to tell G_parser() that a module may read from stdin so that
the GUI can add a button to allow stdin to be redirected from a file
of the user's choice.]
I suggest not converting this code to use G_message(). You can't use
it for the prompt (G_message() adds a newline), and the information
should (IMHO) be displayed even if verbosity is not enabled.
> If the interactive mode should remain untached, maybe functions
> G_tty() and G_promt() should be introduced:
>
> G_tty(_(Enter rules, "end" when done, "help" if you need it.));
> G_promt()
I don't see any need.
IMHO, the migration to the use of G_message() is primarily for the
benefit of non-interactive modules.
> which would show
>
> Enter rules, "end" when done, "help" if you need it.
> >
>
> Could anybody give advice how to approach to modules like r.colors?
So far as G_message() migration is concerned, don't worry about
interactive cases.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list