Lumesh Console Operation Module Documentation
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 Categories and Detailed Descriptions
1. Basic Terminal Information
console.width
Function: Get the terminal width (number of columns)
Parameters: None
Return Value:integer
(returnsnone
on failure)
Example:console.width() # => 120
console.height
Function: Get the terminal height (number of rows)
Parameters: None
Return Value:integer
(returnsnone
on failure)
Example:console.height() # => 40
2. Terminal Control
console.write
Function: Output text at a specified position
Parameters:x: integer
(column position)y: integer
(row position)text: string
(content to output)
Return Value:none
Example:
console.write 10 5 "Hello" # Output "Hello" at row 5, column 10
console.title
Function: Set the terminal window title
Parameters:title: string
Return Value:none
Example:console.title "My App"
console.clear
Function: Clear the terminal screen
Parameters: None
Return Value:none
Example:console.clear()
console.flush
Function: Force refresh the output buffer
Parameters: None
Return Value:none
Example:console.flush()
3. Terminal Mode Control
console.mode_raw
Function: Enable raw input mode_(disable line buffering)
Parameters: None
Return Value:none
Example:console.mode_raw()
console.mode_normal
Function: Disable raw input mode_(enable line buffering)
Parameters: None
Return Value:none
Example:console.mode_normal()
console.screen_alternate
Function: Enable alternate screen (preserve main screen content)
Parameters: None
Return Value:none
Example:console.screen_alternate()
console.screen_normal
Function: Disable alternate screen (return to main screen)
Parameters: None
Return Value:none
Example:console.screen_normal()
4. Cursor Control
console.cursor_to
Function: Move the cursor to a specified position
Parameters:x: integer
(column position)y: integer
(row position)
Return Value:none
Example:
console.cursor_to 10 5
Directional Movement:
Function Parameters Functionality console.cursor_up()
lines: integer
Move up N rows console.cursor_down()
lines: integer
Move down N rows console.cursor_left()
cols: integer
Move left N columns console.cursor_right()
cols: integer
Move right N columns Example:
console.cursor_down 3 # Move down 3 rows
console.cursor_save
Function: Save the current cursor position
Parameters: None
Return Value:none
Example:console.cursor_save()
console.cursor_restore
Function: Restore the saved cursor position
Parameters: None
Return Value:none
Example:console.cursor_restore()
console.cursor_hide
Function: Hide the cursor
Parameters: None
Return Value:none
Example:console.cursor_hide()
console.cursor_show
Function: Show the cursor
Parameters: None
Return Value:none
Example:console.cursor_show()
5. Keyboard Input
console.read_line
Function: Read a line of input (displays the input content)
Parameters: None
Return Value:string
Example:let input = console.read_line()
console.read_password
Function: Read a password (hides the input content)
Parameters: None
Return Value:string
Example:let pwd = console.read_password()
console.read_key
Function: Read a single key press
Parameters: None
Return Value:string
(escape sequence for special keys)
Example:let key = console.read_key()
Special Key Constants:
console.keys.enter # Enter key
console.keys.backspace # Backspace key
console.keys.tab # Tab key
console.keys.esc # ESC key
console.keys.up # Up arrow
console.keys.down # Down arrow
console.keys.left # Left arrow
console.keys.right # Right arrow
console.keys.f1 # F1 function key
... # 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 an exception on parameter type errors
- Returns
none
on terminal operation failures
ANSI Escape Sequences:
All control functionalities are implemented using standard ANSI escape sequences.