当前位置: 首页>>代码示例>>Python>>正文


Python Terminal.clear方法代码示例

本文整理汇总了Python中blessed.Terminal.clear方法的典型用法代码示例。如果您正苦于以下问题:Python Terminal.clear方法的具体用法?Python Terminal.clear怎么用?Python Terminal.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在blessed.Terminal的用法示例。


在下文中一共展示了Terminal.clear方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: reset

# 需要导入模块: from blessed import Terminal [as 别名]
# 或者: from blessed.Terminal import clear [as 别名]
def reset(term: Terminal):
    print(term.clear())
    print(term.move(0, 0))
开发者ID:hsharrison,项目名称:bistable-perception-experiment,代码行数:5,代码来源:experiment.py

示例2: monitor

# 需要导入模块: from blessed import Terminal [as 别名]
# 或者: from blessed.Terminal import clear [as 别名]
def monitor(run_once=False, broker=None):
    if not broker:
        broker = get_broker()
    term = Terminal()
    broker.ping()
    with term.fullscreen(), term.hidden_cursor(), term.cbreak():
        val = None
        start_width = int(term.width / 8)
        while val not in (u'q', u'Q',):
            col_width = int(term.width / 8)
            # In case of resize
            if col_width != start_width:
                print(term.clear())
                start_width = col_width
            print(term.move(0, 0) + term.black_on_green(term.center(_('Host'), width=col_width - 1)))
            print(term.move(0, 1 * col_width) + term.black_on_green(term.center(_('Id'), width=col_width - 1)))
            print(term.move(0, 2 * col_width) + term.black_on_green(term.center(_('State'), width=col_width - 1)))
            print(term.move(0, 3 * col_width) + term.black_on_green(term.center(_('Pool'), width=col_width - 1)))
            print(term.move(0, 4 * col_width) + term.black_on_green(term.center(_('TQ'), width=col_width - 1)))
            print(term.move(0, 5 * col_width) + term.black_on_green(term.center(_('RQ'), width=col_width - 1)))
            print(term.move(0, 6 * col_width) + term.black_on_green(term.center(_('RC'), width=col_width - 1)))
            print(term.move(0, 7 * col_width) + term.black_on_green(term.center(_('Up'), width=col_width - 1)))
            i = 2
            stats = Stat.get_all(broker=broker)
            print(term.clear_eos())
            for stat in stats:
                status = stat.status
                # color status
                if stat.status == Conf.WORKING:
                    status = term.green(str(Conf.WORKING))
                elif stat.status == Conf.STOPPING:
                    status = term.yellow(str(Conf.STOPPING))
                elif stat.status == Conf.STOPPED:
                    status = term.red(str(Conf.STOPPED))
                elif stat.status == Conf.IDLE:
                    status = str(Conf.IDLE)
                # color q's
                tasks = str(stat.task_q_size)
                if stat.task_q_size > 0:
                    tasks = term.cyan(str(stat.task_q_size))
                    if Conf.QUEUE_LIMIT and stat.task_q_size == Conf.QUEUE_LIMIT:
                        tasks = term.green(str(stat.task_q_size))
                results = stat.done_q_size
                if results > 0:
                    results = term.cyan(str(results))
                # color workers
                workers = len(stat.workers)
                if workers < Conf.WORKERS:
                    workers = term.yellow(str(workers))
                # format uptime
                uptime = (timezone.now() - stat.tob).total_seconds()
                hours, remainder = divmod(uptime, 3600)
                minutes, seconds = divmod(remainder, 60)
                uptime = '%d:%02d:%02d' % (hours, minutes, seconds)
                # print to the terminal
                print(term.move(i, 0) + term.center(stat.host[:col_width - 1], width=col_width - 1))
                print(term.move(i, 1 * col_width) + term.center(stat.cluster_id, width=col_width - 1))
                print(term.move(i, 2 * col_width) + term.center(status, width=col_width - 1))
                print(term.move(i, 3 * col_width) + term.center(workers, width=col_width - 1))
                print(term.move(i, 4 * col_width) + term.center(tasks, width=col_width - 1))
                print(term.move(i, 5 * col_width) + term.center(results, width=col_width - 1))
                print(term.move(i, 6 * col_width) + term.center(stat.reincarnations, width=col_width - 1))
                print(term.move(i, 7 * col_width) + term.center(uptime, width=col_width - 1))
                i += 1
            # bottom bar
            i += 1
            queue_size = broker.queue_size()
            lock_size = broker.lock_size()
            if lock_size:
                queue_size = '{}({})'.format(queue_size, lock_size)
            print(term.move(i, 0) + term.white_on_cyan(term.center(broker.info(), width=col_width * 2)))
            print(term.move(i, 2 * col_width) + term.black_on_cyan(term.center(_('Queued'), width=col_width)))
            print(term.move(i, 3 * col_width) + term.white_on_cyan(term.center(queue_size, width=col_width)))
            print(term.move(i, 4 * col_width) + term.black_on_cyan(term.center(_('Success'), width=col_width)))
            print(term.move(i, 5 * col_width) + term.white_on_cyan(
                term.center(models.Success.objects.count(), width=col_width)))
            print(term.move(i, 6 * col_width) + term.black_on_cyan(term.center(_('Failures'), width=col_width)))
            print(term.move(i, 7 * col_width) + term.white_on_cyan(
                term.center(models.Failure.objects.count(), width=col_width)))
            # for testing
            if run_once:
                return Stat.get_all(broker=broker)
            print(term.move(i + 2, 0) + term.center(_('[Press q to quit]')))
            val = term.inkey(timeout=1)
