prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.11k stars 717 forks source link

Scrollbar does not react on mouse #284

Open certik opened 8 years ago

certik commented 8 years ago

I tested the code from https://github.com/jonathanslenders/python-prompt-toolkit/issues/281#issuecomment-217122767, i.e.:

from __future__ import unicode_literals
from prompt_toolkit.application import Application
from prompt_toolkit.buffer import Buffer
from prompt_toolkit.document import Document
from prompt_toolkit.enums import DEFAULT_BUFFER
from prompt_toolkit.interface import CommandLineInterface
from prompt_toolkit.key_binding.manager import KeyBindingManager
from prompt_toolkit.keys import Keys
from prompt_toolkit.layout.containers import Window
from prompt_toolkit.layout.controls import BufferControl
from prompt_toolkit.layout.margins import ScrollbarMargin
from prompt_toolkit.shortcuts import create_eventloop

manager = KeyBindingManager()

def get_default_text():
    return '\n'.join('%s' % i for i in range(100))

@manager.registry.add_binding(Keys.ControlQ, eager=True)
@manager.registry.add_binding(Keys.ControlC, eager=True)
def _(event):
    event.cli.set_return_value(None)

app = Application(
    layout=Window(
        content=BufferControl(buffer_name=DEFAULT_BUFFER),
        right_margins=[ScrollbarMargin(display_arrows=True)]),
    buffers={
        DEFAULT_BUFFER: Buffer(
            initial_document=Document(get_default_text(), 0))
    },
    key_bindings_registry=manager.registry,
    mouse_support=True,
    use_alternate_screen=True
)

eventloop = create_eventloop()
try:
    cli = CommandLineInterface(application=app, eventloop=eventloop)
    cli.run(reset_current_buffer=False)
finally:
    eventloop.close()

and it shows a scrollbar on the right, but even though mouse_support is enabled, no matter how I click or drag on the scrollbar, nothing happens.

Mouse support itself works, e.g. in examples/mouse-support.py.

jonathanslenders commented 8 years ago

@certik,

Mouse support for scroll bars has indeed not yet been implemented. Dragging won't be for very soon, but adding click support is not difficult. Keeping this issue open as a feature request.

Jonathan

certik commented 8 years ago

236 is for the mouse clicks, and this issue is also for the dragging.