Package org.aesh.charts.canvas
Class Canvas
java.lang.Object
org.aesh.charts.canvas.Canvas
A 2D character grid for rendering chart content.
The canvas uses a coordinate system where (0,0) is the top-left corner. Each cell holds a character and an optional ANSI color/style string.
For braille mode, the canvas operates at sub-cell resolution: each
character cell represents a 2x4 dot matrix. Use setBrailleDot(int, int, java.lang.String)
to set individual dots within cells.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear the canvas to spaces.charget(int x, int y) Get the character at the given position.intheight()voidhorizontalLine(int x, int y, int length, char ch) Draw a horizontal line.voidhorizontalLine(int x, int y, int length, char ch, String style) render()Render the canvas to a multi-line string.voidset(int x, int y, char ch) Set a character at the given position.voidSet a character with an ANSI style at the given position.voidsetBrailleDot(int subX, int subY, String style) Set a braille dot at sub-cell coordinates.voidverticalLine(int x, int y, int length, char ch) Draw a vertical line.voidverticalLine(int x, int y, int length, char ch, String style) intwidth()voidwriteString(int x, int y, String text) Write a string starting at the given position.voidwriteString(int x, int y, String text, String style) Write a string with style starting at the given position.
-
Constructor Details
-
Canvas
public Canvas(int width, int height, boolean braille) Create a canvas with the given dimensions in character cells.- Parameters:
width- width in character cellsheight- height in character cellsbraille- whether to enable braille sub-cell rendering
-
Canvas
public Canvas(int width, int height)
-
-
Method Details
-
clear
public void clear()Clear the canvas to spaces. -
width
public int width() -
height
public int height() -
set
public void set(int x, int y, char ch) Set a character at the given position.- Parameters:
x- column (0 = left)y- row (0 = top)ch- the character
-
set
Set a character with an ANSI style at the given position.- Parameters:
x- column (0 = left)y- row (0 = top)ch- the characterstyle- ANSI escape sequence (e.g., ANSI.GREEN_TEXT), or null
-
get
public char get(int x, int y) Get the character at the given position. -
writeString
Write a string starting at the given position. -
writeString
Write a string with style starting at the given position. -
setBrailleDot
Set a braille dot at sub-cell coordinates.The sub-cell coordinates are mapped to the containing character cell and the appropriate dot bit is set.
- Parameters:
subX- sub-cell X coordinate (each cell is 2 sub-pixels wide)subY- sub-cell Y coordinate (each cell is 4 sub-pixels tall)style- ANSI style for the cell
-
horizontalLine
public void horizontalLine(int x, int y, int length, char ch) Draw a horizontal line. -
horizontalLine
-
verticalLine
public void verticalLine(int x, int y, int length, char ch) Draw a vertical line. -
verticalLine
-
render
Render the canvas to a multi-line string.Each cell is rendered with its ANSI style (if any), and styles are reset after each styled run to prevent color bleeding.
- Returns:
- the rendered string
-