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


Python Terminal.reverse方法代码示例

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


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

示例1: main

# 需要导入模块: from blessed import Terminal [as 别名]
# 或者: from blessed.Terminal import reverse [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

示例2: Console

# 需要导入模块: from blessed import Terminal [as 别名]
# 或者: from blessed.Terminal import reverse [as 别名]

#.........这里部分代码省略.........
        bulbs[self.markedLine - 2].marked = self.moveMode
        self.renderScreen()

    def markDown(self):
        bulbs = self.ledBulbs.orderedBulbs()
        bulb1 = bulbs[self.markedLine - 2]
        if bulb1.marked == 2:
            bulb2 = None
            for bulb in bulbs:
                if bulb.marked == 1:
                    bulb2 = bulb
            for bulb in bulbs:
                bulb.marked = 0

            if bulb2 != None:
                bulb2.marked = 1
            else:
                bulb1.marked = 1
        else:
            for bulb in bulbs:
                bulb.marked = 0
        self.markedLine += 1
        if self.markedLine > self.topLine - 1:
            self.markedLine = self.topLine - 1
        bulbs[self.markedLine - 2].marked = self.moveMode
        self.renderScreen()

    def brightnessUp(self):
        if self.config.brightness + 1 > 31:
            self.config.brightness = 31
        else:
            self.config.brightness += 1
            self.renderScreen()

    def brightnessDown(self):
        if self.config.brightness - 1 < 1:
            self.config.brightness = 1
        else:
            self.config.brightness -= 1
            self.renderScreen()

    def animationNext(self):
        idx = self.animations.currAnimation
        idx = (idx + 1) % self.animations.numAnimations
        self.animations.currAnimation = idx
        self.renderScreen()

    def animationPrev(self):
        idx = self.animations.currAnimation
        idx = (idx - 1) % self.animations.numAnimations
        self.animations.currAnimation = idx
        self.renderScreen()

    def toggleMoveMode(self, targetMode=None):
        if targetMode != None:
            self.moveMode = targetMode
        else:
            self.moveMode = (self.moveMode + 1) % 3

        if self.moveMode == 0:
            for bulb in self.ledBulbs.bulbs.values():
                bulb.marked = self.moveMode
        elif self.moveMode == 1:
            self.ledBulbs.orderedBulbs()[self.markedLine - 2].marked = self.moveMode
        elif self.moveMode == 2:
            self.ledBulbs.orderedBulbs()[self.markedLine - 2].marked = self.moveMode
        self.renderScreen()

    def printTop(self, str, revLine=False):
        with self.t.location(0, self.topLine):
            if revLine:
                print(self.t.reverse(str))
            else:
                print(str)
            self.topLine += 1

    def printBottom(self, str):
        with self.t.location(0, self.t.height - 2):
            print(str)

    def printKeymap(self):
        with self.t.location(0, self.t.height - 1):
            pass

    def printStatus(self):
        with self.t.location(0, self.t.height - 1):
            status = u"Brightness: {0}{1} ".format(SYMBOL_ARROW_UP, SYMBOL_ARROW_DOWN)
            status += (self.t.bold + "%s  " + self.t.normal) % (str(self.config.brightness).ljust(2))
            status += u"Animation: {0} ".format(SYMBOL_ARROW_LEFT_RIGHT)
            animName = self.animations.animation().__class__.__name__
            status += (self.t.bold + "%s   " + self.t.normal) % (animName.ljust(4))
            print(status)

        with self.t.location(0, self.t.height):
            status = ""
            status += ("HTTP port: " + self.t.bold + "%s   " + self.t.normal) % (str(self.config.http_port).ljust(4))
            status += ("Receive port: " + self.t.bold + "%s   " + self.t.normal) % (
                str(self.config.receive_port).ljust(4)
            )
            print(status)
开发者ID:robertfoss,项目名称:esp8266_apa102_bulb,代码行数:104,代码来源:Console.py

示例3: right_of

# 需要导入模块: from blessed import Terminal [as 别名]
# 或者: from blessed.Terminal import reverse [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

示例4: main

# 需要导入模块: from blessed import Terminal [as 别名]
# 或者: from blessed.Terminal import reverse [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


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