Skip to main content
  1. Lumesh Document/
  2. Lumesh Libs/Modules/

Lumesh Console Module

554 words·3 mins
Table of Contents

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

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

    1    Console.height()  # => 40

II. 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:
    1    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:

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

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

    1    Console.flush()

III. Terminal Mode Control
#
  1. Console.mode_raw Function: Enable raw input mode (disable line buffering)
    Parameters: None
    Return Value: none
    Example:

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

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

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

    1    Console.screen_normal()

IV. 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:
    1    Console.cursor_to 10 5
  2. Directional Movement:

    FunctionParameterFunctionality
    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 lines
  3. Console.cursor_save Function: Save the current cursor position
    Parameters: None
    Return Value: none
    Example:

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

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

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

    1    Console.cursor_show()

V. Keyboard Input
#
  1. Console.read_line Function: Read a line of input (displays input content)
    Parameters: None
    Return Value: string
    Example:

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

    1    let pwd = Console.read_password()
  3. Console.read_key Function: Read a single key
    Parameters: None
    Return Value: string (escape sequence for special keys)
    Example:

    1    let key = Console.read_key()
  4. 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
#

  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 exceptions on parameter type errors
    • Returns none on terminal operation failures
  3. ANSI Escape Sequences: All control functionalities are implemented using standard ANSI escape sequences.

Related