From 167736ad1c127735806ba06858bc74c8ce6d49df Mon Sep 17 00:00:00 2001 From: chestwood96 Date: Thu, 30 Jun 2022 19:56:35 +0200 Subject: [PATCH] respond: No forced spaces (#5152) Signed-off-by: Adrian Joachim --- docs/G-Codes.md | 2 ++ klippy/extras/respond.py | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/G-Codes.md b/docs/G-Codes.md index 78949980..afa808c8 100644 --- a/docs/G-Codes.md +++ b/docs/G-Codes.md @@ -1010,6 +1010,8 @@ The following additional commands are also available. configured default prefix (or `echo: ` if no prefix is configured). - `RESPOND TYPE=echo MSG=""`: echo the message prepended with `echo: `. +- `RESPOND TYPE=echo_no_space MSG=""`: echo the message prepended with + `echo:` without a space between prefix and message, helpful for compatibility with some octoprint plugins that expect very specific formatting. - `RESPOND TYPE=command MSG=""`: echo the message prepended with `// `. OctoPrint can be configured to respond to these messages (e.g. `RESPOND TYPE=command MSG=action:pause`). diff --git a/klippy/extras/respond.py b/klippy/extras/respond.py index fb6eb194..047abb77 100644 --- a/klippy/extras/respond.py +++ b/klippy/extras/respond.py @@ -10,6 +10,10 @@ respond_types = { 'error' : '!!', } +respond_types_no_space = { + 'echo_no_space': 'echo:', +} + class HostResponder: def __init__(self, config): self.printer = config.get_printer() @@ -26,19 +30,26 @@ class HostResponder: gcmd.respond_raw("%s %s" % (self.default_prefix, msg)) cmd_RESPOND_help = ("Echo the message prepended with a prefix") def cmd_RESPOND(self, gcmd): + no_space = False respond_type = gcmd.get('TYPE', None) prefix = self.default_prefix if(respond_type != None): respond_type = respond_type.lower() if(respond_type in respond_types): prefix = respond_types[respond_type] + elif(respond_type in respond_types_no_space): + prefix = respond_types_no_space[respond_type] + no_space = True else: raise gcmd.error( "RESPOND TYPE '%s' is invalid. Must be one" " of 'echo', 'command', or 'error'" % (respond_type,)) prefix = gcmd.get('PREFIX', prefix) msg = gcmd.get('MSG', '') - gcmd.respond_raw("%s %s" % (prefix, msg)) + if(no_space): + gcmd.respond_raw("%s%s" % (prefix, msg)) + else: + gcmd.respond_raw("%s %s" % (prefix, msg)) def load_config(config): return HostResponder(config)