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


Python Terminal.raw方法代码示例

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


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

示例1: main

# 需要导入模块: from blessed import Terminal [as 别名]
# 或者: from blessed.Terminal import raw [as 别名]
def main():
    """
    Displays all known key capabilities that may match the terminal.
    As each key is pressed on input, it is lit up and points are scored.
    """
    try:
        from x84.bbs import getterminal, echo

        term = getterminal()
    except (ImportError, AttributeError):
        from blessed import Terminal
        import sys

        term = Terminal()

        def echo(text):
            sys.stdout.write(u"{}".format(text))
            sys.stdout.flush()

    echo(u"".join((term.normal, term.height * u"\r\n", term.home, term.clear_eos)))

    with term.raw():
        inp = u""
        echo(u"Press Q to exit.\r\n")
        while inp.upper() != "Q":
            inp = term.inkey(timeout=10.0)
            disp_inp = inp.__str__() if inp.is_sequence else inp
            echo(u"{0!r}: code={1!r} name={2!r}\r\n".format(disp_inp, inp.code, inp.name))
开发者ID:gofore,项目名称:x84,代码行数:30,代码来源:test_keyboard_keys.py

示例2: main

# 需要导入模块: from blessed import Terminal [as 别名]
# 或者: from blessed.Terminal import raw [as 别名]
def main(logfilepath):
    
    term = Terminal()
    mngr = Manager(term, num_divisions=1, logfilepath=logfilepath)
    
    cursor, scrn = mngr.get_focus_cursor_and_screen()
    
    with term.hidden_cursor(), \
            term.raw(), \
            term.location(), \
            term.fullscreen(), \
            term.keypad():
        inp = None
        
        while True:
            inp = term.inkey(timeout=0.2)
            
            if inp != u'':
                signal = mngr.handle_input(inp)
                
                if signal == -1:
                    # got exit signal
                    break
            
            mngr.draw()
            
            if mngr.logger != None:
                mngr.logger.write_to_file()
开发者ID:bmer,项目名称:proofor,代码行数:30,代码来源:editor.py

示例3: main

# 需要导入模块: from blessed import Terminal [as 别名]
# 或者: from blessed.Terminal import raw [as 别名]
def main():
    """Program entry point."""
    term = Terminal()
    score = level = hit_highbit = hit_unicode = 0
    dirty = True

    gameboard = build_gameboard(term)
    inps = []

    with term.raw(), term.keypad(), term.location():
        inp = term.inkey(timeout=0)
        while inp != chr(3):
            if dirty:
                refresh(term, gameboard, level, score, inps)
                dirty = False
            inp = term.inkey(timeout=5.0)
            dirty = True
            if (inp.is_sequence and
                    inp.name in gameboard and
                    0 == gameboard[inp.name]['hit']):
                gameboard[inp.name]['hit'] = 1
                score, level = add_score(score, 100, level)
            elif inp and not inp.is_sequence and 128 <= ord(inp) <= 255:
                hit_highbit += 1
                if hit_highbit < 5:
                    score, level = add_score(score, 100, level)
            elif inp and not inp.is_sequence and ord(inp) > 256:
                hit_unicode += 1
                if hit_unicode < 5:
                    score, level = add_score(score, 100, level)
            inps.append(inp)

    with term.cbreak():
        echo(term.move(term.height))
        echo(
            u'{term.clear_eol}Your final score was {score} '
            u'at level {level}{term.clear_eol}\n'
            u'{term.clear_eol}\n'
            u'{term.clear_eol}You hit {hit_highbit} '
            u' 8-bit characters\n{term.clear_eol}\n'
            u'{term.clear_eol}You hit {hit_unicode} '
            u' unicode characters.\n{term.clear_eol}\n'
            u'{term.clear_eol}press any key\n'.format(
                term=term,
                score=score, level=level,
                hit_highbit=hit_highbit,
                hit_unicode=hit_unicode)
        )
        term.inkey()
开发者ID:thomasballinger,项目名称:blessed,代码行数:51,代码来源:keymatrix.py

示例4: main

