flexablelib-components 3.7.2__tar.gz → 3.7.4__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.2/flexablelib_components.egg-info → flexablelib_components-3.7.4}/PKG-INFO +3 -3
  2. {flexablelib_components-3.7.2 → flexablelib_components-3.7.4}/flexablelib_components/__init__.py +1 -1
  3. {flexablelib_components-3.7.2 → flexablelib_components-3.7.4}/flexablelib_components/base.py +17 -0
  4. {flexablelib_components-3.7.2 → flexablelib_components-3.7.4}/flexablelib_components/data.py +6 -0
  5. {flexablelib_components-3.7.2 → flexablelib_components-3.7.4}/flexablelib_components/display.py +18 -15
  6. {flexablelib_components-3.7.2 → flexablelib_components-3.7.4}/flexablelib_components/inputs.py +9 -0
  7. {flexablelib_components-3.7.2 → flexablelib_components-3.7.4}/flexablelib_components/navigation.py +36 -21
  8. {flexablelib_components-3.7.2 → flexablelib_components-3.7.4}/flexablelib_components/overlays.py +5 -3
  9. {flexablelib_components-3.7.2 → flexablelib_components-3.7.4/flexablelib_components.egg-info}/PKG-INFO +3 -3
  10. flexablelib_components-3.7.4/flexablelib_components.egg-info/requires.txt +2 -0
  11. flexablelib_components-3.7.2/flexablelib_components.egg-info/requires.txt +0 -2
  12. {flexablelib_components-3.7.2 → flexablelib_components-3.7.4}/LICENSE +0 -0
  13. {flexablelib_components-3.7.2 → flexablelib_components-3.7.4}/MANIFEST.in +0 -0
  14. {flexablelib_components-3.7.2 → flexablelib_components-3.7.4}/README.md +0 -0
  15. {flexablelib_components-3.7.2 → flexablelib_components-3.7.4}/flexablelib_components/dates.py +0 -0
  16. {flexablelib_components-3.7.2 → flexablelib_components-3.7.4}/flexablelib_components/media.py +0 -0
  17. {flexablelib_components-3.7.2 → flexablelib_components-3.7.4}/flexablelib_components/py.typed +0 -0
  18. {flexablelib_components-3.7.2 → flexablelib_components-3.7.4}/flexablelib_components.egg-info/SOURCES.txt +0 -0
  19. {flexablelib_components-3.7.2 → flexablelib_components-3.7.4}/flexablelib_components.egg-info/dependency_links.txt +0 -0
  20. {flexablelib_components-3.7.2 → flexablelib_components-3.7.4}/flexablelib_components.egg-info/top_level.txt +0 -0
  21. {flexablelib_components-3.7.2 → flexablelib_components-3.7.4}/setup.cfg +0 -0
  22. {flexablelib_components-3.7.2 → flexablelib_components-3.7.4}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flexablelib-components
3
- Version: 3.7.2
3
+ Version: 3.7.4
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.2
21
- Requires-Dist: flexablelib-tui>=3.7.2
20
+ Requires-Dist: flexablelib>=3.7.4
21
+ Requires-Dist: flexablelib-tui>=3.7.4
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.2'
21
+ __version__ = '3.7.4'
22
22
 
23
23
  from .base import Theme, DEFAULT_THEME, Input, Box, Button, frame
