summaryrefslogtreecommitdiffstats
path: root/examples/full-screen/scrollable-panes
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 17:35:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 17:35:20 +0000
commite106bf94eff07d9a59771d9ccc4406421e18ab64 (patch)
treeedb6545500e39df9c67aa918a6125bffc8ec1aee /examples/full-screen/scrollable-panes
parentInitial commit. (diff)
downloadprompt-toolkit-e106bf94eff07d9a59771d9ccc4406421e18ab64.tar.xz
prompt-toolkit-e106bf94eff07d9a59771d9ccc4406421e18ab64.zip
Adding upstream version 3.0.36.upstream/3.0.36upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'examples/full-screen/scrollable-panes')
-rw-r--r--examples/full-screen/scrollable-panes/simple-example.py45
-rw-r--r--examples/full-screen/scrollable-panes/with-completion-menu.py120
2 files changed, 165 insertions, 0 deletions
diff --git a/examples/full-screen/scrollable-panes/simple-example.py b/examples/full-screen/scrollable-panes/simple-example.py
new file mode 100644
index 0000000..4606479
--- /dev/null
+++ b/examples/full-screen/scrollable-panes/simple-example.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+"""
+A simple example of a scrollable pane.
+"""
+from prompt_toolkit.application import Application
+from prompt_toolkit.application.current import get_app
+from prompt_toolkit.key_binding import KeyBindings
+from prompt_toolkit.key_binding.bindings.focus import focus_next, focus_previous
+from prompt_toolkit.layout import Dimension, HSplit, Layout, ScrollablePane
+from prompt_toolkit.widgets import Frame, Label, TextArea
+
+
+def main():
+ # Create a big layout of many text areas, then wrap them in a `ScrollablePane`.
+ root_container = Frame(
+ ScrollablePane(
+ HSplit(
+ [
+ Frame(TextArea(text=f"label-{i}"), width=Dimension())
+ for i in range(20)
+ ]
+ )
+ )
+ # ScrollablePane(HSplit([TextArea(text=f"label-{i}") for i in range(20)]))
+ )
+
+ layout = Layout(container=root_container)
+
+ # Key bindings.
+ kb = KeyBindings()
+
+ @kb.add("c-c")
+ def exit(event) -> None:
+ get_app().exit()
+
+ kb.add("tab")(focus_next)
+ kb.add("s-tab")(focus_previous)
+
+ # Create and run application.
+ application = Application(layout=layout, key_bindings=kb, full_screen=True)
+ application.run()
+
+
+if __name__ == "__main__":
+ main()
diff --git a/examples/full-screen/scrollable-panes/with-completion-menu.py b/examples/full-screen/scrollable-panes/with-completion-menu.py
new file mode 100644
index 0000000..fba8d17
--- /dev/null
+++ b/examples/full-screen/scrollable-panes/with-completion-menu.py
@@ -0,0 +1,120 @@
+#!/usr/bin/env python
+"""
+A simple example of a scrollable pane.
+"""
+from prompt_toolkit.application import Application
+from prompt_toolkit.application.current import get_app
+from prompt_toolkit.completion import WordCompleter
+from prompt_toolkit.key_binding import KeyBindings
+from prompt_toolkit.key_binding.bindings.focus import focus_next, focus_previous
+from prompt_toolkit.layout import (
+ CompletionsMenu,
+ Float,
+ FloatContainer,
+ HSplit,
+ Layout,
+ ScrollablePane,
+ VSplit,
+)
+from prompt_toolkit.widgets import Frame, Label, TextArea
+
+
+def main():
+ # Create a big layout of many text areas, then wrap them in a `ScrollablePane`.
+ root_container = VSplit(
+ [
+ Label("<left column>"),
+ HSplit(
+ [
+ Label("ScrollContainer Demo"),
+ Frame(
+ ScrollablePane(
+ HSplit(
+ [
+ Frame(
+ TextArea(
+ text=f"label-{i}",
+ completer=animal_completer,
+ )
+ )
+ for i in range(20)
+ ]
+ )
+ ),
+ ),
+ ]
+ ),
+ ]
+ )
+
+ root_container = FloatContainer(
+ root_container,
+ floats=[
+ Float(
+ xcursor=True,
+ ycursor=True,
+ content=CompletionsMenu(max_height=16, scroll_offset=1),
+ ),
+ ],
+ )
+
+ layout = Layout(container=root_container)
+
+ # Key bindings.
+ kb = KeyBindings()
+
+ @kb.add("c-c")
+ def exit(event) -> None:
+ get_app().exit()
+
+ kb.add("tab")(focus_next)
+ kb.add("s-tab")(focus_previous)
+
+ # Create and run application.
+ application = Application(
+ layout=layout, key_bindings=kb, full_screen=True, mouse_support=True
+ )
+ application.run()
+
+
+animal_completer = WordCompleter(
+ [
+ "alligator",
+ "ant",
+ "ape",
+ "bat",
+ "bear",
+ "beaver",
+ "bee",
+ "bison",
+ "butterfly",
+ "cat",
+ "chicken",
+ "crocodile",
+ "dinosaur",
+ "dog",
+ "dolphin",
+ "dove",
+ "duck",
+ "eagle",
+ "elephant",
+ "fish",
+ "goat",
+ "gorilla",
+ "kangaroo",
+ "leopard",
+ "lion",
+ "mouse",
+ "rabbit",
+ "rat",
+ "snake",
+ "spider",
+ "turkey",
+ "turtle",
+ ],
+ ignore_case=True,
+)
+
+
+if __name__ == "__main__":
+ main()