-
Notifications
You must be signed in to change notification settings - Fork 753
Closed
Labels
Description
I've got so far as the code below but the cursor is not moving. Am I heading in the wrong direction?
from prompt_toolkit.layout.containers import Window
from prompt_toolkit.layout.controls import TokenListControl
from prompt_toolkit.layout.margins import ScrollbarMargin
from prompt_toolkit.key_binding.manager import KeyBindingManager
from prompt_toolkit.token import Token
from prompt_toolkit.keys import Keys
from prompt_toolkit.filters.utils import to_cli_filter
from prompt_toolkit.application import Application
from prompt_toolkit.shortcuts import create_eventloop
from prompt_toolkit.interface import CommandLineInterface
manager = KeyBindingManager()
def getItemList(cli):
tokens = []
for i in range(100):
tokens.append((Token.Item, str(i)))
tokens.append((Token.NewLine, '\n'))
return tokens
@manager.registry.add_binding(Keys.ControlQ, eager=True)
def _(event):
event.cli.set_return_value(None)
itemsControl = TokenListControl(get_tokens=getItemList, has_focus=True)
@manager.registry.add_binding(Keys.Down, eager=True)
def onArrowDown(cli):
itemsControl.move_cursor_down(cli)
display_arrows = to_cli_filter(True)
app = Application(
layout=Window(content=itemsControl, right_margins=[ScrollbarMargin(display_arrows=display_arrows)]),
buffers={},
key_bindings_registry=manager.registry,
mouse_support=True,
use_alternate_screen=True
)
eventloop = create_eventloop()
cli = CommandLineInterface(application=app, eventloop=eventloop)
cli.run()