flexablelib-components 3.7.3__tar.gz → 3.7.5__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.3/flexablelib_components.egg-info → flexablelib_components-3.7.5}/PKG-INFO +3 -3
  2. {flexablelib_components-3.7.3 → flexablelib_components-3.7.5}/flexablelib_components/__init__.py +1 -1
  3. {flexablelib_components-3.7.3 → flexablelib_components-3.7.5}/flexablelib_components/base.py +36 -6
  4. {flexablelib_components-3.7.3 → flexablelib_components-3.7.5}/flexablelib_components/data.py +6 -0
  5. {flexablelib_components-3.7.3 → flexablelib_components-3.7.5}/flexablelib_components/display.py +12 -12
  6. {flexablelib_components-3.7.3 → flexablelib_components-3.7.5}/flexablelib_components/inputs.py +9 -0
  7. {flexablelib_components-3.7.3 → flexablelib_components-3.7.5}/flexablelib_components/navigation.py +18 -12
  8. {flexablelib_components-3.7.3 → flexablelib_components-3.7.5/flexablelib_components.egg-info}/PKG-INFO +3 -3
  9. flexablelib_components-3.7.5/flexablelib_components.egg-info/requires.txt +2 -0
  10. flexablelib_components-3.7.3/flexablelib_components.egg-info/requires.txt +0 -2
  11. {flexablelib_components-3.7.3 → flexablelib_components-3.7.5}/LICENSE +0 -0
  12. {flexablelib_components-3.7.3 → flexablelib_components-3.7.5}/MANIFEST.in +0 -0
  13. {flexablelib_components-3.7.3 → flexablelib_components-3.7.5}/README.md +0 -0
  14. {flexablelib_components-3.7.3 → flexablelib_components-3.7.5}/flexablelib_components/dates.py +0 -0
  15. {flexablelib_components-3.7.3 → flexablelib_components-3.7.5}/flexablelib_components/media.py +0 -0
  16. {flexablelib_components-3.7.3 → flexablelib_components-3.7.5}/flexablelib_components/overlays.py +0 -0
  17. {flexablelib_components-3.7.3 → flexablelib_components-3.7.5}/flexablelib_components/py.typed +0 -0
  18. {flexablelib_components-3.7.3 → flexablelib_components-3.7.5}/flexablelib_components.egg-info/SOURCES.txt +0 -0
  19. {flexablelib_components-3.7.3 → flexablelib_components-3.7.5}/flexablelib_components.egg-info/dependency_links.txt +0 -0
  20. {flexablelib_components-3.7.3 → flexablelib_components-3.7.5}/flexablelib_components.egg-info/top_level.txt +0 -0
  21. {flexablelib_components-3.7.3 → flexablelib_components-3.7.5}/setup.cfg +0 -0
  22. {flexablelib_components-3.7.3 → flexablelib_components-3.7.5}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flexablelib-components
3
- Version: 3.7.3
3
+ Version: 3.7.5
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.3
21
- Requires-Dist: flexablelib-tui>=3.7.3
20
+ Requires-Dist: flexablelib>=3.7.5
21
+ Requires-Dist: flexablelib-tui>=3.7.5
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.3'
21
+ __version__ = '3.7.5'
22
22
 
23
23
  from .base import Theme, DEFAULT_THEME, Input, Box, Button, frame
