Add documentation
This commit is contained in:
+10
-1
@@ -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 = {};
|
export const CHARSETS: any = {};
|
||||||
|
|
||||||
// DEC Special Character and Line Drawing Set.
|
// DEC Special Character and Line Drawing Set.
|
||||||
|
|||||||
@@ -1,7 +1,18 @@
|
|||||||
|
/**
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
import { IInputHandler, ITerminal } from './Interfaces';
|
import { IInputHandler, ITerminal } from './Interfaces';
|
||||||
import { C0 } from './EscapeSequences';
|
import { C0 } from './EscapeSequences';
|
||||||
import { CHARSETS } from './Charsets';
|
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 {
|
export class InputHandler implements IInputHandler {
|
||||||
// TODO: We want to type _terminal when it's pulled into TS
|
// TODO: We want to type _terminal when it's pulled into TS
|
||||||
constructor(private _terminal: any) { }
|
constructor(private _terminal: any) { }
|
||||||
|
|||||||
+54
-4
@@ -1,3 +1,7 @@
|
|||||||
|
/**
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
import { C0 } from './EscapeSequences';
|
import { C0 } from './EscapeSequences';
|
||||||
import { IInputHandler } from './Interfaces';
|
import { IInputHandler } from './Interfaces';
|
||||||
import { CHARSETS } from './Charsets';
|
import { CHARSETS } from './Charsets';
|
||||||
@@ -169,6 +173,11 @@ enum ParserState {
|
|||||||
IGNORE = 7
|
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 {
|
export class Parser {
|
||||||
private _state: ParserState;
|
private _state: ParserState;
|
||||||
private _position: number;
|
private _position: number;
|
||||||
@@ -181,6 +190,11 @@ export class Parser {
|
|||||||
this._state = ParserState.NORMAL;
|
this._state = ParserState.NORMAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse and handle data.
|
||||||
|
*
|
||||||
|
* @param data The data to parse.
|
||||||
|
*/
|
||||||
public parse(data: string) {
|
public parse(data: string) {
|
||||||
let l = data.length, j, cs, ch, code, low;
|
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 {
|
public setState(state: ParserState): void {
|
||||||
this._state = state;
|
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 {
|
public setPrefix(prefix: string): void {
|
||||||
this._terminal.prefix = prefix;
|
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) {
|
public setParam(param: number) {
|
||||||
this._terminal.currentParam = param;
|
this._terminal.currentParam = param;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the parser's current parameter.
|
||||||
|
*/
|
||||||
public getParam(): number {
|
public getParam(): number {
|
||||||
return this._terminal.currentParam;
|
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 {
|
public finalizeParam(): void {
|
||||||
this._terminal.params.push(this._terminal.currentParam);
|
this._terminal.params.push(this._terminal.currentParam);
|
||||||
this._terminal.currentParam = 0;
|
this._terminal.currentParam = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public setPostfix(postfix: string): void {
|
/**
|
||||||
this._terminal.postfix = postfix;
|
* Tell the parser to skip the next character.
|
||||||
}
|
*/
|
||||||
|
|
||||||
public skipNextChar(): void {
|
public skipNextChar(): void {
|
||||||
this._position++;
|
this._position++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tell the parser to repeat parsing the current character (for example if it
|
||||||
|
* needs parsing using a different state.
|
||||||
|
*/
|
||||||
// public repeatChar(): void {
|
// public repeatChar(): void {
|
||||||
// this._position--;
|
// this._position--;
|
||||||
// }
|
// }
|
||||||
|
|||||||
Reference in New Issue
Block a user