flexablelib-components 3.7.0__tar.gz → 3.7.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. {flexablelib_components-3.7.0/flexablelib_components.egg-info → flexablelib_components-3.7.1}/PKG-INFO +3 -3
  2. {flexablelib_components-3.7.0 → flexablelib_components-3.7.1}/flexablelib_components/__init__.py +1 -1
  3. {flexablelib_components-3.7.0 → flexablelib_components-3.7.1}/flexablelib_components/data.py +37 -9
  4. {flexablelib_components-3.7.0 → flexablelib_components-3.7.1}/flexablelib_components/dates.py +10 -1
  5. {flexablelib_components-3.7.0 → flexablelib_components-3.7.1}/flexablelib_components/display.py +12 -3
  6. {flexablelib_components-3.7.0 → flexablelib_components-3.7.1}/flexablelib_components/inputs.py +13 -0
  7. {flexablelib_components-3.7.0 → flexablelib_components-3.7.1}/flexablelib_components/navigation.py +54 -9
  8. {flexablelib_components-3.7.0 → flexablelib_components-3.7.1/flexablelib_components.egg-info}/PKG-INFO +3 -3
  9. flexablelib_components-3.7.1/flexablelib_components.egg-info/requires.txt +2 -0
  10. flexablelib_components-3.7.0/flexablelib_components.egg-info/requires.txt +0 -2
  11. {flexablelib_components-3.7.0 → flexablelib_components-3.7.1}/LICENSE +0 -0
  12. {flexablelib_components-3.7.0 → flexablelib_components-3.7.1}/MANIFEST.in +0 -0
  13. {flexablelib_components-3.7.0 → flexablelib_components-3.7.1}/README.md +0 -0
  14. {flexablelib_components-3.7.0 → flexablelib_components-3.7.1}/flexablelib_components/base.py +0 -0
  15. {flexablelib_components-3.7.0 → flexablelib_components-3.7.1}/flexablelib_components/media.py +0 -0
  16. {flexablelib_components-3.7.0 → flexablelib_components-3.7.1}/flexablelib_components/overlays.py +0 -0
  17. {flexablelib_components-3.7.0 → flexablelib_components-3.7.1}/flexablelib_components/py.typed +0 -0
  18. {flexablelib_components-3.7.0 → flexablelib_components-3.7.1}/flexablelib_components.egg-info/SOURCES.txt +0 -0
  19. {flexablelib_components-3.7.0 → flexablelib_components-3.7.1}/flexablelib_components.egg-info/dependency_links.txt +0 -0
  20. {flexablelib_components-3.7.0 → flexablelib_components-3.7.1}/flexablelib_components.egg-info/top_level.txt +0 -0
  21. {flexablelib_components-3.7.0 → flexablelib_components-3.7.1}/setup.cfg +0 -0
  22. {flexablelib_components-3.7.0 → flexablelib_components-3.7.1}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flexablelib-components
3
- Version: 3.7.0
3
+ Version: 3.7.1
4
4
  Summary: Interactive terminal components for flexablelib: inputs, dates, tables, forms, menus, tabs, dialogs and more.
5
5
  Home-page: https://github.com/Opus-Perpetuus/flexablelib
6
6
  Author: Benjamin Ramirez
@@ -17,8 +17,8 @@ Classifier: Topic :: Software Development :: User Interfaces
17
17
  Requires-Python: >=3.8
18
18
  Description-Content-Type: text/markdown
19
19
  License-File: LICENSE
20
- Requires-Dist: flexablelib>=3.7.0
21
- Requires-Dist: flexablelib-tui>=3.7.0
20
+ Requires-Dist: flexablelib>=3.7.1
21
+ Requires-Dist: flexablelib-tui>=3.7.1
22
22
  Dynamic: author
23
23
  Dynamic: author-email
24
24
  Dynamic: classifier
@@ -18,7 +18,7 @@ keys to the focused component) and also renders on its own with
18
18
  ``render(width)``. See docs/COMPONENTS.md.