24
24
  from .inputs import (TextInput, PasswordInput, NumberInput, ExpressionInput,
@@ -281,6 +281,23 @@ def frame(lines, width, title=None, color=None, painter=None, style='rounded',
281
281
  return out
282
282
 
283
283
 
284
+ def pairs(items):
285
+ """``items`` (a mapping or a sequence) as a list of ``(key, value)``
286
+ pairs. A bare string, or a one-item tuple, is a key with no value
287
+ (``None``) -- not a pair made of the string's first two characters."""
288
+ if isinstance(items, dict):
289
+ return list(items.items())
290
+ out = []
291
+ for item in items:
292
+ if isinstance(item, str):
293
+ out.append((item, None))
294
+ elif len(item) < 2:
295
+ out.append((tuple(item) + (None, None))[:2])
296
+ else:
297
+ out.append(item)
298
+ return out
299
+
300
+
284
301
  def join_columns(blocks, widths, gap=1):
285
302
  """Side-by-side blocks of lines, each fitted to its width."""
286
303
  height = max((len(b) for b in blocks), default=0)
@@ -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
 
@@ -869,9 +869,9 @@ class DetailView(_Themed):
869
869
 
870
870
  class Timeline(_Themed):
871
871
  """
872
- Events down a line: ``(when, title, detail)`` or dicts with ``when``,
873
- ``title``, ``detail``, ``kind`` / ``status``. Also a status history: give
874
- ``kind`` per event (``'success'``, ``'error'`` ...).
872
+ Events down a line: ``(when, title, detail)``, a bare title, or dicts
873
+ with ``when``, ``title``, ``detail``, ``kind`` / ``status``. Also a
874
+ status history: give ``kind`` per event (``'success'``, ``'error'`` ...).
875
875
  """
876
876
 
877
877
  role = 'list'
@@ -896,6 +896,9 @@ class Timeline(_Themed):
896
896
  return (str(event.get('when', '')), str(event.get('title', '')),
897
897
  event.get('detail'), event.get('kind',
898
898
  event.get('status')))
899
+ if isinstance(event, str):
900
+ # A bare string is the event's title, not (when, title) letters.
901
+ return ('', event, None, None)
899
902
  event = tuple(event) + (None, None)
900
903
  return (str(event[0]), str(event[1]), event[2], event[3])
901
904
 
@@ -1051,8 +1054,8 @@ def human_size(size):
1051
1054
 
1052
1055
 
1053
1056
  class AttachmentList(_Themed):
1054
- """Files with an icon by type, name and size: ``(name, size)`` pairs or
1055
- 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``."""
1056
1059
 
1057
1060
  ICONS = {'pdf': '📕', 'xlsx': '📗', 'xls': '📗', 'csv': '📗', 'doc': '📘',
1058
1061
  'docx': '📘', 'png': '🖼', 'jpg': '🖼', 'jpeg': '🖼', 'gif': '🖼',
@@ -1066,8 +1069,8 @@ class AttachmentList(_Themed):
1066
1069
 
1067
1070
  def __init__(self, files, **kwargs):
1068
1071
  super(AttachmentList, self).__init__(**kwargs)
1069
- self.files = [(f.get('name'), f.get('size')) if isinstance(f, dict)
1070
- 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)
1071
1074
 
1072
1075
  def draw(self, width, height):
1073
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)
@@ -653,8 +654,9 @@ class TopBar(_Themed):
653
654
 
654
655
  class Toolbar(_Themed):
655
656
  """
656
- A row of :class:`Button` s (or ``(label, action)`` pairs): Left/Right
657
- move between them while one has focus; each keeps its own shortcut.
657
+ A row of :class:`Button` s (or ``(label, action)`` pairs, or bare
658
+ labels): Left/Right move between them while one has focus; each keeps
659
+ its own shortcut.
658
660
  """
659
661
 
660
662
  role = 'toolbar'
@@ -662,12 +664,19 @@ class Toolbar(_Themed):
662
664
  def __init__(self, buttons, gap=1, align='l', **kwargs):
663
665
  super(Toolbar, self).__init__(**kwargs)
664
666
  self.buttons = [b if isinstance(b, Button) else
665
- Button(b[0], b[1], theme=self._theme,
666
- use_colors=kwargs.get('use_colors'))
667
+ self._button(b, kwargs.get('use_colors'))
667
668
  for b in buttons]
668
669
  self.gap = gap
669
670
  self.align = align
670
671
 
672
+ def _button(self, spec, use_colors):
673
+ # A bare label is a button with no action -- not a label made of
674
+ # its first character and an "action" made of the second.
675
+ if isinstance(spec, str):
676
+ spec = (spec,)
677
+ return Button(spec[0], spec[1] if len(spec) > 1 else None,
678
+ theme=self._theme, use_colors=use_colors)
679
+
671
680
  def children(self):
672
681
  return list(self.buttons)
673
682
 
@@ -698,7 +707,8 @@ class Toolbar(_Themed):
698
707
  class Wizard(_Themed):
699
708
  """
700
709
  Steps with a stepper on top, the current step's content, and Back /
701
- Next / Finish buttons. ``steps`` are ``(title, content)`` pairs;
710
+ Next / Finish buttons. ``steps`` are ``(title, content)`` pairs (or bare
711
+ titles);
702
712
  ``validate(index) -> error or None`` guards Next; ``on_finish()``.
703
713
  Ctrl-N / Ctrl-P move too.
704
714
  """
@@ -717,7 +727,7 @@ class Wizard(_Themed):
717
727
 
718
728
  def __init__(self, steps, on_finish=None, validate=None, **kwargs):
719
729
  super(Wizard, self).__init__(**kwargs)
720
- self.steps = list(steps)
730
+ self.steps = pairs(steps)
721
731
  self.index = 0
722
732
  self.on_finish = on_finish
723
733
  self.check = validate
@@ -798,7 +808,8 @@ class Wizard(_Themed):
798
808
 
799
809
  class Accordion(_Themed):
800
810
  """
801
- 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
802
813
  move between headers, Enter/Space toggle; ``multiple=False`` keeps one
803
814
  open at a time. A single section works as a collapsible panel.
804
815
  """
@@ -823,19 +834,20 @@ class Accordion(_Themed):
823
834
 
824
835
  def __init__(self, sections, open=(0,), multiple=True, **kwargs):
825
836
  super(Accordion, self).__init__(**kwargs)
826
- self.sections = list(sections.items()) if isinstance(sections, dict) \
827
- else list(sections)
837
+ self.sections = pairs(sections)
828
838
  self.opened = set(open or ())
829
839
  self.multiple = bool(multiple)
830
840
  self.index = 0
831
841
 
832
842
  def children(self):
833
843
  return [c for i, (_, c) in enumerate(self.sections)
834
- 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)]
835
846
 
836
847
  def form_children(self):
837
848
  """Every section, open or not (the fields a form collects)."""
838
- 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)]
839
851
 
