Commit 29c97003 authored by Christopher Olah's avatar Christopher Olah

Fancy configurable prompts!

* Prompts are now generated based off of string templates,
  for example: "%(bold)sT:%(extruder_temp_fancy)s %(progress_fancy)s
  >%(normal)s "

* We have a dictionary of prompt string templates for different
  situations.

* We have bold support for the prompt.

* We have extruder temperature support for the prompt.

* We have progress support for the prompt.
parent 92821f7e
...@@ -261,20 +261,45 @@ class pronsole(cmd.Cmd): ...@@ -261,20 +261,45 @@ class pronsole(cmd.Cmd):
self.webrequested = False self.webrequested = False
self.web_config = None self.web_config = None
self.web_auth_config = None self.web_auth_config = None
self.promptstrs = {"offline" : "%(bold)suninitialized>%(normal)s ",
"fallback" : "%(bold)sPC>%(normal)s ",
"macro" : "%(bold)s..>%(normal)s ",
"online" : "%(bold)sT:%(extruder_temp_fancy)s %(progress_fancy)s >%(normal)s "}
def promptf(self): def promptf(self):
"""A function to generate prompts so that we can do dynamic prompts. """ """A function to generate prompts so that we can do dynamic prompts. """
if self.in_macro: if self.in_macro:
return "..>" promptstr = self.promptstrs["macro"]
elif not self.p.online: elif not self.p.online:
return "uninitialized>" promptstr = self.promptstrs["offline"]
elif self.status.extruder_enabled and self.dynamic_temp: elif self.status.extruder_enabled:
promptstr = self.promptstrs["online"]
else:
promptstr = self.promptstrs["fallback"]
if not "%" in promptstr:
return promptstr
else:
specials = {}
specials["extruder_temp"] = str(int(self.status.extruder_temp))
specials["extruder_temp_target"] = str(int(self.status.extruder_temp_target))
if self.status.extruder_temp_target == 0: if self.status.extruder_temp_target == 0:
return "T:%s>" % self.status.extruder_temp specials["extruder_temp_fancy"] = str(int(self.status.extruder_temp))
else:
specials["extruder_temp_fancy"] = "%s/%s" % (str(int(self.status.extruder_temp)), str(int(self.status.extruder_temp_target)))
if self.p.printing:
progress = int(1000*float(self.p.queueindex)/len(self.p.mainqueue)) / 10
elif self.sdprinting:
progress = self.percentdone
else: else:
return "T:%s/%s>" % (self.status.extruder_temp, self.status.extruder_temp_target) progress = 0.0
specials["progress"] = str(progress)
if self.p.printing or self.sdprinting:
specials["progress_fancy"] = str(progress) +"%"
else: else:
return "printer>" specials["progress_fancy"] = "?%"
specials["bold"] = "\033[01m"
specials["normal"] = "\033[00m"
return promptstr % specials
def postcmd(self, stop, line): def postcmd(self, stop, line):
""" A hook we override to generate prompts after """ A hook we override to generate prompts after
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment