From ef60e50e1decaaf79ca0fb1f988f1a1c5aa0c1b7 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Wed, 18 Jan 2017 09:35:27 -0800 Subject: [PATCH] Add documentation --- src/Charsets.ts | 11 ++++++++- src/InputHandler.ts | 11 +++++++++ src/Parser.ts | 58 +++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 75 insertions(+), 5 deletions(-) diff --git a/src/Charsets.ts b/src/Charsets.ts index 4035d45..3220f7d 100644 --- a/src/Charsets.ts +++ b/src/Charsets.ts @@ -1,4 +1,13 @@ -// TODO: Give this a proper type +/** + * @license MIT + */ + +// TODO: Give CHARSETS a proper type +/** + * The character sets supported by the terminal. These enable several languages + * to be represented within the terminal with only 8-bit encoding. See ISO 2022 + * for a discussion on character sets. + */ export const CHARSETS: any = {}; // DEC Special Character and Line Drawing Set. diff --git a/src/InputHandler.ts b/src/InputHandler.ts index d13ad42..00626ce 100644 --- a/src/InputHandler.ts +++ b/src/InputHandler.ts @@ -1,7 +1,18 @@ +/** + * @license MIT + */ + import { IInputHandler, ITerminal } from './Interfaces'; import { C0 } from './EscapeSequences'; import { CHARSETS } from './Charsets'; +/** + * The terminal's standard implementation of IInputHandler, this handles all + * input from the Parser. + * + * Refer to http://invisible-island.net/xterm/ctlseqs/ctlseqs.html to understand + * each function's header comment. + */ export class InputHandler implements IInputHandler { // TODO: We want to type _terminal when it's pulled into TS constructor(private _terminal: any) { } diff --git a/src/Parser.ts b/src/Parser.ts index b429c57..860baaa 100644 --- a/src/Parser.ts +++ b/src/Parser.ts @@ -1,3 +1,7 @@ +/** + * @license MIT + */ + import { C0 } from './EscapeSequences'; import { IInputHandler } from './Interfaces'; import { CHARSETS } from './Charsets'; @@ -169,6 +173,11 @@ enum ParserState { IGNORE = 7 } +/** + * The terminal's parser, all input into the terminal goes through the parser + * which parses and defers the actual input handling the the IInputHandler + * specified in the constructor. + */ export class Parser { private _state: ParserState; private _position: number; @@ -181,6 +190,11 @@ export class Parser { this._state = ParserState.NORMAL; } + /** + * Parse and handle data. + * + * @param data The data to parse. + */ public parse(data: string) { let l = data.length, j, cs, ch, code, low; @@ -565,35 +579,71 @@ export class Parser { } } + /** + * Set the parser's current parsing state. + * + * @param state The new state. + */ public setState(state: ParserState): void { this._state = state; } + /** + * Sets the parsier's current prefix. CSI codes can have prefixes of '?', '>' + * or '!'. + * + * @param prefix The prefix. + */ public setPrefix(prefix: string): void { this._terminal.prefix = prefix; } + /** + * Sets the parsier's current prefix. CSI codes can have postfixes of '$', + * '"', ' ', '\''. + * + * @param postfix The postfix. + */ + public setPostfix(postfix: string): void { + this._terminal.postfix = postfix; + } + + /** + * Sets the parser's current parameter. + * + * @param param the parameter. + */ public setParam(param: number) { this._terminal.currentParam = param; } + /** + * Gets the parser's current parameter. + */ public getParam(): number { return this._terminal.currentParam; } + /** + * Finalizes the parser's current parameter, adding it to the list of + * parameters and setting the new current parameter to 0. + */ public finalizeParam(): void { this._terminal.params.push(this._terminal.currentParam); this._terminal.currentParam = 0; } - public setPostfix(postfix: string): void { - this._terminal.postfix = postfix; - } - + /** + * Tell the parser to skip the next character. + */ public skipNextChar(): void { this._position++; } + /** + * Tell the parser to repeat parsing the current character (for example if it + * needs parsing using a different state. + */ // public repeatChar(): void { // this._position--; // } -- 2.39.2