840
852
  def natural_width(self):
841
853
  return max([_natural_width(c) + 2 for _, c in self.sections] +
@@ -1100,6 +1112,8 @@ class Tree(_Themed):
1100
1112
  self.top = self.index
1101
1113
  if self.index >= self.top + view:
1102
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))
1103
1117
  out = []
1104
1118
  for i in range(self.top, min(len(rows), self.top + view)):
1105
1119
  path, key, value, depth, branch = rows[i]
@@ -1122,9 +1136,9 @@ class Tree(_Themed):
1122
1136
 
1123
1137
  class CommandPalette(_Themed):
1124
1138
  """
1125
- A search box over commands -- ``(label, action)`` pairs or dicts with
1126
- ``label``, ``action``, ``hint``, ``keywords`` -- matched by fuzzy
1127
- subsequence, best first. Up/Down choose, Enter runs, Escape closes.
1139
+ A search box over commands -- ``(label, action)`` pairs, bare labels
1140
+ (no action) or dicts with ``label``, ``action``, ``hint``, ``keywords``
1141
+ -- matched by fuzzy subsequence, best first. Up/Down choose, Enter runs, Escape closes.
1128
1142
  Open it with ``open(app)`` (bind it to ``ctrl+k`` or ``/``).
1129
1143
  """
1130
1144
 
@@ -1154,8 +1168,9 @@ class CommandPalette(_Themed):
1154
1168
  title='Comandos', **kwargs):
1155
1169
  super(CommandPalette, self).__init__(**kwargs)
1156
1170
  self.commands = [c if isinstance(c, dict) else
1157
- {'label': c[0], 'action': c[1] if len(c) > 1
1158
- else None} for c in commands]
1171
+ {'label': c, 'action': None} if isinstance(c, str)
1172
+ else {'label': c[0], 'action': c[1] if len(c) > 1
1173
+ else None} for c in commands]
1159
1174
  self.placeholder = placeholder
1160
1175
  self.max_visible = max_visible
1161
1176
  self.title = title
@@ -18,9 +18,9 @@ __all__ = ['Modal', 'ConfirmDialog', 'PromptDialog', 'LoadingOverlay',
18
18
  class Modal(_Themed):
19
19
  """
20
20
  A framed dialog over the screen: ``content`` and a row of ``buttons``
21
- (``(label, action)`` pairs or :class:`Button` s; an action returning
22
- anything but False closes the dialog). ``open(app)`` shows it; Escape
23
- closes it when ``closable``. ``width`` caps its width.
21
+ (``(label, action)`` pairs, bare labels or :class:`Button` s; an action
22
+ returning anything but False closes the dialog). ``open(app)`` shows it;
23
+ Escape closes it when ``closable``. ``width`` caps its width.
24
24
  """
25
25
 
26
26
  role = 'dialog'
@@ -43,6 +43,8 @@ class Modal(_Themed):
43
43
  colors = kwargs.get('use_colors')
44
44
  for b in buttons:
45
45
  if not isinstance(b, Button):
46
+ if isinstance(b, str):
47
+ b = (b,) # a bare label: a button that just closes
46
48
  label, action = b[0], b[1] if len(b) > 1 else None
47
49
  kind = b[2] if len(b) > 2 else 'default'
48
50
  b = Button(label, None, kind=kind, theme=self._theme,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flexablelib-components
3
- Version: 3.7.2
3
+ Version: 3.7.4
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.2
21
- Requires-Dist: flexablelib-tui>=3.7.2
20
+ Requires-Dist: flexablelib>=3.7.4
21
+ Requires-Dist: flexablelib-tui>=3.7.4
22
22
  Dynamic: author
23
23
  Dynamic: author-email
24
24
  Dynamic: classifier
@@ -0,0 +1,2 @@
1
+ flexablelib>=3.7.4
2
+ flexablelib-tui>=3.7.4
@@ -1,2 +0,0 @@
1
- flexablelib>=3.7.2
2
- flexablelib-tui>=3.7.2