19
19
  """
20
20
 
21
- __version__ = '3.7.0'
21
+ __version__ = '3.7.1'
22
22
 
23
23
  from .base import Theme, DEFAULT_THEME, Input, Box, Button, frame
24
24
  from .inputs import (TextInput, PasswordInput, NumberInput, ExpressionInput,
@@ -405,7 +405,12 @@ class DataTable(_Themed):
405
405
  extra = (1 if self.status else 0) + (1 if self.typing or self.query
406
406
  else 0)
407
407
  rows_h = self.height or (height - 2 - extra if height else None)
408
+ room = None
408
409
  if self.page_size:
410
+ # A page taller than the slot scrolls inside the page, so the
411
+ # cursor row stays on screen.
412
+ room = max(1, rows_h) if rows_h is not None and \
413
+ rows_h < self.page_size else None
409
414
  rows_h = self.page_size
410
415
  if rows_h is None:
411
416
  rows_h = len(view)
@@ -414,13 +419,27 @@ class DataTable(_Themed):
414
419
  self.cursor_row = max(0, min(self.cursor_row, len(view) - 1))
415
420
  if self.page_size:
416
421
  self.page = self.cursor_row // self.page_size + 1
417
- self.top = (self.page - 1) * self.page_size
422
+ start = (self.page - 1) * self.page_size
423
+ if room is None:
424
+ self.top = start
425
+ else:
426
+ end = min(len(view), start + self.page_size)
427
+ top = max(start, min(self.top, end - room))
428
+ if self.cursor_row < top:
429
+ top = self.cursor_row
430
+ elif self.cursor_row >= top + room:
431
+ top = self.cursor_row - room + 1
432
+ self.top = max(start, top)
433
+ rows_h = room
418
434
  else:
419
435
  if self.cursor_row < self.top:
420
436
  self.top = self.cursor_row
421
437
  if self.cursor_row >= self.top + rows_h:
422
438
  self.top = self.cursor_row - rows_h + 1
423
- shown = view[self.top:self.top + rows_h]
439
+ stop = self.top + rows_h
440
+ if self.page_size:
441
+ stop = min(stop, (self.page) * self.page_size)
442
+ shown = view[self.top:stop]
424
443
  if not view:
425
444
  if self.focused:
426
445
  # Focus on an empty table: a marker and reverse video, not
@@ -883,11 +902,13 @@ class CatalogGrid(_Themed):
883
902
  self.paint, style='heavy' if selected else 'rounded')
884
903
 
885
904
  def _card_rows(self):
886
- return self.card_height + self._picture_rows()
905
+ # A card is at least its border and one line inside.
906
+ return max(3, (self.card_height or 0) + self._picture_rows())
887
907
 
888
908
  def draw(self, width, height):
889
909
  card_rows = self._card_rows()
890
- cols = max(1, (width + 1) // (self.min_width + 1))
910
+ step = max(1, (self.min_width or 0) + 1)
911
+ cols = max(1, (width + 1) // step)
891
912
  self._columns = cols
892
913
  card_w = (width - (cols - 1)) // cols
893
914
  n_rows = int(math.ceil(len(self.items) / float(cols)))
@@ -1154,6 +1175,8 @@ class Form(_Themed):
1154
1175
  if self.min_column_width:
1155
1176
  cols = min(cols, max(1, (width + 2) //
1156
1177
  (self.min_column_width + 2)))
1178
+ # Never more columns than get one cell each.
1179
+ cols = min(cols, (width + 2) // 3)
1157
1180
  return max(1, cols)
1158
1181
 
1159
1182
  def _next_from(self, field):
@@ -1321,11 +1344,16 @@ class Form(_Themed):
1321
1344
  def flush():
1322
1345
  if not pending:
1323
1346
  return
1324
- n = len(pending)
1325
- each = (width - 2 * (n - 1)) // n
1326
- blocks = [p.render(width=each).split('\n') for p in pending]
1327
- out.extend(join_columns(blocks, [each] * n, gap=2))
1328
- out.append('')
1347
+ # At most as many side by side as get one cell each: a narrow
1348
+ # form stacks the rest below instead of failing.
1349
+ fit = max(1, (width + 2) // 3)
1350
+ for start in range(0, len(pending), fit):
1351
+ chunk = pending[start:start + fit]
1352
+ n = len(chunk)
1353
+ each = (width - 2 * (n - 1)) // n
1354
+ blocks = [p.render(width=each).split('\n') for p in chunk]
1355
+ out.extend(join_columns(blocks, [each] * n, gap=2))
1356
+ out.append('')
1329
1357
  del pending[:]
1330
1358
  for row in self.rows:
1331
1359
  if len(row) == 1 and isinstance(row[0], str):
@@ -991,6 +991,7 @@ class Stopwatch(Input):
991
991
  self.precision = max(0, min(3, int(precision)))
992
992
  self.max_laps = max_laps
993
993
  self.laps = []
994
+ self._lap_count = 0
994
995
  self._accum = 0.0
995
996
  self._since = None
996
997
  super(Stopwatch, self).__init__(label=label, value=value, **kwargs)
@@ -1050,6 +1051,7 @@ class Stopwatch(Input):
1050
1051
  return False
1051
1052
  split = self.value
1052
1053
  self.laps.append(split)
1054
+ self._lap_count += 1
1053
1055
  if self.max_laps:
1054
1056
  del self.laps[:-int(self.max_laps)]
1055
1057
  if self.on_lap is not None:
@@ -1061,6 +1063,7 @@ class Stopwatch(Input):
1061
1063
  self._accum = 0.0
1062
1064
  self._since = self.clock() if self._since is not None else None
1063
1065
  self.laps = []
1066
+ self._lap_count = 0
1064
1067
  if self.on_change is not None:
1065
1068
  self.on_change(self.value)
1066
1069
  self.refresh()
@@ -1121,7 +1124,13 @@ class Stopwatch(Input):
1121
1124
  ' · l: vuelta · r: reiniciar',
1122
1125
  self.theme.muted)
1123
1126
  out = [line]
1124
- for n, split in enumerate(self.laps[-5:], max(1, len(self.laps) - 4)):
1127
+ shown = self.laps[-5:]
1128
+ # Numbered by lap, also when max_laps dropped the first ones (and
1129
+ # when laps was set from code).
1130
+ total = len(self.laps)
1131
+ if self.max_laps and self._lap_count > total:
1132
+ total = self._lap_count
1133
+ for n, split in enumerate(shown, total - len(shown) + 1):
1125
1134
  out.append(' {0:>2}. {1}'.format(n, self.format_duration(
1126
1135
  split.total_seconds(), self.precision)))
1127
1136
  return out
@@ -1276,6 +1276,9 @@ class LineChart(_Themed):
1276
1276
 
1277
1277
 
1278
1278
 
1279
+ _LINE_BREAKS = re.compile('[\t\n\v\f\r\x1c-\x1e\x85\u2028\u2029]+')
1280
+
1281
+
1279
1282
  class StatusLine(_Themed):
1280
1283
  """
