class Opal::UI::Buffer

Overview

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

Defined in:

opal/ui/buffer.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(width : Int32, height : Int32) #

[View source]

Class Method Detail

def self.flip_h_glyph(ch : Char) : Char #

[View source]
def self.flip_v_glyph(ch : Char) : Char #

[View source]
def self.rotate_glyph(ch : Char, turns : Int32) : Char #

Box-drawing glyph transposition helpers


[View source]

Instance Method Detail

def active_mask : MaskMap | Nil #

Active mask for masked rendering operations


[View source]
def active_mask=(active_mask : MaskMap | Nil) #

Active mask for masked rendering operations


[View source]
def apply_shader(pass : Shader::Pass, time : Float64 = 0.0, frame : UInt64 = 0_u64) : self #

Applies a shader pass to this buffer


[View source]
def 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.


[View source]
def cells : Array(Cell) #

[View source]
def clear : Nil #

[View source]
def clip_rect : Rect | Nil #

[View source]
def clip_rect=(clip_rect : Rect | Nil) #

[View source]
def clone : Buffer #

[View source]
def copy(x : Int32, y : Int32, w : Int32, h : Int32) : Buffer #

[View source]
def copy(rect : Rect) : Buffer #

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


[View source]
def copy_from(other : Buffer) : Nil #

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


[View source]
def crop(x : Int32, y : Int32, w : Int32, h : Int32) : Buffer #

[View source]
def crop(rect : Rect) : Buffer #

Alias for copy


[View source]
def dim_all : Nil #

Dims the entire buffer to create a backdrop effect.


[View source]
def dim_rect(x : Int32, y : Int32, w : Int32, h : Int32) : Nil #

Applies dimming attribute to all cells within the given rectangle.


[View source]
def fill(x : Int32, y : Int32, w : Int32, h : Int32, cell : Cell = Cell.empty) : Nil #

[View source]
def fill(x : Int32, y : Int32, w : Int32, h : Int32, char : Char, fg : Color = Color.none, bg : Color = Color.none) : Nil #

[View source]
def fill_rect(x : Int32, y : Int32, w : Int32, h : Int32, cell : Cell = Cell.empty) : Nil #

[View source]
def fill_rect(rect : Rect, cell : Cell = Cell.empty) : Nil #

Fills a rectangle with a specified cell


[View source]
def flip_h : Buffer #

[View source]
def flip_v : Buffer #

[View source]
def get(x : Int32, y : Int32) : Cell #

[View source]
def height : Int32 #

[View source]
def in_bounds?(x : Int32, y : Int32) : Bool #

[View source]
def in_clip?(x : Int32, y : Int32) : Bool #

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


[View source]
def invert(x : Int32, y : Int32, w : Int32, h : Int32) : Nil #

[View source]
def invert(rect : Rect) : Nil #

Inverts foreground and background colors in a rectangle


[View source]
def mask_feather : Bool #

[View source]
def mask_feather=(mask_feather : Bool) #

[View source]
def mask_offset_x : Int32 #

[View source]
def mask_offset_x=(mask_offset_x : Int32) #

[View source]
def mask_offset_y : Int32 #

[View source]
def mask_offset_y=(mask_offset_y : Int32) #

[View source]
def 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


[View source]
def 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, hyperlink : String | Nil = nil) : Nil #

[View source]
def 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


[View source]
def put_link(x : Int32, y : Int32, url : String, label : String | Nil = nil, fg : Color = Color.cyan, bg : Color = Color.none, bold : Bool = false, dim : Bool = false, italic : Bool = false, underline : Bool = true, reverse : Bool = false, max_width : Int32 | Nil = nil, keep_bg : Bool = false) : Int32 #

Writes an OSC 8 clickable hyperlink into the buffer cells at (x, y).


[View source]
def 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, hyperlink : String | Nil = nil) : Int32 #

[View source]
def render_to_string(with_ansi : Bool = true) : String #

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


[View source]
def rotate_180 : Buffer #

[View source]
def rotate_90(clockwise : Bool = true) : Buffer #

Transforms: Rotate 90 degrees clockwise or counterclockwise


[View source]
def 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.


[View source]
def screenshot_to_clipboard(format : Symbol = :text) : String #

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


[View source]
def 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


[View source]
def set(x : Int32, y : Int32, cell : Cell) : Nil #

[View source]
def 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)


[View source]
def to_html(title : String = "Opal Terminal Frame") : String #

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


[View source]
def to_s(io : IO) : Nil #
Description copied from class Reference

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>

[View source]
def width : Int32 #

[View source]
def 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.


[View source]
def with_clip(rect : Rect, &) #

Clip execution using a Rect struct


[View source]
def with_mask(mask : MaskMap, offset_x : Int32 = 0, offset_y : Int32 = 0, feather : Bool = true, &) #

Executes a block with an active mask map.


[View source]
def with_scissor(x : Int32, y : Int32, w : Int32, h : Int32, &) #

[View source]
def with_scissor(rect : Rect, &) #

Executes a block with an active scissor clipping rectangle.


[View source]