Struct ScrollbackBuffer
The ScrollbackBuffer is a writable in-memory terminal that can be drawn to a real [Terminal]
and maintain some internal position state by handling events. It is your responsibility to
draw it (using the [drawInto] method) and dispatch events to its [handleEvent] method (if you
want to, you can also just call the methods yourself).
I originally wrote this to support my irc client and some of the features are geared toward
helping with that (for example, [name] and [demandsAttention]), but the main thrust is to
support either tabs or sub-sections of the terminal having their own output that can be displayed
and scrolled back independently while integrating with some larger application.
Constructors
| Name | Description |
this
(name)
|
The name is for your own use only. I use the name as a tab title but you could ignore it and just pass null too.
|
Fields
| Name | Type | Description |
defaultBackground
|
Color | This is the color it uses to clear the screen.
|
defaultForeground
|
Color | This is the color it uses to clear the screen.
|
demandsAttention
|
bool | A flag you can set and process on your own. All the library does with it is
set it to false when it handles an event, otherwise you can do whatever you
want with it.
|
height
|
int | The coordinates of the last [drawInto]
|
name
|
string | A string you can set and process on your own. The library only sets it from the
constructor, then leaves it alone.
|
width
|
int | The coordinates of the last [drawInto]
|
x
|
int | The coordinates of the last [drawInto]
|
y
|
int | The coordinates of the last [drawInto]
|
Properties
| Name | Type | Description |
scrollbackPosition[get]
|
int | Property to control the current scrollback position. 0 = latest message
at bottom of screen.
|
Methods
| Name | Description |
addComponent
(text, foreground, background, onclick)
|
|
addLine
()
|
Adds an empty line.
|
addLine
(line)
|
This is what [writeln] actually calls.
|
addLine
(components)
|
Adds a line by components without affecting scrollback.
|
clear
()
|
Clears the scrollback buffer.
|
color
(foreground, background)
|
Writing into the scrollback buffer can be done with the same normal functions.
|
drawInto
(terminal, x, y, width, height)
|
Draws the current state into the given terminal inside the given bounding box.
|
handleEvent
(e)
|
Default event handling for this widget. Call this only after drawing it into a rectangle
and only if the event ought to be dispatched to it (which you determine however you want;
you could dispatch all events to it, or perhaps filter some out too)
|
scrollDown
(lines)
|
Scrolling controls.
|
scrollToBottom
()
|
Scrolling controls.
|
scrollTopPosition
(width, height)
|
Given a size, how far would you have to scroll back to get to the top?
|
scrollToTop
(width, height)
|
Scrolling controls.
|
scrollUp
(lines)
|
Scrolling controls.
|
write
(t)
|
Writing into the scrollback buffer can be done with the same normal functions.
|
writef
(fmt, t)
|
Writing into the scrollback buffer can be done with the same normal functions.
|
writefln
(fmt, t)
|
Writing into the scrollback buffer can be done with the same normal functions.
|
writeln
(t)
|
Writing into the scrollback buffer can be done with the same normal functions.
|
Inner structs
| Name | Description |
CircularBuffer
|
This is an internal helper for its scrollback buffer.
|
LineComponent
|
You can construct these to get more control over specifics including
setting RGB colors.
|
History
Committed to git on August 4, 2015.
Cleaned up and documented on May 25, 2021.