add interfaces and option handling

This commit is contained in:
Jörg Breitbart
2019-12-05 21:30:59 +01:00
parent 31ccb796ac
commit 43303ba4c1
7 changed files with 67 additions and 10 deletions
+2 -2
View File
@@ -205,10 +205,10 @@ export class UnicodeV11 implements IUnicodeVersionProvider {
}
}
public wcwidth(num: number): number {
public wcwidth(num: number): 0 | 1 | 2 {
if (num < 32) return 0;
if (num < 127) return 1;
if (num < 65536) return UnicodeV11.bmpTable[num];
if (num < 65536) return UnicodeV11.bmpTable[num] as 0 | 1 | 2;
if (UnicodeV11.bisearch(num, UnicodeV11.highCombining)) return 0;
if (UnicodeV11.bisearch(num, UnicodeV11.highWide)) return 2;
return 1;
+2 -2
View File
@@ -118,10 +118,10 @@ export class UnicodeV6 implements IUnicodeVersionProvider {
}
}
public wcwidth(num: number): number {
public wcwidth(num: number): 0 | 1 | 2 {
if (num < 32) return 0;
if (num < 127) return 1;
if (num < 65536) return UnicodeV6.bmpTable[num];
if (num < 65536) return UnicodeV6.bmpTable[num] as 0 | 1 | 2;
if (UnicodeV6.bisearch(num, UnicodeV6.highCombining)) return 0;
if ((num >= 0x20000 && num <= 0x2fffd) || (num >= 0x30000 && num <= 0x3fffd)) return 2;
return 1;
+2 -2
View File
@@ -289,7 +289,7 @@ export interface IUnicodeService {
/** Registered Unicode versions. */
readonly versions: string[];
/** Currently active version. */
readonly activeVersion: string;
activeVersion: string;
/** Event triggered, when activate version changed. */
readonly onChange: IEvent<string>;
@@ -302,5 +302,5 @@ export interface IUnicodeService {
export interface IUnicodeVersionProvider {
version: string;
wcwidth(ucs: number): number;
wcwidth(ucs: number): 0 | 1 | 2;
}
+3 -3
View File
@@ -9,8 +9,8 @@ import { IUnicodeVersionProvider } from 'common/services/Services';
class DummyProvider implements IUnicodeVersionProvider {
version = '123';
wcwidth(n: number): number {
return 123;
wcwidth(n: number): 0 | 1 | 2 {
return 2;
}
}
@@ -41,7 +41,7 @@ describe('unicode provider', () => {
const dummyProvider = new DummyProvider();
us.register(dummyProvider);
us.activeVersion = dummyProvider.version;
assert.equal(us.getStringCellWidth('hello'), 123 * 5);
assert.equal(us.getStringCellWidth('hello'), 2 * 5);
});
it('wcwidth V6 emoji test', () => {
const widthV6 = us.getStringCellWidth('🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣');