I love the new Print feature. But, when I do need to print a page I need to first go in and change my color scheme to one that has a white background and good contrast. It would be super convenient if there were a preference where users could specify a different color scheme for when the page is sent to the browser for rendering/printing.
Print color scheme preference
It is pretty easy to write a wrapper command around html_print
(The command behind File -> Print
) to first change the color scheme to something you want (without affecting your global color scheme).
import sublime
import sublime_plugin
class CustomPrintCommand(sublime_plugin.WindowCommand):
def run(self, color_scheme = None):
# If we are not provided with a color scheme, then simply run the print command
# with the current color scheme.
if color_scheme is None:
self.window.run_command("html_print")
return
# We first load the required settings file.
preferences = sublime.load_settings("Preferences.sublime-settings")
# We get the current color scheme so that we have a record of it.
current_color_scheme = preferences.get("color_scheme")
# If we don't find the color_scheme resource, we bail out.
if len(sublime.find_resources(color_scheme)) == 0:
sublime.status_message("No color scheme {} found".format(color_scheme))
return
preferences.set("color_scheme", color_scheme)
# We then print the current view.
self.window.run_command("html_print")
# Once the print is done, we set back the old color scheme.
preferences.set("color_scheme", current_color_scheme)
Save the above file as a python file with any name you want in the User
directory. You can then either have a key binding for it, a menu item, a command palette item, anything that makes you comfortable.
An example key binding for it (You can set the color scheme using the color_scheme
argument)
{
"keys": ["ctrl+shift+u"],
"command": "custom_print",
"args": {
"color_scheme": "Material (Palenight).sublime-color-scheme"
},
},
2 Likes