Raxol.Terminal.Buffer.Manager.Buffer (Raxol v0.3.0)

View Source

Handles buffer operations and synchronization for the terminal. Provides functionality for buffer manipulation, double buffering, and synchronization.

Summary

Functions

Clears the active buffer.

Copies a region from one position to another in the active buffer.

Fills a region in the active buffer with a cell.

Gets a cell from the active buffer.

Gets the differences between the active and back buffers.

Creates a new buffer with the specified dimensions.

Resizes the active buffer.

Scrolls a region in the active buffer.

Sets a cell in the active buffer.

Synchronizes the back buffer with the active buffer.

Functions

clear(state)

Clears the active buffer.

Examples

iex> state = State.new(80, 24)
iex> state = Buffer.clear(state)
iex> Buffer.get_cell(state, 0, 0)
%Cell{char: " ", fg: :default, bg: :default}

copy_region(state, src_x, src_y, dst_x, dst_y, width, height)

Copies a region from one position to another in the active buffer.

Examples

iex> state = State.new(80, 24)
iex> cell = %Cell{char: "A", fg: :red, bg: :blue}
iex> state = Buffer.set_cell(state, 0, 0, cell)
iex> state = Buffer.copy_region(state, 0, 0, 10, 0, 5, 5)
iex> Buffer.get_cell(state, 10, 0)
%Cell{char: "A", fg: :red, bg: :blue}

fill_region(state, x, y, width, height, cell)

Fills a region in the active buffer with a cell.

Examples

iex> state = State.new(80, 24)
iex> cell = %Cell{char: "X", fg: :red, bg: :blue}
iex> state = Buffer.fill_region(state, 0, 0, 10, 5, cell)
iex> Buffer.get_cell(state, 5, 2)
%Cell{char: "X", fg: :red, bg: :blue}

get_cell(state, x, y)

Gets a cell from the active buffer.

Examples

iex> state = State.new(80, 24)
iex> Buffer.get_cell(state, 0, 0)
%Cell{char: " ", fg: :default, bg: :default}

get_differences(state)

Gets the differences between the active and back buffers.

Examples

iex> state = State.new(80, 24)
iex> cell = %Cell{char: "A", fg: :red, bg: :blue}
iex> state = Buffer.set_cell(state, 0, 0, cell)
iex> Buffer.get_differences(state)
[{0, 0, %Cell{char: "A", fg: :red, bg: :blue}}]

new(width, height)

Creates a new buffer with the specified dimensions.

Examples

iex> Buffer.new(80, 24)
%Buffer{width: 80, height: 24, cells: %{}}

resize(state, width, height)

Resizes the active buffer.

Examples

iex> state = State.new(80, 24)
iex> state = Buffer.resize(state, 100, 30)
iex> state.active_buffer.width
100
iex> state.active_buffer.height
30

scroll_region(state, x, y, width, height, lines)

Scrolls a region in the active buffer.

Examples

iex> state = State.new(80, 24)
iex> state = Buffer.scroll_region(state, 0, 0, 10, 5, 2)
iex> Buffer.get_cell(state, 0, 2)
%Cell{char: " ", fg: :default, bg: :default}

set_cell(state, x, y, cell)

Sets a cell in the active buffer.

Examples

iex> state = State.new(80, 24)
iex> cell = %Cell{char: "A", fg: :red, bg: :blue}
iex> state = Buffer.set_cell(state, 0, 0, cell)
iex> Buffer.get_cell(state, 0, 0)
%Cell{char: "A", fg: :red, bg: :blue}

sync_buffers(state)

Synchronizes the back buffer with the active buffer.

Examples

iex> state = State.new(80, 24)
iex> state = Buffer.sync_buffers(state)
iex> state.active_buffer == state.back_buffer
true