1281
1284
  A one-line status bar with ``left``, ``center`` and ``right`` text
@@ -1302,7 +1305,8 @@ class StatusLine(_Themed):
1302
1305
  @staticmethod
1303
1306
  def _value(part):
1304
1307
  part = part() if callable(part) else part
1305
- return '' if part is None else str(part)
1308
+ # One line: line breaks and tabs in a part become spaces.
1309
+ return '' if part is None else _LINE_BREAKS.sub(' ', str(part))
1306
1310
 
1307
1311
  def parts(self):
1308
1312
  """``(left, center, right)`` as text."""
@@ -1350,8 +1354,13 @@ class StatusLine(_Themed):
1350
1354
  if self.kind:
1351
1355
  left = _a11y.status_symbol(self.kind) + ' ' + left
1352
1356
  left, right = ' ' + left, right + ' ' if right else right
1353
- room = max(0, width - _fx.visible_width(left) -
1354
- _fx.visible_width(right))
1357
+ right_w = _fx.visible_width(right)
1358
+ if right and _fx.visible_width(left) + right_w > width and \
1359
+ width - right_w >= 4:
1360
+ # Too long: the left text gives way so the right one (often a
1361
+ # position or a count) stays in view.
1362
+ left = _fx.truncate(left, width - right_w - 1, '…') + ' '
1363
+ room = max(0, width - _fx.visible_width(left) - right_w)
1355
1364
  mid = _fx.fit_line(_fx.truncate(center, room, '…'), room, 'c')
