dt-console 0.1.2__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.
- dt_console-0.1.2/CHANGELOG.md +4 -0
- dt_console-0.1.2/LICENSE +21 -0
- dt_console-0.1.2/PKG-INFO +187 -0
- dt_console-0.1.2/README.md +166 -0
- dt_console-0.1.2/dt_tools/cli/dt_console_demo.py +241 -0
- dt_console-0.1.2/dt_tools/console/console_helper.py +806 -0
- dt_console-0.1.2/dt_tools/console/msgbox.py +537 -0
- dt_console-0.1.2/dt_tools/console/progress_bar.py +141 -0
- dt_console-0.1.2/dt_tools/console/spinner.py +189 -0
- dt_console-0.1.2/pyproject.toml +40 -0
dt_console-0.1.2/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 JavaWiz1 (Al D'Amico)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: dt-console
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: Console helper tools for CLIs
|
|
5
|
+
Home-page: https://github.com/JavaWiz1/dt-console
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: python,dt-tools,cli,console,command-line,status bar,progress bar
|
|
8
|
+
Author: Al DAmico
|
|
9
|
+
Author-email: JavaWiz1@hotmail.com
|
|
10
|
+
Requires-Python: >=3.10,<4.0
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Requires-Dist: dt-misc
|
|
18
|
+
Project-URL: Repository, https://github.com/JavaWiz1/dt-console
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# dt-console
|
|
22
|
+
|
|
23
|
+
dt-console is a Python library to simplify CLI input and output for your python apps/scripts. It has been tested in Windows and Linux.
|
|
24
|
+
|
|
25
|
+
Features include:
|
|
26
|
+
<ul>
|
|
27
|
+
<li><b>ConsoleHelper</b> - manage window and cursor control</li>
|
|
28
|
+
<ul>
|
|
29
|
+
<li>Set console window title</li>
|
|
30
|
+
<li>Show/Hide console window, set fg/bg colors</li>
|
|
31
|
+
<li>Set cursor style, location, ...</li>
|
|
32
|
+
<li>Routines to print and colorize output text</li>
|
|
33
|
+
</ul>
|
|
34
|
+
<li><b>ConsoleInputHelper</b> - Keyboard input prompts with validation and timeouts.</li>
|
|
35
|
+
<li><b>MessageBox</b> - GUI messsagebox (alert, confirm, input, password)</li>
|
|
36
|
+
<li><b>ProgressBar</b> - Display visual progress on screen via configurable progress bar</li>
|
|
37
|
+
<li><b>Spinner</b> - Display visual progress on screen via configuable spinner control</li>
|
|
38
|
+
</ul>
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
## Installation
|
|
42
|
+
|
|
43
|
+
### Download source code from githup via git
|
|
44
|
+
```bash
|
|
45
|
+
git clone https://github.com/JavaWiz1/dt-console.git
|
|
46
|
+
```
|
|
47
|
+
Note, when downloading source, [Poetry](https://python-poetry.org/docs/) was used as the package manager. Poetry
|
|
48
|
+
handles creating the virtual environment and all dependent packages installs with proper versions.
|
|
49
|
+
|
|
50
|
+
To setup virtual environment with required production __AND__ dev ([sphinx](https://www.sphinx-doc.org/en/master/)) dependencies:
|
|
51
|
+
```bash
|
|
52
|
+
poetry install
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
with ONLY production packages (no sphinx):
|
|
56
|
+
```bash
|
|
57
|
+
poetry install --without dev
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
### use the package manager [pip](https://pip.pypa.io/en/stable/) to install dt-console.
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pip install dt-console [--user]
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Usage
|
|
68
|
+
A demo cli has been included to show how these modules can be used. The demo selectively displays each control (console tools, input prompt, messagebox, ProgressBar and Spinner) and source is provided to review for implementation details.
|
|
69
|
+
|
|
70
|
+
See [dt_tools.cli.dt_console_demos.py](https://github.com/JavaWiz1/dt-console/blob/develop/dt_tools/cli/dt_console_demos.py) for detailed demo examples (runnable demo)
|
|
71
|
+
|
|
72
|
+
To run the demo type:
|
|
73
|
+
```bash
|
|
74
|
+
python -m dt_tools.cli.dt_console_demos
|
|
75
|
+
|
|
76
|
+
# or if via source (and poetry)
|
|
77
|
+
poetry run python -m dt_tools.cli.dt_console_demos
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Developer package documentation contains details on all classes and supporting code (i.e. constant namespaces and enums) use for method calls. Docs can be found [here](https://htmlpreview.github.io/?https://github.com/JavaWiz1/dt-console/blob/develop/docs/html/index.html).
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
### Main classes/modules Overview
|
|
84
|
+
|
|
85
|
+
#### ConsoleHelper
|
|
86
|
+
ConsoleHelper provides methods for managing the console windows.
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
from dt_tools.console.console_helper import ConsoleHelper
|
|
90
|
+
import time
|
|
91
|
+
|
|
92
|
+
console.clear_screen(cursor_home=True)
|
|
93
|
+
|
|
94
|
+
console_size = console.get_console_size()
|
|
95
|
+
row, col = console.cursor_current_position()
|
|
96
|
+
print(f'Console size: {console_size}, cur pos: {row},{col}')
|
|
97
|
+
|
|
98
|
+
console.print_at(row=3, col=5, msg="Here we are at row 3, column 5", eol='\n\n')
|
|
99
|
+
time.sleep(.5)
|
|
100
|
+
|
|
101
|
+
blue = console.cwrap('blue', cc.CBLUE)
|
|
102
|
+
brown = console.cwrap('brown', cc.CBEIGE)
|
|
103
|
+
green = console.cwrap('green', cc.CGREEN)
|
|
104
|
+
text = f"The {blue} skies and the {brown} bear look wonderful in the {green} forest!"
|
|
105
|
+
print(text)
|
|
106
|
+
|
|
107
|
+
row, col = console.cursor_current_position()
|
|
108
|
+
print(f' at ({row},{col})', flush=True)
|
|
109
|
+
time.sleep(2)
|
|
110
|
+
console.print_at(row,col,'Finished')
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
#### ConsoleInputHelper
|
|
114
|
+
ConsoleInputHelper provides a customizable input prompt.
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
from dt_tools.console.console_helper import ConsoleInputHelper
|
|
118
|
+
|
|
119
|
+
console_input = ConsoleInputHelper()
|
|
120
|
+
|
|
121
|
+
resp = console_input.get_input_with_timeout(prompt='Do you want to continue (y/n) > ',
|
|
122
|
+
valid_responses=console_input.YES_NO_RESPONSE,
|
|
123
|
+
default='y',
|
|
124
|
+
timeout_secs=5)
|
|
125
|
+
print(f' returns: {resp}')
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
#### MessageBox
|
|
130
|
+
Message box implements Alert, Confirmation, Input Prompt, Password Prompt message boxes.
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
import dt_tools.console.msgbox as msgbox
|
|
134
|
+
|
|
135
|
+
resp = msgbox.alert(text='This is an alert box', title='ALERT no timeout')
|
|
136
|
+
print(f' mxgbox returns: {resp}')
|
|
137
|
+
|
|
138
|
+
resp = msgbox.alert(text='This is an alert box', title='ALERT w/Timeout', timeout=3000)
|
|
139
|
+
print(f' mxgbox returns: {resp}')
|
|
140
|
+
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
#### ProgressBar
|
|
144
|
+
ProgressBar is an easy to use, customizable console ProgressBar which displays percentage complete and elapsed time.
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
from dt_tools.console.progress_bar import ProgressBar
|
|
148
|
+
import time
|
|
149
|
+
|
|
150
|
+
print('Progress bar...')
|
|
151
|
+
pbar = ProgressBar(caption="Test bar 1", bar_length=40, max_increments=50, show_elapsed=False)
|
|
152
|
+
for incr in range(1,51):
|
|
153
|
+
pbar.display_progress(incr, f'incr [{incr}]')
|
|
154
|
+
time.sleep(.15)
|
|
155
|
+
|
|
156
|
+
print('\nProgress bar with elapsed time...')
|
|
157
|
+
pbar = ProgressBar(caption="Test bar 2", bar_length=40, max_increments=50, show_elapsed=True)
|
|
158
|
+
for incr in range(1,51):
|
|
159
|
+
pbar.display_progress(incr, f'incr [{incr}]')
|
|
160
|
+
time.sleep(.15)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
#### Spinner
|
|
164
|
+
Spinner is an easy to use, customizable console Spinner control which displays spinning icon and elapsed time.
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
from dt_tools.console.spinner import Spinner, SpinnerType
|
|
168
|
+
import time
|
|
169
|
+
|
|
170
|
+
# Example to display all spinner types for approx 5 sec. apiece
|
|
171
|
+
for spinner_type in SpinnerType:
|
|
172
|
+
spinner = Spinner(caption=spinner_type, spinner=spinner_type, show_elapsed=True)
|
|
173
|
+
spinner.start_spinner()
|
|
174
|
+
|
|
175
|
+
# Do long task...
|
|
176
|
+
for cnt in range(1,20):
|
|
177
|
+
time.sleep(.25)
|
|
178
|
+
|
|
179
|
+
spinner.stop_spinner()
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
## License
|
|
184
|
+
[MIT](https://choosealicense.com/licenses/mit/)
|
|
185
|
+
|
|
186
|
+
PyMsgBox - BSD for PyMsgBox (see source for msgbox.py)
|
|
187
|
+
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# dt-console
|
|
2
|
+
|
|
3
|
+
dt-console is a Python library to simplify CLI input and output for your python apps/scripts. It has been tested in Windows and Linux.
|
|
4
|
+
|
|
5
|
+
Features include:
|
|
6
|
+
<ul>
|
|
7
|
+
<li><b>ConsoleHelper</b> - manage window and cursor control</li>
|
|
8
|
+
<ul>
|
|
9
|
+
<li>Set console window title</li>
|
|
10
|
+
<li>Show/Hide console window, set fg/bg colors</li>
|
|
11
|
+
<li>Set cursor style, location, ...</li>
|
|
12
|
+
<li>Routines to print and colorize output text</li>
|
|
13
|
+
</ul>
|
|
14
|
+
<li><b>ConsoleInputHelper</b> - Keyboard input prompts with validation and timeouts.</li>
|
|
15
|
+
<li><b>MessageBox</b> - GUI messsagebox (alert, confirm, input, password)</li>
|
|
16
|
+
<li><b>ProgressBar</b> - Display visual progress on screen via configurable progress bar</li>
|
|
17
|
+
<li><b>Spinner</b> - Display visual progress on screen via configuable spinner control</li>
|
|
18
|
+
</ul>
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
### Download source code from githup via git
|
|
24
|
+
```bash
|
|
25
|
+
git clone https://github.com/JavaWiz1/dt-console.git
|
|
26
|
+
```
|
|
27
|
+
Note, when downloading source, [Poetry](https://python-poetry.org/docs/) was used as the package manager. Poetry
|
|
28
|
+
handles creating the virtual environment and all dependent packages installs with proper versions.
|
|
29
|
+
|
|
30
|
+
To setup virtual environment with required production __AND__ dev ([sphinx](https://www.sphinx-doc.org/en/master/)) dependencies:
|
|
31
|
+
```bash
|
|
32
|
+
poetry install
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
with ONLY production packages (no sphinx):
|
|
36
|
+
```bash
|
|
37
|
+
poetry install --without dev
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
### use the package manager [pip](https://pip.pypa.io/en/stable/) to install dt-console.
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install dt-console [--user]
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Usage
|
|
48
|
+
A demo cli has been included to show how these modules can be used. The demo selectively displays each control (console tools, input prompt, messagebox, ProgressBar and Spinner) and source is provided to review for implementation details.
|
|
49
|
+
|
|
50
|
+
See [dt_tools.cli.dt_console_demos.py](https://github.com/JavaWiz1/dt-console/blob/develop/dt_tools/cli/dt_console_demos.py) for detailed demo examples (runnable demo)
|
|
51
|
+
|
|
52
|
+
To run the demo type:
|
|
53
|
+
```bash
|
|
54
|
+
python -m dt_tools.cli.dt_console_demos
|
|
55
|
+
|
|
56
|
+
# or if via source (and poetry)
|
|
57
|
+
poetry run python -m dt_tools.cli.dt_console_demos
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Developer package documentation contains details on all classes and supporting code (i.e. constant namespaces and enums) use for method calls. Docs can be found [here](https://htmlpreview.github.io/?https://github.com/JavaWiz1/dt-console/blob/develop/docs/html/index.html).
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
### Main classes/modules Overview
|
|
64
|
+
|
|
65
|
+
#### ConsoleHelper
|
|
66
|
+
ConsoleHelper provides methods for managing the console windows.
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from dt_tools.console.console_helper import ConsoleHelper
|
|
70
|
+
import time
|
|
71
|
+
|
|
72
|
+
console.clear_screen(cursor_home=True)
|
|
73
|
+
|
|
74
|
+
console_size = console.get_console_size()
|
|
75
|
+
row, col = console.cursor_current_position()
|
|
76
|
+
print(f'Console size: {console_size}, cur pos: {row},{col}')
|
|
77
|
+
|
|
78
|
+
console.print_at(row=3, col=5, msg="Here we are at row 3, column 5", eol='\n\n')
|
|
79
|
+
time.sleep(.5)
|
|
80
|
+
|
|
81
|
+
blue = console.cwrap('blue', cc.CBLUE)
|
|
82
|
+
brown = console.cwrap('brown', cc.CBEIGE)
|
|
83
|
+
green = console.cwrap('green', cc.CGREEN)
|
|
84
|
+
text = f"The {blue} skies and the {brown} bear look wonderful in the {green} forest!"
|
|
85
|
+
print(text)
|
|
86
|
+
|
|
87
|
+
row, col = console.cursor_current_position()
|
|
88
|
+
print(f' at ({row},{col})', flush=True)
|
|
89
|
+
time.sleep(2)
|
|
90
|
+
console.print_at(row,col,'Finished')
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
#### ConsoleInputHelper
|
|
94
|
+
ConsoleInputHelper provides a customizable input prompt.
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from dt_tools.console.console_helper import ConsoleInputHelper
|
|
98
|
+
|
|
99
|
+
console_input = ConsoleInputHelper()
|
|
100
|
+
|
|
101
|
+
resp = console_input.get_input_with_timeout(prompt='Do you want to continue (y/n) > ',
|
|
102
|
+
valid_responses=console_input.YES_NO_RESPONSE,
|
|
103
|
+
default='y',
|
|
104
|
+
timeout_secs=5)
|
|
105
|
+
print(f' returns: {resp}')
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
#### MessageBox
|
|
110
|
+
Message box implements Alert, Confirmation, Input Prompt, Password Prompt message boxes.
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
import dt_tools.console.msgbox as msgbox
|
|
114
|
+
|
|
115
|
+
resp = msgbox.alert(text='This is an alert box', title='ALERT no timeout')
|
|
116
|
+
print(f' mxgbox returns: {resp}')
|
|
117
|
+
|
|
118
|
+
resp = msgbox.alert(text='This is an alert box', title='ALERT w/Timeout', timeout=3000)
|
|
119
|
+
print(f' mxgbox returns: {resp}')
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
#### ProgressBar
|
|
124
|
+
ProgressBar is an easy to use, customizable console ProgressBar which displays percentage complete and elapsed time.
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
from dt_tools.console.progress_bar import ProgressBar
|
|
128
|
+
import time
|
|
129
|
+
|
|
130
|
+
print('Progress bar...')
|
|
131
|
+
pbar = ProgressBar(caption="Test bar 1", bar_length=40, max_increments=50, show_elapsed=False)
|
|
132
|
+
for incr in range(1,51):
|
|
133
|
+
pbar.display_progress(incr, f'incr [{incr}]')
|
|
134
|
+
time.sleep(.15)
|
|
135
|
+
|
|
136
|
+
print('\nProgress bar with elapsed time...')
|
|
137
|
+
pbar = ProgressBar(caption="Test bar 2", bar_length=40, max_increments=50, show_elapsed=True)
|
|
138
|
+
for incr in range(1,51):
|
|
139
|
+
pbar.display_progress(incr, f'incr [{incr}]')
|
|
140
|
+
time.sleep(.15)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
#### Spinner
|
|
144
|
+
Spinner is an easy to use, customizable console Spinner control which displays spinning icon and elapsed time.
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
from dt_tools.console.spinner import Spinner, SpinnerType
|
|
148
|
+
import time
|
|
149
|
+
|
|
150
|
+
# Example to display all spinner types for approx 5 sec. apiece
|
|
151
|
+
for spinner_type in SpinnerType:
|
|
152
|
+
spinner = Spinner(caption=spinner_type, spinner=spinner_type, show_elapsed=True)
|
|
153
|
+
spinner.start_spinner()
|
|
154
|
+
|
|
155
|
+
# Do long task...
|
|
156
|
+
for cnt in range(1,20):
|
|
157
|
+
time.sleep(.25)
|
|
158
|
+
|
|
159
|
+
spinner.stop_spinner()
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
## License
|
|
164
|
+
[MIT](https://choosealicense.com/licenses/mit/)
|
|
165
|
+
|
|
166
|
+
PyMsgBox - BSD for PyMsgBox (see source for msgbox.py)
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import time
|
|
2
|
+
|
|
3
|
+
import dt_tools.console.console_helper as helper
|
|
4
|
+
from dt_tools.console.console_helper import (
|
|
5
|
+
ColorBG,
|
|
6
|
+
ColorFG,
|
|
7
|
+
ColorStyle,
|
|
8
|
+
ConsoleHelper,
|
|
9
|
+
ConsoleInputHelper,
|
|
10
|
+
CursorShape,
|
|
11
|
+
_CursorAttribute,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def console_helper_demo():
|
|
16
|
+
console = ConsoleHelper()
|
|
17
|
+
cih = ConsoleInputHelper()
|
|
18
|
+
|
|
19
|
+
helper.enable_ctrl_c_handler()
|
|
20
|
+
|
|
21
|
+
wait_seconds = 2
|
|
22
|
+
|
|
23
|
+
console.clear_screen(cursor_home=True)
|
|
24
|
+
console_size = console.get_console_size()
|
|
25
|
+
row, col = console.cursor_current_position()
|
|
26
|
+
console.set_viewport(1,console_size[0]-1)
|
|
27
|
+
console.print_with_wait(f'Console size: {console_size}, cur pos: {row},{col}', wait_seconds, eol='\n\n')
|
|
28
|
+
console.cursor_save_position()
|
|
29
|
+
|
|
30
|
+
console.print_line_seperator('Test color attributes', 40)
|
|
31
|
+
color_code = ConsoleHelper().color_code(ColorStyle.ITALIC, ColorFG.RED, ColorBG.WHITEBG)
|
|
32
|
+
token = ConsoleHelper().cwrap('string', color_code)
|
|
33
|
+
print(f'This {token} is Red Italic on White BG')
|
|
34
|
+
print(f'This {ConsoleHelper().cwrap("string", ColorFG.GREEN)} is Green')
|
|
35
|
+
print(f'This {ConsoleHelper().cwrap("string", ColorFG.RED)} is Red')
|
|
36
|
+
print(f'This {ConsoleHelper().cwrap("string", ColorFG.RED, None, ColorStyle.ITALIC)} is Italic Red')
|
|
37
|
+
print(f'This {ConsoleHelper().cwrap("string", ColorFG.RED, None, ColorStyle.BOLD)} is Bold Red\n')
|
|
38
|
+
cih.get_input_with_timeout('Press ENTER to continue', timeout_secs=10)
|
|
39
|
+
|
|
40
|
+
console.cursor_restore_position()
|
|
41
|
+
console.clear_to_EOS()
|
|
42
|
+
|
|
43
|
+
console.print_line_seperator('Test cursor attributes', 40)
|
|
44
|
+
for attr in _CursorAttribute:
|
|
45
|
+
console.cursor_attribute = attr
|
|
46
|
+
console.debug_display_cursor_location()
|
|
47
|
+
console.print_with_wait(f'CURSOR: {attr} ', wait_seconds, eol='')
|
|
48
|
+
print()
|
|
49
|
+
print()
|
|
50
|
+
cih.get_input_with_timeout('Press ENTER to continue', timeout_secs=10)
|
|
51
|
+
console.cursor_restore_position()
|
|
52
|
+
console.clear_to_EOS()
|
|
53
|
+
|
|
54
|
+
console.print_line_seperator('Test cursor shape...', 40)
|
|
55
|
+
for shape in CursorShape:
|
|
56
|
+
console.cursor_shape = shape
|
|
57
|
+
console.debug_display_cursor_location()
|
|
58
|
+
console.print_with_wait(f'CURSOR: {shape}', wait_seconds, eol = ' ')
|
|
59
|
+
print()
|
|
60
|
+
cih.get_input_with_timeout('Press ENTER to continue', timeout_secs=10)
|
|
61
|
+
console.clear_screen()
|
|
62
|
+
|
|
63
|
+
console.cursor_shape = CursorShape.STEADY_BLOCK
|
|
64
|
+
console.display_status('Test Rows...')
|
|
65
|
+
for row in range(1, console_size[0]+1):
|
|
66
|
+
console.print_at(row, 60, f'Row {row}', eol='')
|
|
67
|
+
console.cursor_move(row=1,column=1)
|
|
68
|
+
console.print_with_wait(f'Console size: {console_size} and current position: {row},{col}', wait_seconds)
|
|
69
|
+
console.cursor_move(5,1)
|
|
70
|
+
print(f'Look at the beautiful {console.cwrap("blue",ColorFG.BLUE)} sky')
|
|
71
|
+
console.debug_display_cursor_location(f'After {console.cwrap("blue",ColorFG.BLUE)} sky')
|
|
72
|
+
time.sleep(wait_seconds)
|
|
73
|
+
|
|
74
|
+
print('Check cursor positioning...')
|
|
75
|
+
console.print_at(10, 5, "Should print at location 10,5 xxxxxxx", eol='')
|
|
76
|
+
console.debug_display_cursor_location()
|
|
77
|
+
time.sleep(wait_seconds)
|
|
78
|
+
console.cursor_left(7)
|
|
79
|
+
|
|
80
|
+
console.clear_to_EOL()
|
|
81
|
+
console.debug_display_cursor_location(f"Clear to {console.cwrap('EOL',ColorFG.GREEN)}")
|
|
82
|
+
time.sleep(wait_seconds)
|
|
83
|
+
|
|
84
|
+
print('abc', end='')
|
|
85
|
+
console.debug_display_cursor_location()
|
|
86
|
+
time.sleep(wait_seconds)
|
|
87
|
+
|
|
88
|
+
console.clear_to_BOL()
|
|
89
|
+
console.debug_display_cursor_location(f"Clear to {console.cwrap('BOL',ColorFG.GREEN)}")
|
|
90
|
+
time.sleep(wait_seconds)
|
|
91
|
+
|
|
92
|
+
console.clear_to_BOS()
|
|
93
|
+
console.debug_display_cursor_location(f"Clear to {console.cwrap('BOS',ColorFG.GREEN)}")
|
|
94
|
+
time.sleep(wait_seconds)
|
|
95
|
+
|
|
96
|
+
console.cursor_move(12,1)
|
|
97
|
+
console.debug_display_cursor_location( "Moved to 12,1")
|
|
98
|
+
time.sleep(wait_seconds)
|
|
99
|
+
|
|
100
|
+
console.clear_to_EOS()
|
|
101
|
+
console.debug_display_cursor_location(f"Clear to {console.cwrap('EOS',ColorFG.GREEN)}")
|
|
102
|
+
time.sleep(wait_seconds)
|
|
103
|
+
|
|
104
|
+
console.print_with_wait(f'Console size: {console_size}, cur pos: {row},{col}', wait_seconds, eol='\n\n')
|
|
105
|
+
console.set_viewport(2,console_size[0]-1)
|
|
106
|
+
|
|
107
|
+
console.clear_screen()
|
|
108
|
+
console.print_line_seperator('Check scrolling...', 40)
|
|
109
|
+
for row in range(1, 50):
|
|
110
|
+
print(f'Row {row}')
|
|
111
|
+
if row % 5 == 0:
|
|
112
|
+
console.debug_display_cursor_location('Scrolling...')
|
|
113
|
+
time.sleep(.5)
|
|
114
|
+
cih.get_input_with_timeout('Press ENTER to continue', timeout_secs=10)
|
|
115
|
+
|
|
116
|
+
console.set_viewport()
|
|
117
|
+
console.clear_screen()
|
|
118
|
+
console.print_line_seperator('Display color palette, codes are [style,fg,bg]...', 40)
|
|
119
|
+
print('')
|
|
120
|
+
time.sleep(wait_seconds)
|
|
121
|
+
console._display_color_palette()
|
|
122
|
+
|
|
123
|
+
console.cursor_shape = CursorShape.DEFAULT
|
|
124
|
+
print(f"End of {console.cwrap('ConsoleHelper', ColorFG.YELLOW)} demo.")
|
|
125
|
+
|
|
126
|
+
def console_input_helper_demo():
|
|
127
|
+
console = ConsoleHelper()
|
|
128
|
+
console_input = ConsoleInputHelper()
|
|
129
|
+
print()
|
|
130
|
+
test_name = console.cwrap('Input with Timeout', ColorStyle.ITALIC)
|
|
131
|
+
print(f'{test_name}: default response is y, timeout 3 secs...')
|
|
132
|
+
resp = console_input.get_input_with_timeout('Test prompt (y/n) > ', console_input.YES_NO_RESPONSE, default='y', timeout_secs=3)
|
|
133
|
+
print(f' returns: {resp}')
|
|
134
|
+
test_name = console.cwrap('Wait with Timeout', ColorStyle.ITALIC)
|
|
135
|
+
print(f'\n{test_name}: Wait 5 seconds, or press enter to abort wait')
|
|
136
|
+
console_input.wait_with_bypass(5)
|
|
137
|
+
|
|
138
|
+
print(f"End of {console.cwrap('ConsoleInputHelper', ColorFG.YELLOW)} demo.")
|
|
139
|
+
|
|
140
|
+
def message_box_demo():
|
|
141
|
+
import tkinter as tk
|
|
142
|
+
|
|
143
|
+
import dt_tools.console.msgbox as msgbox
|
|
144
|
+
|
|
145
|
+
console = ConsoleHelper()
|
|
146
|
+
|
|
147
|
+
print('Alert box (no timeout)')
|
|
148
|
+
resp = msgbox.alert('This is an alert box', 'ALERT no timeout')
|
|
149
|
+
print(f' returns: {console.cwrap(resp, ColorFG.GREEN)}')
|
|
150
|
+
|
|
151
|
+
print('Alert box (with timeout, 3 sec)')
|
|
152
|
+
resp = msgbox.alert('This is an alert box', 'ALERT w/Timeout', timeout=3000)
|
|
153
|
+
print(f' returns: {console.cwrap(resp, ColorFG.GREEN)}')
|
|
154
|
+
|
|
155
|
+
txt = ''
|
|
156
|
+
for k,v in tk.__dict__.items():
|
|
157
|
+
if not k.startswith('_') and isinstance(v, int):
|
|
158
|
+
txt += f'{k:20} {v}\n'
|
|
159
|
+
|
|
160
|
+
print('Alert box (multi-line)')
|
|
161
|
+
msgbox._used_font_family = msgbox.MB_FontFamily.MONOSPACE
|
|
162
|
+
msgbox._used_font_size = msgbox.MB_FontSize.MONOSPACE
|
|
163
|
+
resp = msgbox.alert(txt,"ALERT-MULTILINE (no timeout)")
|
|
164
|
+
print(f' returns: {console.cwrap(resp, ColorFG.GREEN)}')
|
|
165
|
+
|
|
166
|
+
msgbox._used_font_family = msgbox.MB_FontFamily.PROPORTIONAL
|
|
167
|
+
msgbox._used_font_size = msgbox.MB_FontSize.PROPORTIONAL
|
|
168
|
+
print('Confirmation box (no timeout)')
|
|
169
|
+
resp = msgbox.confirm('this is a confirm box, no timeout', "CONFIRM")
|
|
170
|
+
print(f' returns: {console.cwrap(resp, ColorFG.GREEN)}')
|
|
171
|
+
|
|
172
|
+
print('Confirmation box (3 sec timeout)')
|
|
173
|
+
resp = msgbox.confirm('this is a confirm box, 3 sec timeout', "CONFIRM", timeout=3000)
|
|
174
|
+
print(f' returns: {console.cwrap(resp, ColorFG.GREEN)}')
|
|
175
|
+
|
|
176
|
+
print('Prompt box (no timeout)')
|
|
177
|
+
resp = msgbox.prompt('This is a prompt box', 'PROMPT', 'default')
|
|
178
|
+
print(f' returns: {console.cwrap(resp, ColorFG.GREEN)}')
|
|
179
|
+
|
|
180
|
+
print('Prompt box (3 sec timeout)')
|
|
181
|
+
resp = msgbox.prompt('This is a prompt box', 'PROMPT (3 sec timeout)', 'default', timeout=3000)
|
|
182
|
+
print(f' returns: {console.cwrap(resp, ColorFG.GREEN)}')
|
|
183
|
+
|
|
184
|
+
print('Password box (no timeout)')
|
|
185
|
+
resp = msgbox.password('This is a password box', 'PASSWORD', 'SuperSecretPassword')
|
|
186
|
+
print(f' returns: {console.cwrap(resp, ColorFG.GREEN)}')
|
|
187
|
+
|
|
188
|
+
print(f"End of {console.cwrap('MessageBox', ColorFG.YELLOW)} demo.")
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def progress_bar_demo():
|
|
192
|
+
from dt_tools.console.progress_bar import ProgressBar
|
|
193
|
+
|
|
194
|
+
sleep_time = .15
|
|
195
|
+
print('Progress bar...')
|
|
196
|
+
pbar = ProgressBar("Test bar", bar_length=40, max_increments=50, show_elapsed=False)
|
|
197
|
+
for incr in range(1,51):
|
|
198
|
+
pbar.display_progress(incr, f'incr [{incr}]')
|
|
199
|
+
time.sleep(sleep_time)
|
|
200
|
+
|
|
201
|
+
print('\nProgress bar with elapsed time...')
|
|
202
|
+
pbar = ProgressBar("Test bar", bar_length=40, max_increments=50, show_elapsed=True)
|
|
203
|
+
for incr in range(1,51):
|
|
204
|
+
pbar.display_progress(incr, f'incr [{incr}]')
|
|
205
|
+
time.sleep(sleep_time)
|
|
206
|
+
print(f"End of {console.cwrap('ProgressBar', ColorFG.YELLOW)} demo.")
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def spinner_demo():
|
|
210
|
+
from dt_tools.console.spinner import Spinner, SpinnerType
|
|
211
|
+
|
|
212
|
+
sleep_time = .25
|
|
213
|
+
for spinner_type in SpinnerType:
|
|
214
|
+
spinner = Spinner(caption=spinner_type, spinner=spinner_type, show_elapsed=True)
|
|
215
|
+
spinner.start_spinner()
|
|
216
|
+
for cnt in range(1,20):
|
|
217
|
+
time.sleep(sleep_time)
|
|
218
|
+
spinner.stop_spinner()
|
|
219
|
+
print(f"End of {console.cwrap('Spinner',ColorFG.YELLOW)} demo.")
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
if __name__ == '__main__':
|
|
223
|
+
DEMOS = {
|
|
224
|
+
"ConsoleHelper": console_helper_demo,
|
|
225
|
+
"ConsoleInputHelper": console_input_helper_demo,
|
|
226
|
+
"MessageBox": message_box_demo,
|
|
227
|
+
"ProgressBar": progress_bar_demo,
|
|
228
|
+
"Spinner": spinner_demo
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
console = ConsoleHelper()
|
|
232
|
+
console_input = ConsoleInputHelper()
|
|
233
|
+
console.clear_screen()
|
|
234
|
+
for name, demo_func in DEMOS.items():
|
|
235
|
+
demo_name = console.cwrap(name, ColorFG.YELLOW)
|
|
236
|
+
resp = console_input.get_input_with_timeout(f'Demo {demo_name} Functions (y/n) > ',
|
|
237
|
+
console_input.YES_NO_RESPONSE, default='n',
|
|
238
|
+
timeout_secs=10).lower()
|
|
239
|
+
if resp == 'y':
|
|
240
|
+
demo_func()
|
|
241
|
+
print()
|