24
24
  from .inputs import (TextInput, PasswordInput, NumberInput, ExpressionInput,
@@ -4,7 +4,7 @@ labels, help text and validation, and a few drawing helpers.
4
4
  """
5
5
 
6
6
  from flexablelib import _frames as _fx
7
- from flexablelib.colors import RESET, parse_spec
7
+ from flexablelib.colors import RESET, color_depth, parse_spec
8
8
  from flexablelib_tui import Component
9
9
 
10
10
  __all__ = ['Theme', 'DEFAULT_THEME', 'THEMES', 'Input', 'frame',
@@ -30,8 +30,8 @@ class Theme(object):
30
30
 
31
31
  def __init__(self, accent='cyan', muted='bright_black', text=None,
32
32
  selection='bold black on cyan', border='bright_black',
33
- info='blue', success='green', warning='yellow',
34
- error='red', title='bold', field='on #262626',
33
+ info='#5f87ff', success='green', warning='yellow',
34
+ error='bright_red', title='bold', field='on #262626',
35
35
  background='#000000', foreground='#e5e5e5', marker=False,
36
36
  name='custom'):
37
37
  self.name = name
@@ -134,6 +134,17 @@ THEMES = {
134
134
 
135
135
  DEFAULT_THEME = Theme(name='default')
136
136
 
137
+
138
+ def _text_on(colour):
139
+ """``'black'`` or ``'white'``, whichever reads better on ``colour``."""
140
+ from flexablelib_tui.accessibility import spec_colors, contrast_ratio
141
+ rgb = spec_colors(colour)[0]
142
+ if rgb is None:
143
+ return 'white'
144
+ black = contrast_ratio((0, 0, 0), rgb)
145
+ white = contrast_ratio(spec_colors('white')[0], rgb)
146
+ return 'black' if black > white else 'white'
147
+
137
148
  _SPEC_CACHE = {}
138
149
 
139
150
  _BOXES = {
@@ -234,9 +245,10 @@ class _Themed(Component):
234
245
  def paint(self, text, spec):
235
246
  if not text or not spec or not self._active():
236
247
  return text
237
- prefix = _SPEC_CACHE.get(spec)
248
+ key = (spec, color_depth())
249
+ prefix = _SPEC_CACHE.get(key)
238
250
  if prefix is None:
239
- prefix = _SPEC_CACHE[spec] = parse_spec(spec)
251
+ prefix = _SPEC_CACHE[key] = parse_spec(spec)
240
252
  if not prefix:
241
253
  return text
242
254
  return prefix + text.replace(RESET, RESET + prefix) + RESET
@@ -281,6 +293,23 @@ def frame(lines, width, title=None, color=None, painter=None, style='rounded',
281
293
  return out
282
294
 
283
295
 
296
+ def pairs(items):
297
+ """``items`` (a mapping or a sequence) as a list of ``(key, value)``
298
+ pairs. A bare string, or a one-item tuple, is a key with no value
299
+ (``None``) -- not a pair made of the string's first two characters."""
300
+ if isinstance(items, dict):
301
+ return list(items.items())
302
+ out = []
303
+ for item in items:
304
+ if isinstance(item, str):
305
+ out.append((item, None))
306
+ elif len(item) < 2:
307
+ out.append((tuple(item) + (None, None))[:2])
308
+ else:
309
+ out.append(item)
310
+ return out
311
+
312
+
284
313
  def join_columns(blocks, widths, gap=1):
285
314
  """Side-by-side blocks of lines, each fitted to its width."""
286
315
  height = max((len(b) for b in blocks), default=0)
@@ -530,7 +559,8 @@ class Button(_Themed):
530
559
  if self.disabled:
531
560
  return theme.muted
532
561
  base = {'primary': 'black on ' + theme.accent,
533
- 'danger': 'white on ' + theme.error}.get(self.kind)
562
+ 'danger': _text_on(theme.error) + ' on ' + theme.error
563
+ }.get(self.kind)
534
564
  if self.focused:
535
565
  return 'bold reverse' if base is None else 'bold ' + base
536
566
  return base or 'on bright_black'
@@ -436,6 +436,9 @@ class DataTable(_Themed):
436
436
  self.top = self.cursor_row
437
437
  if self.cursor_row >= self.top + rows_h:
438
438
  self.top = self.cursor_row - rows_h + 1
439
+ # Taller again (a resize): fill the room from above instead of
440
+ # keeping the rows the short layout scrolled to at the top.
441
+ self.top = max(0, min(self.top, len(view) - rows_h))
439
442
  stop = self.top + rows_h
