Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buffer API #1994

Closed
Tyriar opened this issue Apr 2, 2019 · 0 comments · Fixed by #2074
Closed

Buffer API #1994

Tyriar opened this issue Apr 2, 2019 · 0 comments · Fixed by #2074
Assignees
Labels
area/api type/enhancement Features or improvements to existing features
Milestone

Comments

@Tyriar
Copy link
Member

Tyriar commented Apr 2, 2019

As part of #1128 we will be pulling the search addon out of the core repo and into a satellite repo to be published as its own npm module. This is exactly the sort of thing that would be cool for addons to be able to build so we should stabilize some API as right now it hooks into internals. Here's what it touches in buffer:

  • ydisp
  • ybase
  • length
  • translateBufferLineToString
  • lines (for isWrapped, length, get width, get char to check if emoji)

Given this, I'm proposing the following API. It resembles the internal structure, but I tweaked a bit here and there to make it more consistent and easier to use (eg. buffer.lines.get -> buffer.getLine):

class Terminal {
    /**
     * The terminal's current buffer, note that this might be either the normal
     * buffer or the alt buffer depending on what's running in the terminal.
     */
    buffer: IBuffer;
}

interface IBuffer {

    /**
     * The y position of the cursor. This ranges between `0` (when the
     * cursor is at baseY) and `Terminal.rows - 1` (when the cursor is on the
     * last row).
     */
    readonly cursorY: number;

    /**
     * The x position of the cursor. This ranges between `0` (left side) and
     * `Terminal.cols - 1` (right side).
     */
    readonly cursorX: number;

    /**
     * The line within the buffer where the top of the viewport is.
     */
    readonly viewportY: number;

    /**
     * The line within the buffer where the top of the bottom page is (when
     * fully scrolled down);
     */
    readonly baseY: number;

    /**
     * The amount of lines in the buffer.
     */
    readonly length: number;

    /**
     * Gets a line from the buffer.
     * 
     * @param y The line index to get.
     */
    getLine(y: number): IBufferLine;
}

interface IBufferLine {
    /**
     * Whether the line is wrapped from the previous line.
     */
    readonly isWrapped: boolean;

    /**
     * Gets a cell from the line.
     * 
     * @param x The character index to get.
     */
    getCell(x: number): IBufferCell;

    /**
     * Gets the line
     */
    translateToString(trimRight: boolean, startColumn: number, endColumn: number): string;
}

interface IBufferCell {
    /**
     * The character within the cell.
     */
    readonly char: number;

    /**
     * The width of the character. Some examples:
     * 
     * - This is `1` for most cells.
     * - This is `2` for wide character like CJK glyphs.
     * - This is `0` for cells immediately following cells with a width of `2`.
     */
    readonly width: number;
}
@Tyriar Tyriar added the type/proposal A proposal that needs some discussion before proceeding label Apr 2, 2019
@Tyriar Tyriar self-assigned this Apr 2, 2019
Tyriar added a commit to Tyriar/xterm.js that referenced this issue Apr 4, 2019
buffer.x will probably be public API soon (xtermjs#1994)

Fixes xtermjs#1989
Tyriar added a commit to Tyriar/xterm.js that referenced this issue Apr 7, 2019
@Tyriar Tyriar mentioned this issue Apr 10, 2019
@Tyriar Tyriar mentioned this issue May 11, 2019
@Tyriar Tyriar added this to the 3.14.0 milestone May 11, 2019
@Tyriar Tyriar added area/api type/enhancement Features or improvements to existing features and removed type/proposal A proposal that needs some discussion before proceeding labels May 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api type/enhancement Features or improvements to existing features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant