Raxol.Terminal.ANSI.ScreenModes (Raxol v0.2.0)

View Source

Handles screen mode transitions and state management. This includes alternate screen buffer, cursor visibility, line wrapping, and other terminal modes.

Summary

Functions

Clears the current line based on the mode parameter.

Clears the screen based on the mode parameter.

Deletes n lines starting from the current cursor position.

Gets the current auto-repeat mode.

Gets the current column width mode.

Gets the current interlacing mode.

Gets the current screen mode.

Inserts n lines at the current cursor position.

Looks up a DEC private mode code and returns the corresponding mode atom.

Looks up a standard mode code and returns the corresponding mode atom.

Checks if a specific mode is enabled.

Creates a new screen state with default values.

Resets a specific screen mode flag.

Sets a specific screen mode flag.

Switches between screen modes, saving the current state if needed.

Switches a specific mode on or off.

Types

screen_mode()

@type screen_mode() ::
  :normal | :alternate | :application | :origin | :insert | :replace

screen_state()

@type screen_state() :: %{
  mode: screen_mode(),
  cursor_visible: boolean(),
  auto_wrap: boolean(),
  origin_mode: boolean(),
  insert_mode: boolean(),
  line_feed_mode: boolean(),
  column_width_mode: :normal | :wide,
  auto_repeat_mode: boolean(),
  interlacing_mode: boolean(),
  saved_state: map() | nil
}

Functions

clear_line(emulator, n)

Clears the current line based on the mode parameter.

Parameters

  • emulator - The terminal emulator state
  • n - The mode for clearing the line:
    • 0: Clear from cursor to end of line
    • 1: Clear from start of line to cursor
    • 2: Clear entire line

Returns

Updated emulator state

clear_screen(emulator, n)

Clears the screen based on the mode parameter.

Parameters

  • emulator - The terminal emulator state
  • n - The mode for clearing the screen:
    • 0: Clear from cursor to end of screen
    • 1: Clear from start of screen to cursor
    • 2: Clear entire screen
    • 3: Clear entire screen and scrollback buffer

Returns

Updated emulator state

delete_line(emulator, n)

Deletes n lines starting from the current cursor position.

Parameters

  • emulator - The terminal emulator state
  • n - The number of lines to delete

Returns

Updated emulator state

get_auto_repeat_mode(state)

@spec get_auto_repeat_mode(screen_state()) :: boolean()

Gets the current auto-repeat mode.

get_column_width_mode(state)

@spec get_column_width_mode(screen_state()) :: :normal | :wide

Gets the current column width mode.

get_interlacing_mode(state)

@spec get_interlacing_mode(screen_state()) :: boolean()

Gets the current interlacing mode.

get_mode(state)

@spec get_mode(screen_state()) :: screen_mode()

Gets the current screen mode.

insert_line(emulator, n)

Inserts n lines at the current cursor position.

Parameters

  • emulator - The terminal emulator state
  • n - The number of lines to insert

Returns

Updated emulator state

lookup_private(code)

@spec lookup_private(integer()) :: atom() | nil

Looks up a DEC private mode code and returns the corresponding mode atom.

lookup_standard(code)

@spec lookup_standard(integer()) :: atom() | nil

Looks up a standard mode code and returns the corresponding mode atom.

mode_enabled?(state, mode_flag)

@spec mode_enabled?(screen_state(), atom()) :: boolean()

Checks if a specific mode is enabled.

new()

@spec new() :: %{
  mode: :normal,
  cursor_visible: true,
  auto_wrap: true,
  origin_mode: false,
  insert_mode: false,
  line_feed_mode: false,
  column_width_mode: :normal,
  auto_repeat_mode: false,
  interlacing_mode: false,
  saved_state: nil
}

Creates a new screen state with default values.

reset_mode(state, mode_flag)

@spec reset_mode(screen_state(), atom()) :: screen_state()

Resets a specific screen mode flag.

set_mode(state, mode_flag)

@spec set_mode(screen_state(), atom()) :: screen_state()

Sets a specific screen mode flag.

switch_mode(state, new_mode)

@spec switch_mode(screen_state(), screen_mode()) :: screen_state()

Switches between screen modes, saving the current state if needed.

switch_mode(state, mode_flag, enable)

@spec switch_mode(screen_state(), atom(), boolean()) :: screen_state()

Switches a specific mode on or off.