This commit is contained in:
Labhansh Agrawal
2020-05-01 14:26:03 +05:30
parent c818381ef1
commit 4702a0af9d
3 changed files with 15 additions and 10 deletions
+11 -8
View File
@@ -16,18 +16,21 @@ describe('xterm-addon-ligatures', () => {
before(() => { before(() => {
sinon.stub(fontFinder, 'list').returns(Promise.resolve({ sinon.stub(fontFinder, 'list').returns(Promise.resolve({
// eslint-disable-next-line @typescript-eslint/naming-convention
'Fira Code': [{ 'Fira Code': [{
path: path.join(__dirname, '../fonts/firaCode.otf'), path: path.join(__dirname, '../fonts/firaCode.otf'),
style: fontFinder.Style.Regular, style: fontFinder.Style.Regular,
type: fontFinder.Type.Monospace, type: fontFinder.Type.Monospace,
weight: 400 weight: 400
}], }],
// eslint-disable-next-line @typescript-eslint/naming-convention
'Iosevka': [{ 'Iosevka': [{
path: path.join(__dirname, '../fonts/iosevka.ttf'), path: path.join(__dirname, '../fonts/iosevka.ttf'),
style: fontFinder.Style.Regular, style: fontFinder.Style.Regular,
type: fontFinder.Type.Monospace, type: fontFinder.Type.Monospace,
weight: 400 weight: 400
}], }],
// eslint-disable-next-line @typescript-eslint/naming-convention
'Nonexistant Font': [{ 'Nonexistant Font': [{
path: path.join(__dirname, '../fonts/nonexistant.ttf'), path: path.join(__dirname, '../fonts/nonexistant.ttf'),
style: fontFinder.Style.Regular, style: fontFinder.Style.Regular,
@@ -185,32 +188,32 @@ describe('xterm-addon-ligatures', () => {
}); });
class MockTerminal { class MockTerminal {
static applyAddon(addon: any): void { public static applyAddon(addon: any): void {
addon.apply(MockTerminal); addon.apply(MockTerminal);
} }
private _options: { [name: string]: string | number; } = { private _options: { [name: string]: string | number } = {
fontFamily: 'Fira Code, monospace', fontFamily: 'Fira Code, monospace',
rows: 50 rows: 50
}; };
joiner?: (text: string) => [number, number][]; public joiner?: (text: string) => [number, number][];
refresh: (start: number, end: number) => void; public refresh: (start: number, end: number) => void;
constructor(onRefresh: (start: number, end: number) => void) { constructor(onRefresh: (start: number, end: number) => void) {
this.refresh = onRefresh; this.refresh = onRefresh;
} }
registerCharacterJoiner(handler: (text: string) => [number, number][]): number { public registerCharacterJoiner(handler: (text: string) => [number, number][]): number {
this.joiner = handler; this.joiner = handler;
return 1; return 1;
} }
deregisterCharacterJoiner(id: number): void { public deregisterCharacterJoiner(id: number): void {
this.joiner = undefined; this.joiner = undefined;
} }
setOption(name: string, value: string | number): void { public setOption(name: string, value: string | number): void {
this._options[name] = value; this._options[name] = value;
} }
getOption(name: string): string | number { public getOption(name: string): string | number {
return this._options[name]; return this._options[name];
} }
} }
+2 -1
View File
@@ -70,7 +70,8 @@ export function enableLigatures(term: Terminal): void {
return font.findLigatureRanges(text).map<[number, number]>( return font.findLigatureRanges(text).map<[number, number]>(
range => [range[0], range[1]] range => [range[0], range[1]]
); );
} else if (loadingState === LoadingState.FAILED) { }
if (loadingState === LoadingState.FAILED) {
throw loadError || new Error('Failure while loading font'); throw loadError || new Error('Failure while loading font');
} }
+2 -1
View File
@@ -150,7 +150,8 @@ function parseUnicode(context: IParseContext): string {
// The first whitespace character after a unicode escape indicates the end // The first whitespace character after a unicode escape indicates the end
// of the escape and is swallowed. // of the escape and is swallowed.
return unicodeToString(str); return unicodeToString(str);
} else if (str.length >= 6 || !/[0-9a-fA-F]/.test(char)) { }
if (str.length >= 6 || !/[0-9a-fA-F]/.test(char)) {
// If the next character is not a valid hex digit or we have reached the // If the next character is not a valid hex digit or we have reached the
// maximum of 6 digits in the escape, terminate the escape. // maximum of 6 digits in the escape, terminate the escape.
context.offset--; context.offset--;