Example #1
0
File: main.py Project: lge/crmsh
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
Example #2
0
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
Example #3
0
 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
Example #4
0
 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
Example #5
0
            common_err(msg)
            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: