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


Python Terminal.move_x方法代码示例

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


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

示例1: main

# 需要导入模块: from blessed import Terminal [as 别名]
# 或者: from blessed.Terminal import move_x [as 别名]
def main():
    """Program entry point."""
    term = Terminal()
    assert term.hpa(1) != u'', (
        'Terminal does not support hpa (Horizontal position absolute)')

    col, offset = 1, 1
    with term.cbreak():
        inp = None
        print("press 'X' to stop.")
        sys.stderr.write(term.move(term.height, 0) + u'[')
        sys.stderr.write(term.move_x(term.width) + u']' + term.move_x(1))
        while inp != 'X':
            if col >= (term.width - 2):
                offset = -1
            elif col <= 1:
                offset = 1
            sys.stderr.write(term.move_x(col))
            if offset == -1:
                sys.stderr.write(u'.')
            else:
                sys.stderr.write(u'=')
            col += offset
            sys.stderr.write(term.move_x(col))
            sys.stderr.write(u'|\b')
            sys.stderr.flush()
            inp = term.inkey(0.04)
    print()
开发者ID:jquast,项目名称:blessed,代码行数:30,代码来源:progress_bar.py

示例2: main

# 需要导入模块: from blessed import Terminal [as 别名]
# 或者: from blessed.Terminal import move_x [as 别名]
def main():
    term = Terminal()
    term.stream.write('YO >')
    term.stream.flush()
    termHistory = history.CommandHistory()
    buffer = ''
    while True:    
        try: 
            with term.cbreak():
                char = term.inkey()
                if char.is_sequence:
                    if char.name == 'KEY_UP':
                        termHistory.increment_index()
                        buffer = termHistory.get_item()
                        term.stream.write(term.clear_bol)
                        term.stream.write(term.move_x(0))
                        term.stream.write('YO >')
                        term.stream.write(buffer)
                    elif char.name == 'KEY_DOWN':
                        termHistory.decrement_index()
                        buffer = termHistory.get_item()
                        term.stream.write(term.clear_bol)
                        term.stream.write(term.move_x(0))
                        term.stream.write(term.clear_bol + 'YO >')
                        term.stream.write(buffer)
                    elif char.name == 'KEY_DELETE':
                        buffer = buffer[ :-1 ]
                        term.stream.write(term.move_left)
                        term.stream.write(' ')
                        term.stream.write(term.move_left)
                    elif char.name == 'KEY_ENTER':
                        termHistory.add(buffer)
                        args = buffer.split(' ')
                        commands = separate_by_pipe(args)
                        term.stream.write('\n')
                        run_all_commands(commands, 1)
                        buffer = ''
                        term.stream.write('YO >')
        finally:
            if not char.is_sequence:
                buffer += char
                term.stream.write(char)
            term.stream.flush()
开发者ID:sfrapoport,项目名称:python-shell,代码行数:45,代码来源:shell_blessed.py

示例3: Terminal

# 需要导入模块: from blessed import Terminal [as 别名]
# 或者: from blessed.Terminal import move_x [as 别名]
import copy
import os
import sys
import io

from blessed import Terminal
try:
    from collections import OrderedDict
except ImportError:  # python 2.6
    from ordereddict import OrderedDict

from qifqif import tags
from qifqif.ui import diff, set_completer, complete_matches

TERM = Terminal()
CLEAR = TERM.move_up + TERM.move_x(0) + TERM.clear_eol
ENCODING = 'utf-8' if sys.stdin.encoding in (None, 'ascii') else \
    sys.stdin.encoding


def quick_input(prompt, choices=''):
    """Reads a line from input, converts it to a string (stripping a trailing
       newline), and returns that. If no input, returns default choice.
    """
    default = [x for x in choices if x.isupper()]
    default = default[0] if default else ''
    _input = raw_input('%s%s' % (prompt, (' [%s] ? ' % ','.join(choices)) if
                       choices else ': ')).decode(ENCODING)
    if _input in choices:
        _input = _input.upper()
    return _input or default
开发者ID:flywire,项目名称:qifqif,代码行数:33,代码来源:__init__.py

示例4: info