1356
1365
  line = _fx.fit_line(left + mid + right, width)
1357
1366
  if not self._active():
@@ -1839,6 +1839,16 @@ class SignatureInput(Input):
1839
1839
  strokes.append(points)
1840
1840
  return strokes
1841
1841
 
1842
+ @property
1843
+ def value(self):
1844
+ # A copy: what a Form collected (or on_change got) does not change
1845
+ # as the user keeps drawing.
1846
+ return [list(stroke) for stroke in self._value]
1847
+
1848
+ @value.setter
1849
+ def value(self, new):
1850
+ self._value = self.coerce(new)
1851
+
1842
1852
  @property
1843
1853
  def strokes(self):
1844
1854
  return self._value
@@ -1891,6 +1901,9 @@ class SignatureInput(Input):
1891
1901
 
1892
1902
  def erase(self, point):
1893
1903
  point = self._inside(point)
1904
+ # Erasing lifts the pen: moving on must not join what is left of
1905
+ # the stroke (or the one before it) to the pen with a line.
1906
+ self.pen_down = False
1894
1907
  kept = []
1895
1908
  for stroke in self._value:
1896
1909
  rest = [p for p in stroke if p != point]
@@ -119,6 +119,14 @@ class Tabs(_Themed):
119
119
  return out
120
120
 
121
121
 
122
+ def _rows_for(max_visible, height):
123
+ """The rows a menu window gets: ``max_visible``, never more than the
124
+ ``height`` it is drawn in (either may be None)."""
125
+ if max_visible and height:
126
+ return max(1, min(int(max_visible), int(height)))
127
+ return max_visible or height
128
+
129
+
122
130
  def _window(comp, out, row, height):
