Terminal Tools
Terminal tools
terminal_tools
inception
The inception module aids in creating nested terminal blocks (hence the name
"inception"). It provides a Context
class that manages a list of Scope
instances. Each Scope
instance represents a block of text that are buffered
in memory and printed to the terminal at each refresh.
Scope
Source code in terminal_tools/inception.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
refresh()
Clear the terminal and repaint with every scope up and including to this one
Source code in terminal_tools/inception.py
41 42 43 |
|
prompts
checkbox(message, **kwargs)
Wraps inquirer
's checkbox and catches KeyboardInterrupt
Source code in terminal_tools/prompts.py
118 119 120 121 122 |
|
confirm(message, *, cancel_fallback=False, **kwargs)
Wraps inquirer
's confirm input and catches KeyboardInterrupt
Source code in terminal_tools/prompts.py
125 126 127 128 129 130 131 |
|
file_selector(message='select a file', *, state=None)
Lets the user select a file from the filesystem.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str
|
The prompt message. Defaults to "select a file". |
'select a file'
|
|
str
|
Where to start the directory listing. Defaults to current working directory. |
required |
Returns:
Type | Description |
---|---|
(str, optional)
|
The absolute path selected by the user, or None if the user cancels the prompt. |
Source code in terminal_tools/prompts.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
|
get_drives()
Returns a list of the logically assigned drives on a windows system.
Returns:
Name | Type | Description |
---|---|---|
list |
A list of drive letters available and accessible on the system. |
Source code in terminal_tools/prompts.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
|
int_input(message, *, min=None, max=None, default=None, **kwargs)
Wraps inquirer
's text input and catches KeyboardInterrupt
Source code in terminal_tools/prompts.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
|
list_input(message, **kwargs)
Wraps inquirer
's list input and catches KeyboardInterrupt
Source code in terminal_tools/prompts.py
111 112 113 114 115 |
|
text(message, **kwargs)
Wraps inquirer
's text input and catches KeyboardInterrupt
Source code in terminal_tools/prompts.py
134 135 136 137 138 |
|
wrap_keyboard_interrupt(fn, fallback=None)
Calls fn
and catches KeyboardInterrupt, returning fallback
if it occurs.
Source code in terminal_tools/prompts.py
181 182 183 184 185 186 187 188 |
|
utils
clear_printed_lines(count)
Clear the last count
lines of the terminal. Useful for repainting
terminal output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
int
|
The number of lines to clear |
required |
Source code in terminal_tools/utils.py
67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
clear_terminal()
Clears the terminal
Source code in terminal_tools/utils.py
11 12 13 14 15 16 |
|
draw_box(text, *, padding_spaces=5, padding_lines=1)
Draw a box around the given text, which will be centered in the box.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str
|
The text to be drawn, may be multiline. ANSI formatting and emojis are not supported, as they mess with both the character count calculation and the monospace font. |
required |
|
int
|
Extra spaces on either side of the longest line. Defaults to 5. |
5
|
|
int
|
Extra lines above and below the text. Defaults to 1. |
1
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The text surrounded by a box. |
Source code in terminal_tools/utils.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
enable_windows_ansi_support()
Set up the Windows terminal to support ANSI escape codes, which will be needed for colored text, line clearing, and other terminal features.
Source code in terminal_tools/utils.py
52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
is_wsl()
Check if the environment is WSL2.
Source code in terminal_tools/utils.py
137 138 139 140 141 142 143 |
|
print_data_frame_summary(data_frame, title, apply_color='column_data_type', caption=None)
Print a summary table for dataframes with many columns
Source code in terminal_tools/utils.py
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
|
smart_print_data_frame(data_frame, title, apply_color='column_data_type', smart_print=True, caption=None)
Smart dataframe printing with adaptive display based on terminal width.
Automatically chooses between full table display and summary view based on terminal width and number of columns. Provides Rich-styled tables with configurable coloring.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
DataFrame
|
Polars DataFrame to display |
required |
|
str
|
Title text to display above the table |
required |
|
str | None
|
Color mode for the table display: - "column_data_type": Colors columns based on their Polars data types - "column-wise": Cycles through colors for each column - "row-wise": Cycles through colors for each row - None: No coloring (plain black and white display) |
'column_data_type'
|
|
bool
|
Controls adaptive display behavior: - True: Uses summary view for wide tables (>8 cols or narrow terminal) - False: Always uses full table display regardless of width |
True
|
|
str | None
|
Optional caption text displayed below the table |
None
|
Display Logic
- If smart_print=False: Always shows full table
- If smart_print=True and (>8 columns OR estimated column width <12): Shows summary with column info, data types, and examples
- Otherwise: Shows full table with all data
Examples:
>>> smart_print_data_frame(df, "My Data", apply_color=None)
>>> smart_print_data_frame(df, "Analysis Results", caption="Processing complete")
>>> smart_print_data_frame(df, "Wide Dataset", smart_print=False)
Source code in terminal_tools/utils.py
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
|
wait_for_key(prompt=False)
Waits for the user to press any key
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
bool
|
If true, a default text |
False
|
Source code in terminal_tools/utils.py
19 20 21 22 23 24 25 26 27 28 |
|