class

Opal::UI::Buffer

Inherits Reference < Object

In-memory 2D grid of screen cells representing a terminal frame.

Constructors

new(width : Int32, height : Int32)
Source

Class methods

flip_h_glyph(ch : Char) : Char
Source
flip_v_glyph(ch : Char) : Char
Source
rotate_glyph(ch : Char, turns : Int32) : Char

Box-drawing glyph transposition helpers

Source

Instance methods

active_mask

Active mask for masked rendering operations

Source
active_mask=(active_mask : MaskMap | Nil)

Active mask for masked rendering operations

Source
apply_shader(pass : Shader::Pass, time : Float64 = 0.0, frame : UInt64 = 0_u64) : self

Applies a shader pass to this buffer

Source
blit(src : Buffer, dst_x : Int32, dst_y : Int32, ignore_spaces : Bool = false) : Nil

Blits (copies) another buffer onto this buffer at the given coordinates. If ignore_spaces is true, empty cells without background do not overwrite existing cells.

Source
cells
Source
clear
Source
clip_rect
Source
clip_rect=(clip_rect : Rect | Nil)
Source
clone
Source
copy(x : Int32, y : Int32, w : Int32, h : Int32) : Buffer
Source
copy(rect : Rect) : Buffer

Copies a subregion of this buffer into a new standalone Buffer.

Source
copy_from(other : Buffer) : Nil

In-place copies all cells and dimensions from another buffer without reallocating

Source
crop(x : Int32, y : Int32, w : Int32, h : Int32) : Buffer
Source
crop(rect : Rect) : Buffer

Alias for copy

Source
dim_all

Dims the entire buffer to create a backdrop effect.

Source
dim_rect(x : Int32, y : Int32, w : Int32, h : Int32) : Nil

Applies dimming attribute to all cells within the given rectangle.

Source
fill(x : Int32, y : Int32, w : Int32, h : Int32, cell : Cell = Cell.empty) : Nil
Source
fill(x : Int32, y : Int32, w : Int32, h : Int32, char : Char, fg : Color = Color.none, bg : Color = Color.none) : Nil
Source
fill_rect(x : Int32, y : Int32, w : Int32, h : Int32, cell : Cell = Cell.empty) : Nil
Source
fill_rect(rect : Rect, cell : Cell = Cell.empty) : Nil

Fills a rectangle with a specified cell

Source
flip_h
Source
flip_v
Source
get(x : Int32, y : Int32) : Cell
Source
height
Source
in_bounds?(x : Int32, y : Int32) : Bool
Source
in_clip?(x : Int32, y : Int32) : Bool

Returns true if the coordinate is within the buffer bounds and the active clip rect (if any).

Source
invert(x : Int32, y : Int32, w : Int32, h : Int32) : Nil
Source
invert(rect : Rect) : Nil

Inverts foreground and background colors in a rectangle

Source
mask_feather
Source
mask_feather=(mask_feather : Bool)
Source
mask_offset_x
Source
mask_offset_x=(mask_offset_x : Int32)
Source
mask_offset_y
Source
mask_offset_y=(mask_offset_y : Int32)
Source
paste(src : Buffer, dst_x : Int32, dst_y : Int32, mode : BlitMode = BlitMode::Replace, alpha : Float64 = 1.0) : Nil

Pastes another buffer onto this buffer with selectable BlitMode and optional alpha

Source
put_char(x : Int32, y : Int32, char : Char, fg : Color = Color.none, bg : Color = Color.none, bold : Bool = false, dim : Bool = false, italic : Bool = false, underline : Bool = false, reverse : Bool = false, keep_bg : Bool = false) : Nil
Source
put_line(x : Int32, y : Int32, text : String, width : Int32, fg : Color = Color.none, bg : Color = Color.none, bold : Bool = false, dim : Bool = false) : Nil

Writes string and pads remaining columns up to width with spaces, ensuring clean erasure

Source
put_string(x : Int32, y : Int32, text : String, fg : Color = Color.none, bg : Color = Color.none, bold : Bool = false, dim : Bool = false, italic : Bool = false, underline : Bool = false, reverse : Bool = false, max_width : Int32 | Nil = nil, keep_bg : Bool = false) : Int32
Source
render_to_string(with_ansi : Bool = true) : String

Renders the buffer content to a string, optionally including ANSI color and style sequences.

Source
rotate_180
Source
rotate_90(clockwise : Bool = true) : Buffer

Transforms: Rotate 90 degrees clockwise or counterclockwise

Source
screenshot(path : String | Nil = nil, format : Symbol = :ansi, copy_to_clipboard : Bool = false) : String

Captures this buffer as a screenshot string in the specified format (:ansi, :text, or :html). If path is provided, writes the content to disk. If copy_to_clipboard is true, copies the screenshot to the system clipboard.

Source
screenshot_to_clipboard(format : Symbol = :text) : String

Captures this buffer as a screenshot and immediately copies it to the system clipboard.

Source
scroll_rect(rect : Rect, dx : Int32, dy : Int32, fill_char : Char = ' ') : Nil

Shifts cells within a rect by dx and dy, filling exposed regions with fill_char

Source
set(x : Int32, y : Int32, cell : Cell) : Nil
Source
shade(region : Shader::Rect | Nil = nil, time : Float64 = 0.0, frame : UInt64 = 0_u64, &block : Shader::ShaderContext -> Nil) : self

Applies a custom text shader block to this buffer (or a specific region)

Source
to_html(title : String = "Opal Terminal Frame") : String

Exports the buffer as a self-contained HTML representation with styled CSS 24-bit colors.

Source
to_s(io : IO) : Nil

Appends a short String representation of this object which includes its class name and its object address.

class Person
  def initialize(@name : String, @age : Int32)
  end
end

Person.new("John", 32).to_s # => #<Person:0x10a199f20>
Source
width
Source
with_clip(x : Int32, y : Int32, w : Int32, h : Int32, &)

Executes a block with an active clipping rectangle. If a clip rectangle is already active, computes their intersection.

Source
with_clip(rect : Rect, &)

Clip execution using a Rect struct

Source
with_mask(mask : MaskMap, offset_x : Int32 = 0, offset_y : Int32 = 0, feather : Bool = true, &)

Executes a block with an active mask map.

Source
with_scissor(x : Int32, y : Int32, w : Int32, h : Int32, &)
Source
with_scissor(rect : Rect, &)

Executes a block with an active scissor clipping rectangle.

Source