# 需要导入模块: from blessed import Terminal [as 别名]
# 或者: from blessed.Terminal import move_x [as 别名]
def info(broker=None):
    if not broker:
        broker = get_broker()
    term = Terminal()
    broker.ping()
    stat = Stat.get_all(broker=broker)
    # general stats
    clusters = len(stat)
    workers = 0
    reincarnations = 0
    for cluster in stat:
        workers += len(cluster.workers)
        reincarnations += cluster.reincarnations
    # calculate tasks pm and avg exec time
    tasks_per = 0
    per = _('day')
    exec_time = 0
    last_tasks = models.Success.objects.filter(stopped__gte=timezone.now() - timedelta(hours=24))
    tasks_per_day = last_tasks.count()
    if tasks_per_day > 0:
        # average execution time over the last 24 hours
        if not connection.vendor == 'sqlite':
            exec_time = last_tasks.aggregate(time_taken=Sum(F('stopped') - F('started')))
            exec_time = exec_time['time_taken'].total_seconds() / tasks_per_day
        else:
            # can't sum timedeltas on sqlite
            for t in last_tasks:
                exec_time += t.time_taken()
            exec_time = exec_time / tasks_per_day
        # tasks per second/minute/hour/day in the last 24 hours
        if tasks_per_day > 24 * 60 * 60:
            tasks_per = tasks_per_day / (24 * 60 * 60)
            per = _('second')
        elif tasks_per_day > 24 * 60:
            tasks_per = tasks_per_day / (24 * 60)
            per = _('minute')
        elif tasks_per_day > 24:
            tasks_per = tasks_per_day / 24
            per = _('hour')
        else:
            tasks_per = tasks_per_day
    # print to terminal
    print(term.clear_eos())
    col_width = int(term.width / 6)
    print(term.black_on_green(
        term.center(
            _('-- {} {} on {}  --').format(Conf.PREFIX.capitalize(), '.'.join(str(v) for v in VERSION),
                                           broker.info()))))
    print(term.cyan(_('Clusters')) +
          term.move_x(1 * col_width) +
          term.white(str(clusters)) +
          term.move_x(2 * col_width) +
          term.cyan(_('Workers')) +
          term.move_x(3 * col_width) +
          term.white(str(workers)) +
          term.move_x(4 * col_width) +
          term.cyan(_('Restarts')) +
          term.move_x(5 * col_width) +
          term.white(str(reincarnations))
          )
    print(term.cyan(_('Queued')) +
          term.move_x(1 * col_width) +
          term.white(str(broker.queue_size())) +
          term.move_x(2 * col_width) +
          term.cyan(_('Successes')) +
          term.move_x(3 * col_width) +
          term.white(str(models.Success.objects.count())) +
          term.move_x(4 * col_width) +
          term.cyan(_('Failures')) +
          term.move_x(5 * col_width) +
          term.white(str(models.Failure.objects.count()))
          )
    print(term.cyan(_('Schedules')) +
          term.move_x(1 * col_width) +
          term.white(str(models.Schedule.objects.count())) +
          term.move_x(2 * col_width) +
          term.cyan(_('Tasks/{}'.format(per))) +
          term.move_x(3 * col_width) +
          term.white('{0:.2f}'.format(tasks_per)) +
          term.move_x(4 * col_width) +
          term.cyan(_('Avg time')) +
          term.move_x(5 * col_width) +
          term.white('{0:.4f}'.format(exec_time))
          )
    return True
开发者ID:Koed00,项目名称:django-q,代码行数:87,代码来源:monitor.py

示例5: info

# 需要导入模块: from blessed import Terminal [as 别名]
# 或者: from blessed.Terminal import move_x [as 别名]
def info(r=redis_client):
    term = Terminal()
    ping_redis(r)
    stat = Stat.get_all(r)
    # general stats
    clusters = len(stat)
    workers = 0
    reincarnations = 0
    for cluster in stat:
        workers += len(cluster.workers)
        reincarnations += cluster.reincarnations
    # calculate tasks pm and avg exec time
    tasks_per = 0
    per = _("day")
    exec_time = 0
    last_tasks = models.Success.objects.filter(stopped__gte=timezone.now() - timedelta(hours=24))
    tasks_per_day = last_tasks.count()
    if tasks_per_day > 0:
        # average execution time over the last 24 hours
        if not connection.vendor == "sqlite":
            exec_time = last_tasks.aggregate(time_taken=Sum(F("stopped") - F("started")))
            exec_time = exec_time["time_taken"].total_seconds() / tasks_per_day
        else:
            # can't sum timedeltas on sqlite
            for t in last_tasks:
                exec_time += t.time_taken()
            exec_time = exec_time / tasks_per_day
        # tasks per second/minute/hour/day in the last 24 hours
        if tasks_per_day > 24 * 60 * 60:
            tasks_per = tasks_per_day / (24 * 60 * 60)
            per = _("second")
        elif tasks_per_day > 24 * 60:
            tasks_per = tasks_per_day / (24 * 60)
            per = _("minute")
        elif tasks_per_day > 24:
            tasks_per = tasks_per_day / 24
            per = _("hour")
        else:
            tasks_per = tasks_per_day
    # print to terminal
    term.clear_eos()
    col_width = int(term.width / 6)
    print(term.black_on_green(term.center(_("-- {} summary --").format(Conf.PREFIX))))
    print(
        term.cyan(_("Clusters"))
        + term.move_x(1 * col_width)
        + term.white(str(clusters))
        + term.move_x(2 * col_width)
        + term.cyan(_("Workers"))
        + term.move_x(3 * col_width)
        + term.white(str(workers))
        + term.move_x(4 * col_width)
        + term.cyan(_("Restarts"))
        + term.move_x(5 * col_width)
        + term.white(str(reincarnations))
    )
    print(
        term.cyan(_("Queued"))
        + term.move_x(1 * col_width)
        + term.white(str(r.llen(Conf.Q_LIST)))
        + term.move_x(2 * col_width)
        + term.cyan(_("Successes"))
        + term.move_x(3 * col_width)
        + term.white(str(models.Success.objects.count()))
        + term.move_x(4 * col_width)
        + term.cyan(_("Failures"))
        + term.move_x(5 * col_width)
        + term.white(str(models.Failure.objects.count()))
    )
    print(
        term.cyan(_("Schedules"))
        + term.move_x(1 * col_width)
        + term.white(str(models.Schedule.objects.count()))
        + term.move_x(2 * col_width)
        + term.cyan(_("Tasks/{}".format(per)))
        + term.move_x(3 * col_width)
        + term.white("{0:.2f}".format(tasks_per))
        + term.move_x(4 * col_width)
        + term.cyan(_("Avg time"))
        + term.move_x(5 * col_width)
        + term.white("{0:.4f}".format(exec_time))
    )
    return True
开发者ID:sebasmagri,项目名称:django-q,代码行数:85,代码来源:monitor.py


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