Terminal
- class ConsoleM.Core.terminal.Terminal[source]
Bases:
objectA high-level interface for terminal manipulation and input handling.
This class provides methods for: - Screen manipulation (clear, move cursor) - Input handling - Cursor control - Terminal size detection
Example
>>> term = Terminal() >>> term.clear() >>> term.move_cursor(1, 1) >>> width, height = term.get_terminal_size()
- __init__()[source]
Initialize a new Terminal instance.
This creates a terminal interface that supports: - Screen manipulation (clear, move cursor) - Input handling - Cursor control - Terminal size detection
- Raises:
NotImplementedError – If running on Windows (not supported yet) or unsupported OS
- static clear_line()[source]
Clear the current line from cursor position to the end.
This is useful for updating progress or status lines.
- static clear_lines_above(n: int)[source]
Clear n lines above the current cursor position.
- Parameters:
n (int) – Number of lines to clear above the current position
- static create_alternate_screen()[source]
Create an alternate screen buffer.
This is useful for full-screen applications like text editors. The original screen content is preserved and can be restored.
- static restore_alternate_screen()[source]
Restore the original screen after using alternate screen.
This restores the terminal to its previous state.
- static clear()[source]
Clear the entire terminal screen.
This is equivalent to the ‘clear’ command in the terminal.
- static move_cursor(x: int, y: int)[source]
Move the cursor to the specified position.
Example
>>> term.move_cursor(1, 1) # Move to top-left corner
- static move_cursor_relative(x: int, y: int)[source]
Move the cursor relative to its current position.
- Parameters:
Example
>>> term.move_cursor_relative(1, 0) # Move one column right >>> term.move_cursor_relative(-1, 0) # Move one column left
- handle_key_input()[source]
Start capturing keyboard input in a separate thread.
This enables non-blocking keyboard input handling. Use get_key_from_queue() to retrieve pressed keys.
- stop_handle_key_input()[source]
Stop capturing keyboard input.
This should be called when you’re done with input handling.
- get_key_from_str(key: str) Keys | None[source]
Get the key objectfrom a string.
- Parameters:
key (str) – The key to get
- Returns:
The key or None if not found
- Return type:
Keys
- hide_cursor()[source]
Hide the terminal cursor.
Useful for full-screen applications or when you don’t want the cursor visible.