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).

More...

Constructors

this
this(string 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.

Members

Functions

addComponent
void addComponent(string text, int foreground, int background, bool delegate() onclick)
addComponent
void addComponent(LineComponent component)
addLine
void addLine()

Adds an empty line.

addLine
void addLine(string line)

This is what writeln actually calls.

addLine
void addLine(LineComponent[] components)

Adds a line by components without affecting scrollback.

clear
void clear()

Clears the scrollback buffer.

color
void color(int foreground, int background)

Writing into the scrollback buffer can be done with the same normal functions.

drawInto
void drawInto(Terminal* terminal, int x, int y, int width, int height)

Draws the current state into the given terminal inside the given bounding box.

handleEvent
bool handleEvent(InputEvent 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
void scrollDown(int lines)
scrollToBottom
void scrollToBottom()
scrollToTop
void scrollToTop(int width, int height)

Scrolling controls.

scrollTopPosition
int scrollTopPosition(int width, int height)

Given a size, how far would you have to scroll back to get to the top?

scrollUp
void scrollUp(int lines)

Scrolling controls.

write
void write(T t)
writef
void writef(string fmt, T t)
writefln
void writefln(string fmt, T t)
writeln
void writeln(T t)

Writing into the scrollback buffer can be done with the same normal functions.

Properties

scrollbackPosition
int scrollbackPosition [@property getter]

Property to control the current scrollback position. 0 = latest message at bottom of screen.

Structs

CircularBuffer
struct CircularBuffer(T)

This is an internal helper for its scrollback buffer.

LineComponent
struct LineComponent

You can construct these to get more control over specifics including setting RGB colors.

Variables

defaultBackground
Color defaultBackground;

This is the color it uses to clear the screen.

defaultForeground
Color defaultForeground;

This is the color it uses to clear the screen.

demandsAttention
bool demandsAttention;

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 height;

The coordinates of the last drawInto

name
string name;

A string you can set and process on your own. The library only sets it from the constructor, then leaves it alone.

width
int width;

The coordinates of the last drawInto

x
int x;
y
int y;

The coordinates of the last drawInto

Detailed Description

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.

Meta

History

Committed to git on August 4, 2015.

Cleaned up and documented on May 25, 2021.