boon

unix terminal framework
git clone https://git.ce9e.org/boon.git

commit
f2892ea8e72a7cd79a44cf61f06c9adfeb3b7738
parent
389dedb4026c1dfa8edc25539c6db3154f0fdbd3
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2020-07-11 16:18
add new example

Diffstat

A example.py 35 +++++++++++++++++++++++++++++++++++

1 files changed, 35 insertions, 0 deletions


diff --git a/example.py b/example.py

@@ -0,0 +1,35 @@
   -1     1 import sys
   -1     2 
   -1     3 import boon
   -1     4 
   -1     5 
   -1     6 class Example(boon.App):
   -1     7 	items = ['Foo', 'Bar', 'Baz']
   -1     8 
   -1     9 	def __init__(self):
   -1    10 		super().__init__()
   -1    11 		self.selection = 0
   -1    12 
   -1    13 	def render(self):
   -1    14 		for i in range((self.rows - 3) // 2):
   -1    15 			yield ''
   -1    16 
   -1    17 		template = '{:^%i}' % self.cols
   -1    18 		for i, item in enumerate(self.items):
   -1    19 			centered = template.format(item)
   -1    20 			if i == self.selection:
   -1    21 				yield boon.get_cap('rev') + centered + boon.get_cap('sgr0')
   -1    22 			else:
   -1    23 				yield centered
   -1    24 
   -1    25 	def on_key(self, key):
   -1    26 		if key == boon.KEY_UP:
   -1    27 			self.selection -= 1
   -1    28 		elif key == boon.KEY_DOWN:
   -1    29 			self.selection += 1
   -1    30 		elif key in ['q', '\n']:
   -1    31 			sys.exit(0)
   -1    32 
   -1    33 
   -1    34 example = Example()
   -1    35 example.run()