reykit 1.1.27__py3-none-any.whl → 1.1.29__py3-none-any.whl

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.
reykit/rstdout.py CHANGED
@@ -10,21 +10,20 @@
10
10
 
11
11
 
12
12
  from typing import Any, Literal, Final
13
- from collections.abc import Callable
13
+ from collections.abc import Callable, Iterable
14
14
  import sys
15
15
  from io import TextIOWrapper
16
- from os import devnull as os_devnull
16
+ from os import devnull as os_devnull, isatty as os_isatty, get_terminal_size as os_get_terminal_size
17
17
  from os.path import abspath as os_abspath
18
18
 
19
- from .rbase import Base, ConfigMeta, get_first_notnone, get_name, get_stack_param
20
- from .rtext import to_text, add_text_frame
19
+ from .rbase import T, Base, ConfigMeta, get_stack_param, get_varname
21
20
 
22
21
 
23
22
  __all__ = (
24
23
  'ConfigStdout',
25
- 'beautify_text',
24
+ 'get_terminal_size',
26
25
  'echo',
27
- 'rinput',
26
+ 'ask',
28
27
  'stop_print',
29
28
  'start_print',
30
29
  'modify_print',
@@ -39,9 +38,7 @@ class ConfigStdout(Base, metaclass=ConfigMeta):
39
38
 
40
39
  Attributes
41
40
  ----------
42
- is_frame_plain : Whehter global use plain text frame type.
43
- - `Literal[True]`: 'full' to 'half_plain', 'half' to 'half_plain', 'top' to 'top_plain', Other unchanged.
44
- default_width : Global default text width.
41
+ force_print_ascii : Whether force methods print frame use ascii border.
45
42
  """
46
43
 
47
44
  # Module path.
@@ -56,177 +53,165 @@ class ConfigStdout(Base, metaclass=ConfigMeta):
56
53
  _io_stdout: TextIOWrapper = sys.stdout
57
54
  _io_stdout_write: Callable[[str], int] = sys.stdout.write
58
55
 
59
- # Is the print frame plain.
60
- is_frame_plain: bool = False
56
+ # Force print ascii.
57
+ force_print_ascii: bool = False
61
58
 
62
- # print default width.
63
- default_width: int = 100
59
+ # Added print position.
60
+ _added_print_position: set = set()
64
61
 
65
62
 
66
- def beautify_text(
67
- data: tuple[Any],
68
- title: bool | str = True,
69
- width: int | None = None,
70
- frame: Literal['full', 'half', 'top', 'half_plain', 'top_plain'] | None = 'full'
71
- ) -> str:
63
+ def get_terminal_size(
64
+ stream: Literal['stdin', 'stdout', 'stderr'] = 'stdout',
65
+ default: T = (80, 24)
66
+ ) -> tuple[int, int] | T:
72
67
  """
73
- Beautify data to text.
68
+ Get terminal display character size.
74
69
 
75
70
  Parameters
76
71
  ----------
77
- data : Text data.
78
- title : Text title.
79
- - `Literal[True]`: Automatic get data variable name.
80
- - `Literal[False]`: No title.
81
- - `str`: Use this value as the title.
82
- width : Text width.
83
- - `None`: Use attribute `ConfigStdout.default_width`.
84
- - `int`: Use this value.
85
- frame : Text frame type.
86
- - `Literal['full']`: Add beautiful four side frame and limit length.
87
- When attribute `ConfigStdout.is_frame_plain` is True, then frame is `half_plain` type.
88
- When throw `exception`, then frame is `half` type.
89
- - `Literal['half']`: Add beautiful top and bottom side frame.
90
- When attribute `ConfigStdout.is_frame_plain` is True, then frame is `half_plain` type.
91
- - `Literal['top']`: Add beautiful top side frame.
92
- When attribute `ConfigStdout.is_frame_plain` is True, then frame is `top_plain` type.
93
- - `Literal['half_plain']`: Add plain top and bottom side frame.
94
- - `Literal['top_plain']`: Add plain top side frame.
72
+ stream : Standard stream type.
95
73
 
96
74
  Returns
97
75
  -------
98
- Beautify text.
76
+ Column and line display character count.
99
77
  """
100
78
 
101
- # Get parameter.
102
-
103
- ## Title.
104
- if title is True:
105
- titles = get_name(data, 3)
106
- if titles is not None:
107
- titles = [title if not title.startswith('`') else '' for title in titles]
108
- if set(titles) != {''}:
109
- title = ' │ '.join(titles)
110
- if type(title) != str:
111
- title = None
112
-
113
- ## Width.
114
- width = get_first_notnone(width, ConfigStdout.default_width)
115
-
116
- ## Frame.
117
- if ConfigStdout.is_frame_plain:
118
- match frame:
119
- case 'full':
120
- frame = 'half_plain'
121
- case 'half':
122
- frame = 'half_plain'
123
- case 'top':
124
- frame = 'top_plain'
125
-
126
- # To text.
127
- text_list = [
128
- to_text(content, width=width)
129
- for content in data
130
- ]
79
+ # Handle parameter.
80
+ match stream:
81
+ case 'stdin':
82
+ stream = 0
83
+ case 'stdout':
84
+ stream = 1
85
+ case 'stderr':
86
+ stream = 2
131
87
 
132
- # Add frame.
133
- text = add_text_frame(*text_list, title=title, width=width, frame=frame)
88
+ # Get.
89
+ exist = os_isatty(stream)
90
+ if exist:
91
+ terminal_size = os_get_terminal_size(stream)
92
+ terminal_size = tuple(terminal_size)
93
+ else:
94
+ terminal_size = default
134
95
 
135
- return text
96
+ return terminal_size
136
97
 
137
98
 
138
99
  def echo(
139
100
  *data: Any,
140
- title: bool | str = True,
101
+ title: str | Iterable[str] | None = None,
141
102
  width: int | None = None,
142
- frame: Literal['full', 'half', 'top', 'half_plain', 'top_plain'] | None = 'full'
143
- ) -> str:
103
+ frame: Literal['left', 'top', 'box'] = 'box',
104
+ border: Literal['ascii', 'thick', 'double'] = 'double',
105
+ extra: str | None = None
106
+ ) -> None:
144
107
  """
145
- Beautify data to text, and print.
108
+ Frame data and print.
146
109
 
147
110
  Parameters
148
111
  ----------
149
- data : Text data.
150
- title : Text title.
151
- - `Literal[True]`: Automatic get data variable name.
152
- - `Literal[False]`: No title.
153
- - `str`: Use this value as the title.
154
- width : Text width.
155
- - `None`: Use attribute `ConfigStdout.default_width`.
156
- - `int`: Use this value.
157
- frame : Text frame type.
158
- - `Literal['full']`: Add beautiful four side frame and limit length.
159
- When attribute `ConfigStdout.is_frame_plain` is True, then frame is `half_plain` type.
160
- When throw `exception`, then frame is `half` type.
161
- - `Literal['half']`: Add beautiful top and bottom side frame.
162
- When attribute `ConfigStdout.is_frame_plain` is True, then frame is `half_plain` type.
163
- - `Literal['top']`: Add beautiful top side frame.
164
- When attribute `ConfigStdout.is_frame_plain` is True, then frame is `top_plain` type.
165
- - `Literal['half_plain']`: Add plain top and bottom side frame.
166
- - `Literal['top_plain']`: Add plain top side frame.
167
-
168
- Returns
169
- -------
170
- Beautify text.
112
+ data : Print data.
113
+ title : Print title.
114
+ - `None`: Use variable name of argument `data`.
115
+ - `str` : Use this value.
116
+ - `Iterable[str]` : Connect this values and use.
117
+ width : Frame width.
118
+ - `None` : Use terminal display character size.
119
+ frame : Frame type.
120
+ - `Literal[`left`]`: Line beginning add character column.
121
+ - `Literal[`top`]`: Line head add character line, with title.
122
+ - `Literal[`box`]`: Add four borders, with title, automatic newline.
123
+ border : Border type.
124
+ - `Literal['ascii']`: Use ASCII character.
125
+ - `Literal['thick']`: Use thick line character.
126
+ - `Literal['double']`: Use double line character.
127
+ extra : Extra print text.
171
128
  """
172
129
 
173
- # Beautify.
174
- text = beautify_text(data, title=title, width=width, frame=frame)
130
+ # Import.
131
+ from .rtext import frame_data
132
+
133
+ # Handle parameter.
134
+ if title is None:
135
+ title = get_varname('data')
136
+ if ConfigStdout.force_print_ascii:
137
+ border = 'ascii'
138
+
139
+ # Frame.
140
+ text = frame_data(
141
+ *data,
142
+ title=title,
143
+ width=width,
144
+ frame=frame,
145
+ border=border
146
+ )
147
+
148
+ # Extra.
149
+ if extra is not None:
150
+ text = f'{text}\n{extra}'
175
151
 
176
152
  # Print.
177
153
  print(text)
178
154
 
179
- return text
180
-
181
155
 
182
- def rinput(
156
+ def ask(
183
157
  *data: Any,
184
- title: bool | str = True,
158
+ title: str | Iterable[str] | None = None,
185
159
  width: int | None = None,
186
- frame: Literal['full', 'half', 'top', 'half_plain', 'top_plain'] | None = 'full',
160
+ frame: Literal['left', 'top', 'box'] = 'box',
161
+ border: Literal['ascii', 'thick', 'double'] = 'double',
187
162
  extra: str | None = None
188
163
  ) -> str:
189
164
  """
190
- Beautify data to text, and print data, and read string from standard input.
165
+ Frame data and print and read string from standard input.
191
166
 
192
167
  Parameters
193
168
  ----------
194
- data : Text data.
195
- title : Text title.
196
- - `Literal[True]`: Automatic get data variable name.
197
- - `Literal[False]`: No title.
198
- - `str`: Use this value as the title.
199
- width : Text width.
200
- - `None`: Use attribute `ConfigStdout.default_width`.
201
- - `int`: Use this value.
202
- frame : Text frame type.
203
- - `Literal['full']`: Add beautiful four side frame and limit length.
204
- When attribute `ConfigStdout.is_frame_plain` is True, then frame is `half_plain` type.
205
- When throw `exception`, then frame is `half` type.
206
- - `Literal['half']`: Add beautiful top and bottom side frame.
207
- When attribute `ConfigStdout.is_frame_plain` is True, then frame is `half_plain` type.
208
- - `Literal['top']`: Add beautiful top side frame.
209
- When attribute `ConfigStdout.is_frame_plain` is True, then frame is `top_plain` type.
210
- - `Literal['half_plain']`: Add plain top and bottom side frame.
211
- - `Literal['top_plain']`: Add plain top side frame.
212
- extra : Extra print text at the end.
169
+ data : Print data.
170
+ title : Print title.
171
+ - `None`: Use variable name of argument `data`.
172
+ - `str` : Use this value.
173
+ - `Iterable[str]` : Connect this values and use.
174
+ width : Frame width.
175
+ - `None` : Use terminal display character size.
176
+ frame : Frame type.
177
+ - `Literal[`left`]`: Line beginning add character column.
178
+ - `Literal[`top`]`: Line head add character line, with title.
179
+ - `Literal[`box`]`: Add four borders, with title, automatic newline.
180
+ border : Border type.
181
+ - `Literal['ascii']`: Use ASCII character.
182
+ - `Literal['thick']`: Use thick line character.
183
+ - `Literal['double']`: Use double line character.
184
+ extra : Extra print text.
213
185
 
214
186
  Returns
215
187
  -------
216
188
  Standard input string.
217
189
  """
218
190
 
219
- # Beautify.
220
- text = beautify_text(data, title=title, width=width, frame=frame)
191
+ # Import.
192
+ from .rtext import frame_data
193
+
194
+ # Handle parameter.
195
+ if ConfigStdout.force_print_ascii:
196
+ border = 'ascii'
197
+
198
+ # Frame.
199
+ text = frame_data(
200
+ *data,
201
+ title=title,
202
+ width=width,
203
+ frame=frame,
204
+ border=border
205
+ )
221
206
 
222
207
  # Extra.
223
208
  if extra is not None:
224
- text += extra
209
+ text = f'{text}\n{extra}'
225
210
 
226
- # Print.
227
- stdin = input(text)
211
+ # Input.
212
+ string = input(text)
228
213
 
229
- return stdin
214
+ return string
230
215
 
231
216
 
232
217
  def stop_print() -> None:
@@ -333,9 +318,6 @@ def add_print_position() -> None:
333
318
  Preprocessed text.
334
319
  """
335
320
 
336
- # Break.
337
- if __s in ('\n', ' ', ''): return __s
338
-
339
321
  # Get parameter.
340
322
  stack_params = get_stack_param('full', 3)
341
323
  stack_floor = stack_params[-1]
@@ -348,11 +330,14 @@ def add_print_position() -> None:
348
330
  stack_floor = stack_params[-2]
349
331
 
350
332
  # Add.
351
- __s = 'File "%s", line %s\n%s' % (
352
- stack_floor['filename'],
353
- stack_floor['lineno'],
354
- __s
355
- )
333
+ position = 'File "%s", line %s' % (stack_floor['filename'], stack_floor['lineno'])
334
+
335
+ # Added.
336
+ if position in ConfigStdout._added_print_position:
337
+ return __s
338
+
339
+ ConfigStdout._added_print_position.add(position)
340
+ __s = '%s\n%s' % (position, __s)
356
341
 
357
342
  return __s
358
343
 
reykit/rsys.py CHANGED
@@ -51,7 +51,7 @@ from tkinter.filedialog import (
51
51
  askdirectory as tkinter_askdirectory
52
52
  )
53
53
 
54
- from .rbase import Base, ConfigMeta, throw
54
+ from .rbase import Base, ConfigMeta, throw, get_varname
55
55
 
56
56
 
57
57
  __all__ = (
@@ -257,7 +257,7 @@ def get_cmd_var(*vars: Any) -> list[Any]:
257
257
  """
258
258
 
259
259
  # Get parameter.
260
- vars_name = get_name(vars)
260
+ vars_name = get_varname('vars')
261
261
  vars_info = tuple(zip(vars_name, vars))
262
262
 
263
263
  # Set DOS command.
@@ -753,7 +753,7 @@ def memory_read(
753
753
 
754
754
  ## Throw exception.
755
755
  else:
756
- throw(value=dll_address)
756
+ throw(AssertionError, dll_address)
757
757
 
758
758
  # Get memory address.
759
759
  memory_address = dll_address + offset