Raxol.Terminal.Buffer.Manager.Buffer (Raxol v0.4.0)
View SourceHandles 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
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}
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}
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}
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}
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}}]
Creates a new buffer with the specified dimensions.
Examples
iex> Buffer.new(80, 24)
%Buffer{width: 80, height: 24, cells: %{}}
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
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}
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}
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