# 需要导入模块: from blessed import Terminal [as 别名]
# 或者: from blessed.Terminal import raw [as 别名]
def main():
    term = Terminal()
    csr = Cursor(0, 0, term)
    screen = {}
    with term.hidden_cursor(), \
            term.raw(), \
            term.location(), \
            term.fullscreen(), \
            term.keypad():
        inp = None
        while True:
            echo_yx(csr, term.reverse(screen.get((csr.y, csr.x), u' ')))
            inp = term.inkey()

            if inp == chr(3):
                # ^c exits
                break

            elif inp == chr(19):
                # ^s saves
                echo_yx(home(bottom(csr)),
                        term.ljust(term.bold_white('Filename: ')))
                echo_yx(right_of(home(bottom(csr)), len('Filename: ')), u'')
                save(screen, readline(term))
                echo_yx(home(bottom(csr)), term.clear_eol)
                redraw(term=term, screen=screen,
                       start=home(bottom(csr)),
                       end=end(bottom(csr)))
                continue

            elif inp == chr(12):
                # ^l refreshes
                redraw(term=term, screen=screen)

            n_csr = lookup_move(inp.code, csr, term)
            if n_csr != csr:
                # erase old cursor,
                echo_yx(csr, screen.get((csr.y, csr.x), u' '))
                csr = n_csr

            elif not inp.is_sequence and inp.isprintable():
                echo_yx(csr, inp)
                screen[(csr.y, csr.x)] = inp.__str__()
                n_csr = right_of(csr, 1)
                if n_csr == csr:
                    # wrap around margin
                    n_csr = home(below(csr, 1))
                csr = n_csr
开发者ID:JamesWKerr,项目名称:blessed,代码行数:50,代码来源:editor.py

示例5: main

