summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Slenders <jonathan@slenders.be>2018-05-22 22:39:59 +0200
committerJonathan Slenders <jonathan@slenders.be>2018-05-22 22:39:59 +0200
commit529edb45efadfc732f84791f6a835a0dc9f5467b (patch)
tree7c025fc19d4f4e9f9900bfd634e884b1f1702fb8
parent2d3beb9d8918358d85ee95642098c7bf47e68754 (diff)
Added hello-world.py and hello-world-asyncio.py full screen examples.
-rwxr-xr-xexamples/full-screen/hello-world-asyncio.py51
-rwxr-xr-xexamples/full-screen/hello-world.py44
2 files changed, 95 insertions, 0 deletions
diff --git a/examples/full-screen/hello-world-asyncio.py b/examples/full-screen/hello-world-asyncio.py
new file mode 100755
index 00000000..99490209
--- /dev/null
+++ b/examples/full-screen/hello-world-asyncio.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+"""
+A simple example of a a text area displaying "Hello World!".
+"""
+from __future__ import unicode_literals
+from prompt_toolkit.application import Application
+from prompt_toolkit.eventloop import use_asyncio_event_loop
+from prompt_toolkit.key_binding import KeyBindings
+from prompt_toolkit.layout import Layout
+from prompt_toolkit.widgets import Box, Frame, TextArea
+import asyncio
+
+# Layout for displaying hello world.
+# (The frame creates the border, the box takes care of the margin/padding.)
+root_container = Box(
+ Frame(TextArea(
+ text='Hello world!\nPress control-c to quit.',
+ width=40,
+ height=10,
+ )),
+)
+layout = Layout(container=root_container)
+
+
+# Key bindings.
+kb = KeyBindings()
+
+@kb.add('c-c')
+def _(event):
+ " Quit when control-c is pressed. "
+ event.app.exit()
+
+
+# Build a main application object.
+application = Application(
+ layout=layout,
+ key_bindings=kb,
+ full_screen=True)
+
+
+def main():
+ # Tell prompt_toolkit to use asyncio.
+ use_asyncio_event_loop()
+
+ # Run application async.
+ asyncio.get_event_loop().run_until_complete(
+ application.run_async().to_asyncio_future())
+
+
+if __name__ == '__main__':
+ main()
diff --git a/examples/full-screen/hello-world.py b/examples/full-screen/hello-world.py
new file mode 100755
index 00000000..2f1eab79
--- /dev/null
+++ b/examples/full-screen/hello-world.py
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+"""
+A simple example of a a text area displaying "Hello World!".
+"""
+from __future__ import unicode_literals
+from prompt_toolkit.application import Application
+from prompt_toolkit.key_binding import KeyBindings
+from prompt_toolkit.layout import Layout
+from prompt_toolkit.widgets import Box, Frame, TextArea
+
+# Layout for displaying hello world.
+# (The frame creates the border, the box takes care of the margin/padding.)
+root_container = Box(
+ Frame(TextArea(
+ text='Hello world!\nPress control-c to quit.',
+ width=40,
+ height=10,
+ )),
+)
+layout = Layout(container=root_container)
+
+
+# Key bindings.
+kb = KeyBindings()
+
+@kb.add('c-c')
+def _(event):
+ " Quit when control-c is pressed. "
+ event.app.exit()
+
+
+# Build a main application object.
+application = Application(
+ layout=layout,
+ key_bindings=kb,
+ full_screen=True)
+
+
+def main():
+ application.run()
+
+
+if __name__ == '__main__':
+ main()