Raxol.Terminal.Buffer.Common (Raxol v0.5.0)

View Source

Common buffer operations shared between different buffer-related modules. This module provides utility functions for buffer manipulation that are used by multiple modules to avoid code duplication.

Summary

Functions

Appends new lines to existing lines.

Creates a single empty line with optional styling.

Creates empty lines with optional styling.

Gets the lines within a specific region of the buffer.

Gets the bottom boundary of the scroll region.

Gets the top boundary of the scroll region.

Replaces content in a specific region of the buffer.

Functions

append_lines(lines, new_lines)

@spec append_lines([[Raxol.Terminal.Cell.t()]], [[Raxol.Terminal.Cell.t()]]) ::
  {:ok, [[Raxol.Terminal.Cell.t()]]}

Appends new lines to existing lines.

Parameters

  • lines - Current buffer lines
  • new_lines - Lines to append

Returns

  • {:ok, combined_lines} on success

create_empty_line(blank_style)

@spec create_empty_line(Raxol.Terminal.ANSI.TextFormatting.text_style() | nil) :: [
  Raxol.Terminal.Cell.t()
]

Creates a single empty line with optional styling.

Parameters

  • blank_style - Optional style to apply to blank line

Returns

Empty line with optional styling

create_empty_lines(count, blank_style)

@spec create_empty_lines(
  non_neg_integer(),
  Raxol.Terminal.ANSI.TextFormatting.text_style() | nil
) ::
  {:ok, [[Raxol.Terminal.Cell.t()]]}

Creates empty lines with optional styling.

Parameters

  • count - Number of lines to create
  • blank_style - Optional style to apply to blank lines

Returns

  • {:ok, new_lines} on success

get_region_lines(lines, top, bottom)

@spec get_region_lines(
  [[Raxol.Terminal.Cell.t()]],
  non_neg_integer(),
  non_neg_integer()
) :: {:ok, [[Raxol.Terminal.Cell.t()]]} | {:error, atom()}

Gets the lines within a specific region of the buffer.

Parameters

  • lines - Current buffer lines
  • top - Top boundary of region
  • bottom - Bottom boundary of region

Returns

  • {:ok, region_lines} on success
  • {:error, :invalid_region} on failure

get_scroll_bottom(buffer, scroll_region)

@spec get_scroll_bottom(
  Raxol.Terminal.ScreenBuffer.t(),
  {non_neg_integer(), non_neg_integer()} | nil
) :: {:ok, non_neg_integer()} | {:error, atom()}

Gets the bottom boundary of the scroll region.

Parameters

  • buffer - The screen buffer
  • scroll_region - Optional scroll region override

Returns

  • {:ok, bottom} on success
  • {:error, reason} on failure

get_scroll_top(buffer, scroll_region)

@spec get_scroll_top(
  Raxol.Terminal.ScreenBuffer.t(),
  {non_neg_integer(), non_neg_integer()} | nil
) :: {:ok, non_neg_integer()} | {:error, atom()}

Gets the top boundary of the scroll region.

Parameters

  • buffer - The screen buffer
  • scroll_region - Optional scroll region override

Returns

  • {:ok, top} on success
  • {:error, reason} on failure

replace_region(lines, new_region, top, bottom)

Replaces content in a specific region of the buffer.

Parameters

  • lines - Current buffer lines
  • new_region - New content for the region
  • top - Top boundary of region
  • bottom - Bottom boundary of region

Returns

Updated buffer lines with the region replaced