本文整理汇总了Python中blessed.Terminal.ljust方法的典型用法代码示例。如果您正苦于以下问题:Python Terminal.ljust方法的具体用法?Python Terminal.ljust怎么用?Python Terminal.ljust使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blessed.Terminal
的用法示例。
在下文中一共展示了Terminal.ljust方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from blessed import Terminal [as 别名]
# 或者: from blessed.Terminal import ljust [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
示例2: main
# 需要导入模块: from blessed import Terminal [as 别名]
# 或者: from blessed.Terminal import ljust [as 别名]
#.........这里部分代码省略.........
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):
# ^s saves
echo_yx(home(bottom(csr)),
term.ljust(term.bold_white(u'Filename: ')))
echo_yx(right_of(home(bottom(csr)), len(u'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)
else:
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 input_filter(inp):
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