123
131
  """The rows of ``out`` that fit ``height``, kept around ``row`` (the
124
132
  current item) with ``▲ n``/``▼ n`` lines saying how many are hidden
@@ -310,7 +318,7 @@ class Menu(_Themed):
310
318
  return super(Menu, self).handle_key(key)
311
319
 
312
320
  def draw(self, width, height):
313
- rows = self.max_visible or height or len(self.items)
321
+ rows = _rows_for(self.max_visible, height) or len(self.items)
314
322
  self._page = max(1, rows - 2)
315
323
  out = []
316
324
  for i in range(len(self.items)):
@@ -570,13 +578,18 @@ class Sidebar(Menu):
570
578
  elif item.get('disabled'):
571
579
  text = self.paint(text, 'dim')
572
580
  out.append(text)
573
- rows = self.max_visible or (max(1, height - len(head)) if height
574
- else None)
581
+ base = len(head)
582
+ if height:
583
+ # Too short for the title and an item: the item wins (the
584
+ # blank line goes first, then the title).
585
+ del head[max(0, int(height) - 1):]
586
+ rows = _rows_for(self.max_visible,
587
+ max(1, height - len(head)) if height else None)
575
588
  if rows:
576
589
  self._page = max(1, rows - 2)
577
590
  if isinstance(self._hot, list):
578
591
  # _window works in the item rows' own coordinates.
579
- self._hot = [(r - len(head), x0, x1, a)
592
+ self._hot = [(r - base, x0, x1, a)
580
593
  for r, x0, x1, a in self._hot]
581
594
  lines = _window(self, out, current, rows)
582
595
  if isinstance(self._hot, list):
@@ -1549,6 +1562,10 @@ class VStack(_Themed):
1549
1562
  for i in range(len(self.items))]
1550
1563
  room = height - gaps - sum(fixed)
1551
1564
  sizes = _share(room, self.weights, fixed, self.max_heights)
1565
+ # No rows left for a growing child: it keeps one (the stack
1566
+ # scrolls) rather than vanishing -- Tab could land on it.
1567
+ sizes = [self._clamp(i, 1) if not size and self.weights[i] and
1568
+ naturals[i] else size for i, size in enumerate(sizes)]
1552
1569
  blocks = []
1553
1570
  for child, rows in zip(self.items, sizes):
1554
1571
  lines = render_into(child, width, rows) if rows else []
@@ -1565,8 +1582,29 @@ class VStack(_Themed):
1565
1582
  return i
1566
1583
  return None
1567
1584
 
1585
+ def _focus_span(self, i, width, rows):
1586
+ """``(first, last)`` rows of the focused component inside child
1587
+ ``i`` drawn ``rows`` high, or None when it is not drawn there."""
1588
+ from flexablelib_tui.app import _HIT
1589
+ target = getattr(self.app, 'focused', None)
1590
+ saved = _HIT['on'], _HIT['items']
1591
+ _HIT['on'], _HIT['items'] = True, []
1592
+ try:
1593
+ lines = render_into(self.items[i], width, rows)
1594
+ items = _HIT['items']
1595
+ finally:
1596
+ _HIT['on'], _HIT['items'] = saved
1597
+ _lines, regions = _fx.extract_marks(lines)
1598
+ found = [row for k, row, x0, x1, depth in regions
1599
+ if 0 <= k < len(items) and items[k] is target]
1600
+ return (min(found), max(found)) if found else None
1601
+
1568
1602
  def draw(self, width, height):
1569
1603
  h = self.height or height
1604
+ if self.height and height:
1605
+ # Never taller than the slot: what does not fit scrolls (and
1606
+ # the focus is followed) instead of being cut off.
1607
+ h = min(self.height, height)
1570
1608
  sizes, blocks = self._layout(width, h)
1571
1609
  lines = []
1572
1610
  starts = []
@@ -1598,11 +1636,18 @@ class VStack(_Themed):
1598
1636
  self._followed = target
1599
1637
  i = self._holder()
1600
1638
  if i is not None:
1601
- top, size = starts[i], sizes[i]
1602
- if top < self.offset or size > h:
1603
- self.offset = top
1604
- elif top + size > self.offset + h:
1605
- self.offset = top + size - h
1639
+ first, last = starts[i], starts[i] + sizes[i] - 1
1640
+ if sizes[i] > h:
1641
+ # A child taller than the view: follow the focused
1642
+ # component inside it, not the child's first row.
1643
+ span = self._focus_span(i, inner, sizes[i])
1644
+ if span is not None:
1645
+ first, last = starts[i] + span[0], \
1646
+ starts[i] + span[1]
1647
+ if first < self.offset or last - first + 1 > h:
1648
+ self.offset = first
1649
+ elif last >= self.offset + h:
1650
+ self.offset = last - h + 1
1606
1651
  self.offset = max(0, min(self.offset, self.max_offset))
1607
1652
  visible = lines[self.offset:self.offset + h]
1608
1653
  if not (self.scrollbar and inner < width):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flexablelib-components
3
- Version: 3.7.0
3
+ Version: 3.7.1
4
4
  Summary: Interactive terminal components for flexablelib: inputs, dates, tables, forms, menus, tabs, dialogs and more.
5
5
  Home-page: https://github.com/Opus-Perpetuus/flexablelib
6
6
  Author: Benjamin Ramirez
@@ -17,8 +17,8 @@ Classifier: Topic :: Software Development :: User Interfaces
17
17
  Requires-Python: >=3.8
18
18
  Description-Content-Type: text/markdown
19
19
  License-File: LICENSE
20
- Requires-Dist: flexablelib>=3.7.0
21
- Requires-Dist: flexablelib-tui>=3.7.0
20
+ Requires-Dist: flexablelib>=3.7.1
21
+ Requires-Dist: flexablelib-tui>=3.7.1
22
22
  Dynamic: author
23
23
  Dynamic: author-email
24
24
  Dynamic: classifier
@@ -0,0 +1,2 @@
1
+ flexablelib>=3.7.1
2
+ flexablelib-tui>=3.7.1
@@ -1,2 +0,0 @@
1
- flexablelib>=3.7.0
2
- flexablelib-tui>=3.7.0