440
443
  if self.page_size:
441
444
  stop = min(stop, (self.page) * self.page_size)
@@ -919,6 +922,9 @@ class CatalogGrid(_Themed):
919
922
  self.top_row = row_of
920
923
  if row_of >= self.top_row + visible_rows:
921
924
  self.top_row = row_of - visible_rows + 1
925
+ # More columns or rows of room (a resize): no empty rows of cards
926
+ # below while earlier ones stay scrolled out above.
927
+ self.top_row = max(0, min(self.top_row, n_rows - visible_rows))
922
928
  out = []
923
929
  for r in range(self.top_row, min(n_rows, self.top_row +
924
930
  visible_rows)):
@@ -14,7 +14,7 @@ from flexablelib.text_width import wrap_to_width
14
14
 
15
15
  from flexablelib_tui import accessibility as _a11y
16
16
 
17
- from .base import _Themed, frame
17
+ from .base import _Themed, frame, pairs
18
18
 
19
19
  __all__ = ['Badge', 'Tag', 'StatusBadge', 'Alert', 'Link', 'Breadcrumbs',
20
20
  'EmptyState', 'ErrorPanel', 'Spinner', 'Skeleton', 'Code',
@@ -812,26 +812,26 @@ class HtmlView(MarkdownView):
812
812
  class DetailView(_Themed):
813
813
  """
814
814
  Labelled values in aligned columns -- a record's detail. ``fields`` is a
815
- mapping or ``(label, value)`` pairs; a label starting with ``#`` is a
816
- section heading. ``columns=2`` lays the pairs out in two columns.
815
+ mapping or ``(label, value)`` pairs (a bare label has no value); a
816
+ label starting with ``#`` is a section heading. ``columns=2`` lays the pairs out in two columns.
817
817
  """
818
818
 
819
819
  role = 'list'
820
820
 
821
821
  def a11y_value(self):
822
- return '; '.join('{0}: {1}'.format(k, v) for k, v in self.fields
822
+ return '; '.join(str(k) if v is None else '{0}: {1}'.format(k, v)
823
+ for k, v in self.fields
823
824
  if not str(k).startswith('#'))
824
825
 
825
826
  def __init__(self, fields, columns=1, label_color=None, **kwargs):
826
827
  super(DetailView, self).__init__(**kwargs)
827
- self.fields = list(fields.items()) if isinstance(fields, dict) \
828
- else list(fields)
828
+ self.fields = pairs(fields)
829
829
  self.columns = max(1, int(columns))
830
830
  self.label_color = label_color
831
831
 
832
832
  def natural_width(self):
833
- widths = [_fx.visible_width(str(k)) + _fx.visible_width(str(v)) + 2
834
- for k, v in self.fields]
833
+ widths = [_fx.visible_width(str(k)) + 2 + _fx.visible_width(
834
+ '' if v is None else str(v)) for k, v in self.fields]
835
835
  return min(100, max(widths or [10]) * self.columns +
836
836
  3 * (self.columns - 1))
837
837
 
@@ -1054,8 +1054,8 @@ def human_size(size):
1054
1054
 
1055
1055
 
1056
1056
  class AttachmentList(_Themed):
1057
- """Files with an icon by type, name and size: ``(name, size)`` pairs or
1058
- dicts with ``name`` and ``size``."""
1057
+ """Files with an icon by type, name and size: ``(name, size)`` pairs,
1058
+ bare names (no size) or dicts with ``name`` and ``size``."""
1059
1059
 
1060
1060
  ICONS = {'pdf': '📕', 'xlsx': '📗', 'xls': '📗', 'csv': '📗', 'doc': '📘',
1061
1061
  'docx': '📘', 'png': '🖼', 'jpg': '🖼', 'jpeg': '🖼', 'gif': '🖼',
@@ -1069,8 +1069,8 @@ class AttachmentList(_Themed):
1069
1069
 
1070
1070
  def __init__(self, files, **kwargs):
1071
1071
  super(AttachmentList, self).__init__(**kwargs)
1072
- self.files = [(f.get('name'), f.get('size')) if isinstance(f, dict)
1073
- else tuple(f) for f in files]
1072
+ self.files = pairs((f.get('name'), f.get('size'))
1073
+ if isinstance(f, dict) else f for f in files)
1074
1074
 
1075
1075
  def draw(self, width, height):
1076
1076
  out = []
@@ -267,6 +267,12 @@ class TextInput(Input):
267
267
  self.scroll_x = cursor_col
268
268
  if cursor_col >= self.scroll_x + avail:
269
269
  self.scroll_x = cursor_col - avail + 1
270
+ # Never scrolled further than the text needs: once the field is
271
+ # wide enough again (a resize, a shorter value), it shows from the
272
+ # start instead of keeping only the tail it showed when narrow.
273
+ needed = sum(widths) + (1 if self.focused and
274
+ self.cursor_pos >= len(shown) else 0)
275
+ self.scroll_x = max(0, min(self.scroll_x, needed - avail))
270
276
  out, col = [], 0
271
277
  for i, (char, w) in enumerate(zip(shown, widths)):
272
278
  if col >= self.scroll_x and col + w <= self.scroll_x + avail:
@@ -782,6 +788,9 @@ class TextArea(Input):
782
788
  self.scroll_y = cur
783
789
  if cur >= self.scroll_y + self.rows:
784
790
  self.scroll_y = cur - self.rows + 1
791
+ # Wider again (fewer wrapped lines): fill the box from the top
792
+ # instead of keeping the offset the narrow layout needed.
793
+ self.scroll_y = max(0, min(self.scroll_y, len(segs) - self.rows))
785
794
  out = []
786
795
  if not self.text and not self.focused and self.placeholder:
787
796
  out.append(marker + ' ' + self.paint(self.placeholder,
@@ -10,7 +10,7 @@ from flexablelib.layout import _accepts_height, _natural_width, _render_child
10
10
 
11
11
  from flexablelib_tui import Key
12
12
 
13
- from .base import Button, _Themed, frame, join_columns
13
+ from .base import Button, _Themed, frame, join_columns, pairs
14
14
 
15
15
  _Enter = Key('enter')
16
16
 
@@ -39,7 +39,8 @@ def render_into(child, width, height=None):
39
39
 
40
40
  class Tabs(_Themed):
41
41
  """
42
- Tabbed panes: ``tabs`` is a mapping (or pairs) of title to content.
42
+ Tabbed panes: ``tabs`` is a mapping (or pairs) of title to content; a
43
+ bare title is a tab with no content.
43
44
  Left/Right (or 1-9) switch while the tab bar has the focus; the content's
44
45
  own components follow it in the focus order. ``on_change(index)``.
45
46
  """
@@ -56,8 +57,7 @@ class Tabs(_Themed):
56
57
 
57
58
  def __init__(self, tabs, index=0, on_change=None, **kwargs):
58
59
  super(Tabs, self).__init__(**kwargs)
59
- self.tabs = list(tabs.items()) if isinstance(tabs, dict) \
60
- else list(tabs)
60
+ self.tabs = pairs(tabs)
61
61
  self.index = index
62
62
  self.on_change = on_change
63
63
 
@@ -70,7 +70,8 @@ class Tabs(_Themed):
70
70
 
71
71
  def form_children(self):
72
72
  """Every pane, shown or not (the fields a form collects)."""
73
- return [c for _, c in self.tabs if not isinstance(c, str)]
73
+ return [c for _, c in self.tabs
74
+ if c is not None and not isinstance(c, str)]
74
75
 
75
76
  def natural_width(self):
76
77
  bar = sum(_fx.visible_width(t) + 3 for t, _ in self.tabs)
@@ -706,7 +707,8 @@ class Toolbar(_Themed):
706
707
  class Wizard(_Themed):
707
708
  """
708
709
  Steps with a stepper on top, the current step's content, and Back /
709
- Next / Finish buttons. ``steps`` are ``(title, content)`` pairs;
710
+ Next / Finish buttons. ``steps`` are ``(title, content)`` pairs (or bare
711
+ titles);
710
712
  ``validate(index) -> error or None`` guards Next; ``on_finish()``.
711
713
  Ctrl-N / Ctrl-P move too.
712
714
  """
@@ -725,7 +727,7 @@ class Wizard(_Themed):
725
727
 
726
728
  def __init__(self, steps, on_finish=None, validate=None, **kwargs):
727
729
  super(Wizard, self).__init__(**kwargs)
728
- self.steps = list(steps)
730
+ self.steps = pairs(steps)
729
731
  self.index = 0
730
732
  self.on_finish = on_finish
731
733
  self.check = validate
@@ -806,7 +808,8 @@ class Wizard(_Themed):
806
808
 
807
809
  class Accordion(_Themed):
808
810
  """
809
- Collapsible sections: ``sections`` are ``(title, content)`` pairs. Up/Down
811
+ Collapsible sections: ``sections`` are ``(title, content)`` pairs (or a
812
+ mapping; a bare title is a section with no content). Up/Down
810
813
  move between headers, Enter/Space toggle; ``multiple=False`` keeps one
811
814
  open at a time. A single section works as a collapsible panel.
812
815
  """
@@ -831,19 +834,20 @@ class Accordion(_Themed):
831
834
 
832
835
  def __init__(self, sections, open=(0,), multiple=True, **kwargs):
833
836
  super(Accordion, self).__init__(**kwargs)
834
- self.sections = list(sections.items()) if isinstance(sections, dict) \
835
- else list(sections)
837
+ self.sections = pairs(sections)
836
838
  self.opened = set(open or ())
837
839
  self.multiple = bool(multiple)
838
840
  self.index = 0
839
841
 
840
842
  def children(self):
841
843
  return [c for i, (_, c) in enumerate(self.sections)
842
- if i in self.opened and not isinstance(c, str)]
844
+ if i in self.opened and c is not None
845
+ and not isinstance(c, str)]
843
846
 
844
847
  def form_children(self):
845
848
  """Every section, open or not (the fields a form collects)."""
846
- return [c for _, c in self.sections if not isinstance(c, str)]
849
+ return [c for _, c in self.sections
850
+ if c is not None and not isinstance(c, str)]
847
851
 
848
852
  def natural_width(self):
849
853
  return max([_natural_width(c) + 2 for _, c in self.sections] +
@@ -1108,6 +1112,8 @@ class Tree(_Themed):
1108
1112
  self.top = self.index
1109
1113
  if self.index >= self.top + view:
1110
1114
  self.top = self.index - view + 1
1115
+ # Taller again, or nodes collapsed: fill the room from above.
1116
+ self.top = max(0, min(self.top, len(rows) - view))
1111
1117
  out = []
1112
1118
  for i in range(self.top, min(len(rows), self.top + view)):
1113
1119
  path, key, value, depth, branch = rows[i]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flexablelib-components
3
- Version: 3.7.3
3
+ Version: 3.7.5
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.3
21
- Requires-Dist: flexablelib-tui>=3.7.3
20
+ Requires-Dist: flexablelib>=3.7.5
21
+ Requires-Dist: flexablelib-tui>=3.7.5
22
22
  Dynamic: author
23
23
  Dynamic: author-email
24
24
  Dynamic: classifier
@@ -0,0 +1,2 @@
1
+ flexablelib>=3.7.5
2
+ flexablelib-tui>=3.7.5
@@ -1,2 +0,0 @@
1
- flexablelib>=3.7.3
2
- flexablelib-tui>=3.7.3