boon

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

commit
df85dc5246e262840e4464370b66351fe1bd2f25
parent
c459460c7b54f9e84eac07ae96709aa20b5778fd
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2020-07-13 04:50
pass rows/cols to render()

Diffstat

M README.md 8 ++------
M boon.py 4 ++--
M example.py 6 +++---

3 files changed, 7 insertions, 11 deletions


diff --git a/README.md b/README.md

@@ -21,7 +21,7 @@ low level API or a third party library such as
   21    21 import boon
   22    22 
   23    23 class Example(boon.App):
   24    -1   def render(self):
   -1    24   def render(self, rows, cols):
   25    25     yield 'Hello World'
   26    26 
   27    27   def on_key(self, key):
@@ -43,11 +43,7 @@ Call to start the main loop.
   43    43 
   44    44 Set to `False` to stop the main loop.
   45    45 
   46    -1 ### `App.rows` / `App.cols`
   47    -1 
   48    -1 The current size of the terminal.
   49    -1 
   50    -1 ### `App.render()`
   -1    46 ### `App.render(rows, cols)`
   51    47 
   52    48 Overwrite to define your view. For every line in the UI, this functions should
   53    49 yield a string.

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

@@ -104,7 +104,7 @@ class App:
  104   104 		signal.signal(signal.SIGWINCH, self.on_resize)
  105   105 
  106   106 	def update(self):
  107    -1 		lines = list(self.render())
   -1   107 		lines = list(self.render(self.rows, self.cols))
  108   108 		for i, line in enumerate(lines):
  109   109 			if len(self.old_lines) > i and line == self.old_lines[i]:
  110   110 				continue
@@ -133,7 +133,7 @@ class App:
  133   133 					self.on_key(key)
  134   134 					self.update()
  135   135 
  136    -1 	def render(self):
   -1   136 	def render(self, rows, cols):
  137   137 		return []
  138   138 
  139   139 	def on_key(self, key):

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

@@ -10,11 +10,11 @@ class Example(boon.App):
   10    10 		super().__init__()
   11    11 		self.selection = 0
   12    12 
   13    -1 	def render(self):
   14    -1 		for i in range((self.rows - 3) // 2):
   -1    13 	def render(self, rows, cols):
   -1    14 		for i in range((rows - 3) // 2):
   15    15 			yield ''
   16    16 
   17    -1 		template = '{:^%i}' % self.cols
   -1    17 		template = '{:^%i}' % cols
   18    18 		for i, item in enumerate(self.items):
   19    19 			centered = template.format(item)
   20    20 			if i == self.selection: