Module Path: console
Function Description: Provides terminal control, cursor operations, keyboard input, and other console interaction functionalities. Supports two calling methods:
- Functional Call:
Console.func(arg0, arg1...) - Command Call:
Console.func arg0 arg1...
Function Classification and Detailed Description#
I. Basic Terminal Information#
Console.widthFunction: Get the terminal width (number of columns)
Parameters: None
Return Value:integer(returnsnoneon failure)
Example:1 Console.width() # => 120Console.heightFunction: Get the terminal height (number of rows)
Parameters: None
Return Value:integer(returnsnoneon failure)
Example:1 Console.height() # => 40
II. Terminal Control#
Console.writeFunction: Output text at a specified position
Parameters:x: integer(column position)y: integer(row position)text: string(content to output)
Return Value:none
Example:
1 Console.write 10 5 "Hello" # Output "Hello" at row 5, column 10Console.titleFunction: Set the terminal window title
Parameters:title: string
Return Value:none
Example:1 Console.title "My App"Console.clearFunction: Clear the terminal screen
Parameters: None
Return Value:none
Example:1 Console.clear()Console.flushFunction: Force refresh the output buffer
Parameters: None
Return Value:none
Example:1 Console.flush()
III. Terminal Mode Control#
Console.mode_rawFunction: Enable raw input mode (disable line buffering)
Parameters: None
Return Value:none
Example:1 Console.mode_raw()Console.mode_normalFunction: Disable raw input mode (enable line buffering)
Parameters: None
Return Value:none
Example:1 Console.mode_normal()Console.screen_alternateFunction: Enable alternate screen (preserve main screen content)
Parameters: None
Return Value:none
Example:1 Console.screen_alternate()Console.screen_normalFunction: Disable alternate screen (return to main screen)
Parameters: None
Return Value:none
Example:1 Console.screen_normal()
IV. Cursor Control#
Console.cursor_toFunction: Move the cursor to a specified position
Parameters:x: integer(column position)y: integer(row position)
Return Value:none
Example:
1 Console.cursor_to 10 5Directional Movement:
Function Parameter Functionality Console.cursor_up()lines: integerMove up N lines Console.cursor_down()lines: integerMove down N lines Console.cursor_left()cols: integerMove left N columns Console.cursor_right()cols: integerMove right N columns Example:
1 Console.cursor_down 3 # Move down 3 linesConsole.cursor_saveFunction: Save the current cursor position
Parameters: None
Return Value:none
Example:1 Console.cursor_save()Console.cursor_restoreFunction: Restore the saved cursor position
Parameters: None
Return Value:none
Example:1 Console.cursor_restore()Console.cursor_hideFunction: Hide the cursor
Parameters: None
Return Value:none
Example:1 Console.cursor_hide()Console.cursor_showFunction: Show the cursor
Parameters: None
Return Value:none
Example:1 Console.cursor_show()
V. Keyboard Input#
Console.read_lineFunction: Read a line of input (displays input content)
Parameters: None
Return Value:string
Example:1 let input = Console.read_line()Console.read_passwordFunction: Read a password (hides input content)
Parameters: None
Return Value:string
Example:1 let pwd = Console.read_password()Console.read_keyFunction: Read a single key
Parameters: None
Return Value:string(escape sequence for special keys)
Example:1 let key = Console.read_key()Special Key Constants:
1 Console.keys.enter # Enter key 2 Console.keys.backspace # Backspace key 3 Console.keys.tab # Tab key 4 Console.keys.esc # ESC key 5 Console.keys.up # Up arrow 6 Console.keys.down # Down arrow 7 Console.keys.left # Left arrow 8 Console.keys.right # Right arrow 9 Console.keys.f1 # F1 function key 10 ... # Other function keys similarly
General Rules#
Coordinate System:
- The top-left corner is the origin (0, 0)
- The X-axis increases to the right (columns)
- The Y-axis increases downward (rows)
Error Handling:
- Throws exceptions on parameter type errors
- Returns
noneon terminal operation failures
ANSI Escape Sequences: All control functionalities are implemented using standard ANSI escape sequences.