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/__init__.py +1 -1
- reykit/rbase.py +68 -76
- reykit/rdata.py +12 -38
- reykit/rmonkey.py +1 -1
- reykit/ros.py +1 -1
- reykit/rstdout.py +124 -139
- reykit/rsys.py +3 -3
- reykit/rtext.py +309 -200
- {reykit-1.1.27.dist-info → reykit-1.1.29.dist-info}/METADATA +2 -2
- {reykit-1.1.27.dist-info → reykit-1.1.29.dist-info}/RECORD +12 -12
- {reykit-1.1.27.dist-info → reykit-1.1.29.dist-info}/WHEEL +0 -0
- {reykit-1.1.27.dist-info → reykit-1.1.29.dist-info}/licenses/LICENSE +0 -0
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,
|
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
|
-
'
|
24
|
+
'get_terminal_size',
|
26
25
|
'echo',
|
27
|
-
'
|
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
|
-
|
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
|
-
#
|
60
|
-
|
56
|
+
# Force print ascii.
|
57
|
+
force_print_ascii: bool = False
|
61
58
|
|
62
|
-
# print
|
63
|
-
|
59
|
+
# Added print position.
|
60
|
+
_added_print_position: set = set()
|
64
61
|
|
65
62
|
|
66
|
-
def
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
-
|
68
|
+
Get terminal display character size.
|
74
69
|
|
75
70
|
Parameters
|
76
71
|
----------
|
77
|
-
|
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
|
-
|
76
|
+
Column and line display character count.
|
99
77
|
"""
|
100
78
|
|
101
|
-
#
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
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
|
-
#
|
133
|
-
|
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
|
96
|
+
return terminal_size
|
136
97
|
|
137
98
|
|
138
99
|
def echo(
|
139
100
|
*data: Any,
|
140
|
-
title:
|
101
|
+
title: str | Iterable[str] | None = None,
|
141
102
|
width: int | None = None,
|
142
|
-
frame: Literal['
|
143
|
-
|
103
|
+
frame: Literal['left', 'top', 'box'] = 'box',
|
104
|
+
border: Literal['ascii', 'thick', 'double'] = 'double',
|
105
|
+
extra: str | None = None
|
106
|
+
) -> None:
|
144
107
|
"""
|
145
|
-
|
108
|
+
Frame data and print.
|
146
109
|
|
147
110
|
Parameters
|
148
111
|
----------
|
149
|
-
data :
|
150
|
-
title :
|
151
|
-
- `
|
152
|
-
- `
|
153
|
-
- `str
|
154
|
-
width :
|
155
|
-
- `None
|
156
|
-
|
157
|
-
|
158
|
-
- `Literal[
|
159
|
-
|
160
|
-
|
161
|
-
- `Literal['
|
162
|
-
|
163
|
-
- `Literal['
|
164
|
-
|
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
|
-
#
|
174
|
-
|
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
|
156
|
+
def ask(
|
183
157
|
*data: Any,
|
184
|
-
title:
|
158
|
+
title: str | Iterable[str] | None = None,
|
185
159
|
width: int | None = None,
|
186
|
-
frame: Literal['
|
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
|
-
|
165
|
+
Frame data and print and read string from standard input.
|
191
166
|
|
192
167
|
Parameters
|
193
168
|
----------
|
194
|
-
data :
|
195
|
-
title :
|
196
|
-
- `
|
197
|
-
- `
|
198
|
-
- `str
|
199
|
-
width :
|
200
|
-
- `None
|
201
|
-
|
202
|
-
|
203
|
-
- `Literal[
|
204
|
-
|
205
|
-
|
206
|
-
- `Literal['
|
207
|
-
|
208
|
-
- `Literal['
|
209
|
-
|
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
|
-
#
|
220
|
-
|
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
|
209
|
+
text = f'{text}\n{extra}'
|
225
210
|
|
226
|
-
#
|
227
|
-
|
211
|
+
# Input.
|
212
|
+
string = input(text)
|
228
213
|
|
229
|
-
return
|
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', ' ', '[0m'): 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
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
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 =
|
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(
|
756
|
+
throw(AssertionError, dll_address)
|
757
757
|
|
758
758
|
# Get memory address.
|
759
759
|
memory_address = dll_address + offset
|