Lumesh Console Module

wiki libs

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
  1. console.width
    Function: Get the terminal width (number of columns)
    Parameters: None
    Return Value: integer (returns none on failure)
    Example:

    console.width()  # => 120
  2. console.height
    Function: Get the terminal height (number of rows)
    Parameters: None
    Return Value: integer (returns none on failure)
    Example:

    console.height()  # => 40

2. Terminal Control
  1. 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
  2. console.title
    Function: Set the terminal window title
    Parameters: title: string
    Return Value: none
    Example:

    console.title "My App"
  3. console.clear
    Function: Clear the terminal screen
    Parameters: None
    Return Value: none
    Example:

    console.clear()
  4. console.flush
    Function: Force refresh the output buffer
    Parameters: None
    Return Value: none
    Example:

    console.flush()

3. Terminal Mode Control
  1. console.mode_raw
    Function: Enable raw input mode_(disable line buffering)
    Parameters: None
    Return Value: none
    Example:

    console.mode_raw()
  2. console.mode_normal
    Function: Disable raw input mode_(enable line buffering)
    Parameters: None
    Return Value: none
    Example:

    console.mode_normal()
  3. console.screen_alternate
    Function: Enable alternate screen (preserve main screen content)
    Parameters: None
    Return Value: none
    Example:

    console.screen_alternate()
  4. console.screen_normal
    Function: Disable alternate screen (return to main screen)
    Parameters: None
    Return Value: none
    Example:

    console.screen_normal()

4. Cursor Control
  1. 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
  2. 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
  3. console.cursor_save
    Function: Save the current cursor position
    Parameters: None
    Return Value: none
    Example:

    console.cursor_save()
  4. console.cursor_restore
    Function: Restore the saved cursor position
    Parameters: None
    Return Value: none
    Example:

    console.cursor_restore()
  5. console.cursor_hide
    Function: Hide the cursor
    Parameters: None
    Return Value: none
    Example:

    console.cursor_hide()
  6. console.cursor_show
    Function: Show the cursor
    Parameters: None
    Return Value: none
    Example:

    console.cursor_show()

5. Keyboard Input
  1. console.read_line
    Function: Read a line of input (displays the input content)
    Parameters: None
    Return Value: string
    Example:

    let input = console.read_line()
  2. console.read_password
    Function: Read a password (hides the input content)
    Parameters: None
    Return Value: string
    Example:

    let pwd = console.read_password()
  3. 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()
  4. 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

  1. 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)
  2. Error Handling:

    • Throws an exception on parameter type errors
    • Returns none on terminal operation failures
  3. ANSI Escape Sequences:
    All control functionalities are implemented using standard ANSI escape sequences.