# 需要导入模块: from blessed import Terminal [as 别名]
# 或者: from blessed.Terminal import raw [as 别名]
def main():
    """
    Displays all known key capabilities that may match the terminal.
    As each key is pressed on input, it is lit up and points are scored.
    """
    term = Terminal()
    score = level = hit_highbit = hit_unicode = 0
    dirty = True

    def refresh(term, board, level, score, inp):
        sys.stdout.write(term.home + term.clear)
        level_color = level % 7
        if level_color == 0:
            level_color = 4
        bottom = 0
        for keycode, attr in board.items():
            sys.stdout.write(u''.join((
                term.move(attr['row'], attr['column']),
                term.color(level_color),
                (term.reverse if attr['hit'] else term.bold),
                keycode,
                term.normal)))
            bottom = max(bottom, attr['row'])
        sys.stdout.write(term.move(term.height, 0)
                         + 'level: %s score: %s' % (level, score,))
        sys.stdout.flush()
        if bottom >= (term.height - 5):
            sys.stderr.write(
                '\n' * (term.height / 2) +
                term.center(term.red_underline('cheater!')) + '\n')
            sys.stderr.write(
                term.center("(use a larger screen)") +
                '\n' * (term.height / 2))
            sys.exit(1)
        for row, inp in enumerate(inps[(term.height - (bottom + 2)) * -1:]):
            sys.stdout.write(term.move(bottom + row+1))
            sys.stdout.write('%r, %s, %s' % (inp.__str__() if inp.is_sequence
                                             else inp, inp.code, inp.name, ))
            sys.stdout.flush()

    def build_gameboard(term):
        column, row = 0, 0
        board = dict()
        spacing = 2
        for keycode in sorted(term._keycodes.values()):
            if (keycode.startswith('KEY_F')
                    and keycode[-1].isdigit()
                    and int(keycode[len('KEY_F'):]) > 24):
                continue
            if column + len(keycode) + (spacing * 2) >= term.width:
                column = 0
                row += 1
            board[keycode] = {'column': column,
                              'row': row,
                              'hit': 0,
                              }
            column += len(keycode) + (spacing * 2)
        return board

    def add_score(score, pts, level):
        lvl_multiplier = 10
        score += pts
        if 0 == (score % (pts * lvl_multiplier)):
            level += 1
        return score, level

    gb = build_gameboard(term)
    inps = []

    with term.raw():
        inp = term.inkey(timeout=0)
        while inp.upper() != 'Q':
            if dirty:
                refresh(term, gb, level, score, inps)
                dirty = False
            inp = term.inkey(timeout=5.0)
            dirty = True
            if (inp.is_sequence and
                    inp.name in gb and
                    0 == gb[inp.name]['hit']):
                gb[inp.name]['hit'] = 1
                score, level = add_score(score, 100, level)
            elif inp and not inp.is_sequence and 128 <= ord(inp) <= 255:
                hit_highbit += 1
                if hit_highbit < 5:
                    score, level = add_score(score, 100, level)
            elif inp and not inp.is_sequence and ord(inp) > 256:
                hit_unicode += 1
                if hit_unicode < 5:
                    score, level = add_score(score, 100, level)
            inps.append(inp)

    with term.cbreak():
        sys.stdout.write(u''.join((
            term.move(term.height),
            term.clear_eol,
            u'Your final score was %s' % (score,),
            u' at level %s' % (level,),
            term.clear_eol,
            u'\n',
#.........这里部分代码省略.........
开发者ID:lowks,项目名称:blessed,代码行数:103,代码来源:test_keyboard_keys.py

示例6: Terminal

# 需要导入模块: from blessed import Terminal [as 别名]
# 或者: from blessed.Terminal import raw [as 别名]
signal handler.  Meanwhile, blocking keyboard input is displayed to stdout.
If a resize event is discovered, an empty string is returned by term.inkey()
when _intr_continue is False, as it is here.
"""
import signal
from blessed import Terminal

term = Terminal()


def on_resize(sig, action):
    # Its generally not a good idea to put blocking functions (such as print)
    # within a signal handler -- if another SIGWINCH is recieved while this
    # function blocks, an error will occur. In most programs, you'll want to
    # set some kind of 'dirty' flag, perhaps by a Semaphore or global variable.
    print('height={t.height}, width={t.width}\r'.format(t=term))

signal.signal(signal.SIGWINCH, on_resize)

# note that, a terminal driver actually writes '\r\n' when '\n' is found, but
# in raw mode, we are allowed to write directly to the terminal without the
# interference of such driver -- so we must write \r\n ourselves; as python
# will append '\n' to our print statements, we simply end our statements with
# \r.
with term.raw():
    print("press 'X' to stop.\r")
    inp = None
    while inp != 'X':
        inp = term.inkey(_intr_continue=False)
        print(repr(inp) + u'\r')
开发者ID:JamesWKerr,项目名称:blessed,代码行数:32,代码来源:on_resize.py

示例7: right_of

# 需要导入模块: from blessed import Terminal [as 别名]
# 或者: from blessed.Terminal import raw [as 别名]
    b.term.KEY_RIGHT: right_of(b, 1),
    b.term.KEY_DOWN: below(b, 1),
    b.term.KEY_UP: above(b, 1),
    # shift + arrows
    b.term.KEY_SLEFT: left_of(b, 10),
    b.term.KEY_SRIGHT: right_of(b, 10),
    b.term.KEY_SDOWN: below(b, 10),
    b.term.KEY_SUP: above(b, 10),
    # carriage return
    b.term.KEY_ENTER: home(below(b, 1)),
    b.term.KEY_HOME: home(b),
}.get(inp_code, b)

term = Terminal()
csr = Cursor(1, 1, term)
with term.hidden_cursor(), term.raw(), term.location(), term.fullscreen():
    inp = None
    while True:
        echo_xy(csr, term.reverse(u' '))
        inp = term.inkey()
        if inp.code == term.KEY_ESCAPE or inp == chr(3):
            break
        echo_xy(csr, u' ')
        n_csr = lookup_move(inp.code, csr)
        if n_csr != csr:
            echo_xy(n_csr, u' ')
            csr = n_csr
        elif not inp.is_sequence:
            echo_xy(csr, inp)
            csr = right_of(csr, 1)
开发者ID:lowks,项目名称:blessed,代码行数:32,代码来源:dumb_fse.py

示例8: main

# 需要导入模块: from blessed import Terminal [as 别名]
# 或者: from blessed.Terminal import raw [as 别名]
def main():
    """Program entry point."""
    above = lambda csr, n: (
        Cursor(y=max(0, csr.y - n),
               x=csr.x,
               term=csr.term))

    below = lambda csr, n: (
        Cursor(y=min(csr.term.height - 1, csr.y + n),
               x=csr.x,
               term=csr.term))

    right_of = lambda csr, n: (
        Cursor(y=csr.y,
               x=min(csr.term.width - 1, csr.x + n),
               term=csr.term))

    left_of = lambda csr, n: (
        Cursor(y=csr.y,
               x=max(0, csr.x - n),
               term=csr.term))

    home = lambda csr: (
        Cursor(y=csr.y,
               x=0,
               term=csr.term))

    end = lambda csr: (
        Cursor(y=csr.y,
               x=csr.term.width - 1,
               term=csr.term))

    bottom = lambda csr: (
        Cursor(y=csr.term.height - 1,
               x=csr.x,
               term=csr.term))

    center = lambda csr: Cursor(
        csr.term.height // 2,
        csr.term.width // 2,
        csr.term)

    lookup_move = lambda inp_code, csr, term: {
        # arrows, including angled directionals
        csr.term.KEY_END: below(left_of(csr, 1), 1),
        csr.term.KEY_KP_1: below(left_of(csr, 1), 1),

        csr.term.KEY_DOWN: below(csr, 1),
        csr.term.KEY_KP_2: below(csr, 1),

        csr.term.KEY_PGDOWN: below(right_of(csr, 1), 1),
        csr.term.KEY_LR: below(right_of(csr, 1), 1),
        csr.term.KEY_KP_3: below(right_of(csr, 1), 1),

        csr.term.KEY_LEFT: left_of(csr, 1),
        csr.term.KEY_KP_4: left_of(csr, 1),

        csr.term.KEY_CENTER: center(csr),
        csr.term.KEY_KP_5: center(csr),

        csr.term.KEY_RIGHT: right_of(csr, 1),
        csr.term.KEY_KP_6: right_of(csr, 1),

        csr.term.KEY_HOME: above(left_of(csr, 1), 1),
        csr.term.KEY_KP_7: above(left_of(csr, 1), 1),

        csr.term.KEY_UP: above(csr, 1),
        csr.term.KEY_KP_8: above(csr, 1),

        csr.term.KEY_PGUP: above(right_of(csr, 1), 1),
        csr.term.KEY_KP_9: above(right_of(csr, 1), 1),

        # shift + arrows
        csr.term.KEY_SLEFT: left_of(csr, 10),
        csr.term.KEY_SRIGHT: right_of(csr, 10),
        csr.term.KEY_SDOWN: below(csr, 10),
        csr.term.KEY_SUP: above(csr, 10),

        # carriage return
        csr.term.KEY_ENTER: home(below(csr, 1)),
    }.get(inp_code, csr)

    term = Terminal()
    csr = Cursor(0, 0, term)
    screen = {}
    with term.hidden_cursor(), \
            term.raw(), \
            term.location(), \
            term.fullscreen(), \
            term.keypad():
        inp = None
        while True:
            echo_yx(csr, term.reverse(screen.get((csr.y, csr.x), u' ')))
            inp = term.inkey()

            if inp == chr(3):
                # ^c exits
                break

            elif inp == chr(19):
#.........这里部分代码省略.........
开发者ID:cjfuller,项目名称:blessed,代码行数:103,代码来源:editor.py

示例9: main

# 需要导入模块: from blessed import Terminal [as 别名]
# 或者: from blessed.Terminal import raw [as 别名]
def main(argv=None):
    """ Execute the application CLI.

    Arguments are taken from sys.argv by default.

    """

    args = _cmdline(argv)
    logger.start(args.logging_level)
    logger.debug("starting execution")

    #  get repo and initialize GitHeat instance
    try:
        g = Git(os.getcwd())
    except (InvalidGitRepositoryError, GitCommandError, GitCommandNotFound):
        print("Are you sure you're in an initialized git directory?")
        return 0
    githeat = Githeat(g, **vars(args))
    githeat.parse_commits()
    githeat.init_daily_contribution_map()
    githeat.compute_daily_contribution_map()
    githeat.normalize_daily_contribution_map()
    matrix = githeat.compute_graph_matrix()

    term = Terminal()
    matrix_width = githeat.get_matrix_width(matrix)
    if matrix_width > term.width:
        print("Your terminal width is smaller than the heatmap. Please consider using "
              "the --width {thin, reg, thick} argument, resizing your terminal, or "
              "merging months by including --month-merge.")
        return 0
    new_width = (term.width - matrix_width) // 2
    csr = Cursor(term.height // 2 - 3, new_width, term)

    screen = {}
    screen_dates = {}
    with term.hidden_cursor(), \
         term.raw(), \
         term.location(), \
         term.fullscreen(), \
         term.keypad():

        # Print header
        print_header_left(term, unicode(os.getcwd()), screen)
        text = u'GitHeat {}'.format(__version__)
        print_header_center(term, text, screen)
        text = u'ESC, ^c to exit'
        print_header_right(term, text, screen)

        # Print footer
        text = u'Please move cursor to navigate through map'
        print_footer_left(term, term.bold(text), screen)

        graph_right_most_x = term.width  # initialized at terminal width
        graph_left_most_x = csr.x
        graph_top_most_y = csr.y
        graph_x, graph_y = csr.x, csr.y

        #  get graph boundaries
        for i in range(7):
            #  for the week column in the matrix
            for week in matrix:
                if githeat.month_merge:
                    #  check if value in that week is just empty spaces and not colorize
                    if week.col[i][1] == githeat.width:
                        continue
                graph_x += len(githeat.width)

            graph_right_most_x = graph_x
            graph_x = graph_left_most_x  # reset x
            graph_y += 1
        graph_bottom_most_y = graph_y - 1

        #  print graph
        graph_x, graph_y = csr.x, csr.y
        print_graph(term, screen, screen_dates, graph_x, graph_y,
                    graph_left_most_x, matrix, githeat)

        # print legend
        block_separation_width = 4
        legend_x = (term.width - len(githeat.colors) * block_separation_width) // 2
        legend_y = graph_bottom_most_y + 5
        if not githeat.hide_legend:
            print_graph_legend(legend_x, legend_y,
                               githeat.width,
                               block_separation_width,
                               githeat.colors,
                               screen,
                               term)

        while True:
            cursor_color = colorize(githeat.width, ansi=15, ansi_bg=15)
            echo_yx(csr, cursor_color)
            inp = term.inkey()

            if inp in QUIT_KEYS:
                # Esc or ^c pressed
                break
            elif inp == chr(99):
                # c pressed, thus change color
#.........这里部分代码省略.........
开发者ID:AmmsA,项目名称:Githeat,代码行数:103,代码来源:interactive.py

示例10: main

# 需要导入模块: from blessed import Terminal [as 别名]
# 或者: from blessed.Terminal import raw [as 别名]
def main():
    term = Terminal()
    worm = [Location(x=term.width // 2, y=term.height // 2)]
    worm_length = 2
    bearing = Direction(*LEFT)
    direction = left_of
    nibble = Nibble(location=worm[0], value=0)
    color_nibble = term.black_on_green
    color_worm = term.yellow_reverse
    color_head = term.red_reverse
    color_bg = term.on_blue
    echo(term.move(1, 1))
    echo(color_bg(term.clear))

    # speed is actually a measure of time; the shorter, the faster.
    speed = 0.1
    modifier = 0.93
    inp = None

    with term.hidden_cursor(), term.raw():
        while inp not in (u"q", u"Q"):

            # delete the tail of the worm at worm_length
            if len(worm) > worm_length:
                echo(term.move(*worm.pop(0)))
                echo(color_bg(u" "))

            # compute head location
            head = worm.pop()

            # check for hit against self; hitting a wall results in the (y, x)
            # location being clipped, -- and death by hitting self (not wall).
            if hit_any(head, worm):
                break

            # get the next nibble, which may be equal to ours unless this
            # nibble has been struck by any portion of our worm body.
            n_nibble = next_nibble(term, nibble, head, worm)

            # get the next worm_length and speed, unless unchanged.
            worm_length = next_wormlength(nibble, head, worm_length)
            speed = next_speed(nibble, head, speed, modifier)

            if n_nibble != nibble:
                # erase the old one, careful to redraw the nibble contents
                # with a worm color for those portions that overlay.
                for (y, x) in nibble_locations(*nibble):
                    echo(term.move(y, x) + (color_worm if (y, x) == head else color_bg)(u" "))
                    echo(term.normal)
                # and draw the new,
                echo(term.move(*n_nibble.location) + (color_nibble("{}".format(n_nibble.value))))

            # display new worm head
            echo(term.move(*head) + color_head(head_glyph(direction)))

            # and its old head (now, a body piece)
            if worm:
                echo(term.move(*(worm[-1])))
                echo(color_worm(u" "))
            echo(term.move(*head))

            # wait for keyboard input, which may indicate
            # a new direction (up/down/left/right)
            inp = term.inkey(speed)

            # discover new direction, given keyboard input and/or bearing.
            nxt_direction = next_bearing(term, inp.code, bearing)

            # discover new bearing, given new direction compared to prev
            nxt_bearing = change_bearing(nxt_direction, head, term)

            # disallow new bearing/direction when flipped (running into
            # oneself, fe. travelling left while traveling right)
            if not bearing_flipped(bearing, nxt_bearing):
                direction = nxt_direction
                bearing = nxt_bearing

            # append the prior `head' onto the worm, then
            # a new `head' for the given direction.
            worm.extend([head, direction(head, term)])

            # re-assign new nibble,
            nibble = n_nibble

    echo(term.normal)
    score = (worm_length - 1) * 100
    echo(u"".join((term.move(term.height - 1, 1), term.normal)))
    echo(u"".join((u"\r\n", u"score: {}".format(score), u"\r\n")))
开发者ID:JamesWKerr,项目名称:blessed,代码行数:90,代码来源:worms.py


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