开发者ID:Koed00,项目名称:django-q,代码行数:86,代码来源:monitor.py

示例3: CalculonDisplay

# 需要导入模块: from blessed import Terminal [as 别名]
# 或者: from blessed.Terminal import clear [as 别名]
class CalculonDisplay (object):
    def __init__(self):
        self.term = Terminal()
        print(self.term.enter_fullscreen())

        # parse config
        self.config = self.init_config(config)
        self.bin_mode = self.config['bin_mode']
        self.cur_bin_mode = None
        self.bits = self.config['bits']
        self.formats = self.config['formats']
        self.align = self.config['align']
        self.padding = self.config['padding']
        self.attrs = self.config['attrs']

        self.header = 'calculon'
        self.show_header = True

        # Watched variables
        self.lastval = 0

        # Watched expressions
        self.exprs = []

        self.draw_state = {
            'header': True, 'value': True, 'vallabel': True, 'binlabel': True,
            'varlabel': True, 'varvalue': True, 'exprlabel': True, 'exprvalue': True,
            'all': True
        }

        # set initial value
        self.update_value(0)

    @Pyro4.expose
    def are_you_there(self):
        return True

    def init_config(self, config):
        # update text attributes
        for sec in config['attrs']:
            config['attrs'][sec] = ''.join(['{t.' + x + '}' for x in config['attrs'][sec]])

        return config

    def set_win(self, win, repl_win):
        self.win = win
        self.repl_win = repl_win
        self.update_value(0)
        self.redraw()

    def update_bin_mode(self):
        # detect bin display mode
        old_mode = self.cur_bin_mode
        if self.bin_mode == "auto":
            self.cur_bin_mode = "wide" if self.term.width >= BIN_MODE_WIDTH_WIDE else "narrow"
        if self.cur_bin_mode != old_mode:
            self.draw_state['all'] = True

        # round up bits to nearest row
        self.bin_row = BIN_MODE_ROW_NARROW if self.cur_bin_mode == "narrow" else BIN_MODE_ROW_WIDE
        if self.bits % self.bin_row > 0:
            self.bits += self.bin_row - (self.bits % self.bin_row)

    @Pyro4.expose
    def update_value(self, value):
        self.lastval = value
        self.draw_state['value'] = True
        self.redraw()

    @Pyro4.expose
    def set_exprs(self, values):
        self.exprs = values
        self.draw_state['exprvalue'] = True
        self.draw_state['exprlabel'] = True
        self.redraw()

    @Pyro4.expose
    def redraw(self, all=False):
        global needs_redraw

        self.update_bin_mode()

        if all or needs_redraw:
            self.draw_state['all'] = True
            needs_redraw = False
        if self.draw_state['all']:
            print(self.term.clear())
        if self.draw_state['header'] or self.draw_state['all']:
            self.draw_header()
            self.draw_state['header'] = False
        if self.draw_state['value'] or self.draw_state['all']:
            self.clear_value()
            self.draw_value()
            self.draw_binary()
            self.draw_state['value'] = False
        if self.draw_state['vallabel'] or self.draw_state['all']:
            self.draw_value_labels()
            self.draw_binary_labels()
            self.draw_state['vallabel'] = False
        if self.draw_state['exprlabel'] or self.draw_state['all']:
#.........这里部分代码省略.........
开发者ID:snare,项目名称:calculon,代码行数:103,代码来源:display.py


注:本文中的blessed.Terminal.clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。