def render_prompt(context): rendered_prompt = constants.prompt if options.interactive and not options.batch: # TODO: fix how color interacts with readline, # seems the color prompt messes it up promptstr = "crm(%s)%s# " % (cib_prompt(), context.prompt()) constants.prompt = promptstr if clidisplay.colors_enabled(): rendered_prompt = term.render(clidisplay.prompt(promptstr)) else: rendered_prompt = promptstr return rendered_prompt
def help(cls, topic, helptxt): if cls.lasttopic == topic and \ time.time() - cls.laststamp < cls.timeout: return if helptxt: import readline cmdline = readline.get_line_buffer() print "\n%s" % helptxt if clidisplay.colors_enabled(): print "%s%s" % (term.render(clidisplay.prompt_noreadline(constants.prompt)), cmdline), else: print "%s%s" % (constants.prompt, cmdline), cls.laststamp = time.time() cls.lasttopic = topic
def help(cls, topic, helptxt): if cls.lasttopic == topic and \ time.time() - cls.laststamp < cls.timeout: return if helptxt: import readline cmdline = readline.get_line_buffer() print "\n%s" % helptxt if clidisplay.colors_enabled(): print "%s%s" % (term.render( clidisplay.prompt_noreadline(constants.prompt)), cmdline), else: print "%s%s" % (constants.prompt, cmdline), cls.laststamp = time.time() cls.lasttopic = topic
def print_node(uname, id, node_type, other, inst_attr, offline): """ Try to pretty print a node from the cib. Sth like: uname(id): node_type attr1=v1 attr2=v2 """ s_offline = offline and "(offline)" or "" if not node_type: node_type = "normal" if uname == id: print term.render("%s: %s%s" % (uname, node_type, s_offline)) else: print term.render("%s(%s): %s%s" % (uname, id, node_type, s_offline)) for a in other: print term.render("\t%s: %s" % (a, other[a])) for s in inst_attr: print term.render("\t%s" % (s))
def term_render(s): 'Render for TERM.' try: return term.render(s) except: return s
usage(2) if options.interactive and not options.batch: context.setup_readline() rc = 0 while True: try: rendered_prompt = constants.prompt if options.interactive and not options.batch: # TODO: fix how color interacts with readline, # seems the color prompt messes it up promptstr = "crm(%s)%s# " % (cib_prompt(), context.prompt()) constants.prompt = promptstr if clidisplay.colors_enabled(): rendered_prompt = term.render(clidisplay.prompt(promptstr)) else: rendered_prompt = promptstr inp = utils.multi_input(rendered_prompt) if inp is None: if options.interactive: rc = 0 context.quit(rc) try: if not context.run(inp): rc = 1 except ValueError, msg: rc = 1 common_err(msg) except KeyboardInterrupt: if options.interactive and not options.batch: