tui-utilities 1.0.15__tar.gz → 1.0.17__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tui_utilities
3
- Version: 1.0.15
3
+ Version: 1.0.17
4
4
  Summary: Personal-use console utilities library
5
5
  Author-email: Guido Iván Gross <grossguidoivan@gmail.com>
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "tui_utilities"
3
- version = "1.0.15"
3
+ version = "1.0.17"
4
4
  description = "Personal-use console utilities library"
5
5
  readme = "README.md"
6
6
  license = {text = "MIT"}
@@ -2,13 +2,14 @@ from rich.console import Console, RenderableType
2
2
  from rich.text import Text
3
3
  from rich.align import Align
4
4
  from rich.padding import Padding
5
+ from rich.protocol import is_renderable
5
6
  import os
6
7
  import readchar
7
8
 
8
9
  _console = Console()
9
10
 
10
11
  def _style(
11
- text,
12
+ object,
12
13
  color = "#ffffff",
13
14
  bold = False,
14
15
  italic = False,
@@ -23,9 +24,9 @@ def _style(
23
24
  left_padding = None,
24
25
  plain_text = False
25
26
  ):
26
- def apply_text_styles(text):
27
- message = Text()
28
- if isinstance(text, str):
27
+ def apply_text_styles(object):
28
+ styleable = Text()
29
+ if isinstance(object, str):
29
30
  style_parts = [color]
30
31
  if bold: style_parts.append("bold")
31
32
  if italic: style_parts.append("italic")
@@ -34,17 +35,17 @@ def _style(
34
35
  if reverse: style_parts.append("reverse")
35
36
  style = " ".join(style_parts)
36
37
  current_segment = ""
37
- for character in text:
38
+ for character in object:
38
39
  if character == " ":
39
40
  if current_segment:
40
- message.append(current_segment, style = style)
41
+ styleable.append(current_segment, style = style)
41
42
  current_segment = ""
42
- message.append(" ")
43
+ styleable.append(" ")
43
44
  else: current_segment += character
44
- if current_segment: message.append(current_segment, style=style)
45
- return message
46
- elif isinstance(text, list):
47
- for segment, segment_style in text:
45
+ if current_segment: styleable.append(current_segment, style=style)
46
+ return styleable
47
+ elif isinstance(object, list):
48
+ for segment, segment_style in object:
48
49
  style_parts = [segment_style.get("color", color)]
49
50
  if segment_style.get("bold"): style_parts.append("bold")
50
51
  if segment_style.get("italic"): style_parts.append("italic")
@@ -56,29 +57,35 @@ def _style(
56
57
  for character in segment:
57
58
  if character == " ":
58
59
  if current_segment:
59
- message.append(current_segment, style = style)
60
+ styleable.append(current_segment, style = style)
60
61
  current_segment = ""
61
- message.append(" ")
62
+ styleable.append(" ")
62
63
  else: current_segment += character
63
- if current_segment: message.append(current_segment, style = style)
64
- return message
64
+ if current_segment: styleable.append(current_segment, style = style)
65
+ return styleable
65
66
 
66
- def apply_alignment(message): return Align(message, alignment)
67
+ def apply_alignment(alignable): return Align(alignable, alignment)
67
68
 
68
- def apply_padding(message):
69
+ def apply_padding(paddable):
69
70
  final_padding = (
70
71
  top_padding if top_padding is not None else padding,
71
72
  (right_padding if right_padding is not None else padding) * 2,
72
73
  bottom_padding if bottom_padding is not None else padding,
73
74
  (left_padding if left_padding is not None else padding) * 2
74
75
  )
75
- return Padding(message, final_padding)
76
+ return Padding(paddable, final_padding)
76
77
 
77
- message = apply_text_styles(text)
78
- if plain_text: return message
79
- message = apply_alignment(message)
80
- message = apply_padding(message)
81
- return message
78
+ if is_renderable(object):
79
+ aligned = apply_alignment(object)
80
+ padded = apply_padding(aligned)
81
+ return padded
82
+ elif plain_text:
83
+ styled = apply_text_styles(object)
84
+ return styled
85
+ styled = apply_text_styles(object)
86
+ aligned = apply_alignment(styled)
87
+ padded = apply_padding(aligned)
88
+ return padded
82
89
 
83
90
  def print(
84
91
  *objects,
@@ -104,7 +111,7 @@ def print(
104
111
  if isinstance(object, Text): renderables.append(object)
105
112
  elif isinstance(object, (str, list)):
106
113
  renderables.append(_style(
107
- text = object,
114
+ object = object,
108
115
  color = color,
109
116
  bold = bold,
110
117
  italic = italic,
@@ -119,10 +126,19 @@ def print(
119
126
  left_padding = left_padding,
120
127
  plain_text = plain_text
121
128
  ))
122
- elif isinstance(object, RenderableType): renderables.append(object)
129
+ elif is_renderable(object):
130
+ renderables.append(_style(
131
+ object = object,
132
+ alignment = alignment,
133
+ padding = padding,
134
+ top_padding = top_padding,
135
+ right_padding = right_padding,
136
+ bottom_padding = bottom_padding,
137
+ left_padding = left_padding
138
+ ))
123
139
  else:
124
140
  renderables.append(_style(
125
- text = str(object),
141
+ object = str(object),
126
142
  color = color,
127
143
  bold = bold,
128
144
  italic = italic,
@@ -149,7 +165,7 @@ def input(
149
165
  reverse = False
150
166
  ):
151
167
  return _console.input(_style(
152
- text = text,
168
+ object = text,
153
169
  color = color,
154
170
  bold = bold,
155
171
  italic = italic,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tui_utilities
3
- Version: 1.0.15
3
+ Version: 1.0.17
4
4
  Summary: Personal-use console utilities library
5
5
  Author-email: Guido Iván Gross <grossguidoivan@gmail.com>
6
6
  License: MIT
File without changes
File without changes