Extend RESPOND command with some color options

This macro extend the original Klipper RESPOND command by adding a COLOR parameter.

The COLOR parameter adds a css class on the MSG content. Those css classes are already available on Mainsail.

This has been designed to work on Mainsail but it should work on Fluidd as well.

[gcode_macro RESPOND]
rename_existing: BASE_RESPOND
gcode:
  {% set colors = ('primary', 'secondary', 'accent', 'info', 'success', 'error', 'warning') %}

  {% if params.PREFIX is defined %}
    {% set prefix = 'PREFIX=' + params.PREFIX|string %}
  {% endif %}

  {% if params.TYPE is defined %}
      {% if params.TYPE in ('echo', 'echo_no_space', 'command', 'error') and params.TYPE != '' %}    
          {% set type = 'TYPE=' + params.TYPE|string %}
      {% else %}
          BASE_RESPOND TYPE=error MSG="RESPOND TYPE '{params.TYPE}' is invalid. Must be one of 'echo', 'command' or 'error'"
      {% endif %}
  {% endif %}
        
  {% if params.MSG is defined %}   
    {% set msg = 'MSG="'+ params.MSG + '"'|string %}
  {% endif %}

  {% if params.COLOR is defined %}
      {% set color = params.COLOR|lower %}

      {% if color in colors %}
          {% set msg = 'MSG="<span class=' + color + '--text>' + params.MSG + '</span>"'|string %}
  
      {% else %}
          BASE_RESPOND TYPE=error MSG="RESPOND COLOR '{color}' is invalid. Must be one of 'primary', 'secondary', 'accent', 'info', 'success', 'warning' or 'error'"
      {% endif %}
       
  {% endif %}
  BASE_RESPOND {prefix} {type} {msg}

Here is a little preview of the different combinations of messages that you can obtain with this macro. Those are the default colors of Mainsail and they can be changed easily with few lines of css too.

Enjoy :smiley:

3 Likes