I recently submitted a package to CRAN that creates a device that outputs into the terminal (for terminals that support the Terminal Graphics Protocol (and hopefully in the future also terminals that support sixel)) [1].

It introduces a 'tgp' function that does the following:

1. It opens a ragg::agg_capture device.

2. When term_col = TRUE: sets the background and foreground colors of the device to those of the terminal (when these can be detected).

3. Every time the ragg:agg_capture device is updated: updates the plot in the terminal.

Point 2 raises an issue from CRAN as par() changes some properties and these are not set back at the and of the function call. This is intentional, as otherwise setting them would be useless; it is the intention that the colors of subsequent plot calls are changed. I am not sure how I can set the colors of the device to those in the terminal (as requested by the user) without violating this rule.

Are there alternative ways of helping the user to set the colors of the device without violating this issue?

Could this be an exception to the rule as the argument intentionally changes par()? This could be made more explicit by changing the default value to FALSE. I guess this question is better asked at the CRAN maintainers, but perhaps there are other package that do something similar that I might look at.

Instead of having this functionality in the tgp() function, I could create a 'set_figure_colours_to_terminal()` function (perhaps with a corresponding reset function). However, this function would run into the same issue.

I appreciate any suggestions/help that yoy could give.

Best,
Jan




[1] The current version of the code can be found here: https://codeberg.org/djvanderlaan/terminalgraphics/src/branch/dev

______________________________________________
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel

Reply via email to