New unicode-graphemes addon.
Handle grapheme cluster lookup as well as wcwidth. This is based on Unicode 15, and could replace the unicode11 addon.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
|
||||
* @license MIT
|
||||
*/
|
||||
import { IUnicodeService, IUnicodeVersionProvider } from 'common/services/Services';
|
||||
import { IUnicodeService, IUnicodeVersionProvider, UnicodeCharProperties, UnicodeCharWidth } from 'common/services/Services';
|
||||
import { EventEmitter, IEvent } from 'common/EventEmitter';
|
||||
import { UnicodeV6 } from 'common/input/UnicodeV6';
|
||||
|
||||
@@ -16,6 +16,19 @@ export class UnicodeService implements IUnicodeService {
|
||||
private readonly _onChange = new EventEmitter<string>();
|
||||
public readonly onChange = this._onChange.event;
|
||||
|
||||
public static extractShouldJoin(value: UnicodeCharProperties): boolean {
|
||||
return (value & 1) !== 0;
|
||||
}
|
||||
public static extractWidth(value: UnicodeCharProperties): UnicodeCharWidth {
|
||||
return ((value >> 1) & 0x3) as UnicodeCharWidth;
|
||||
}
|
||||
public static extractCharKind(value: UnicodeCharProperties): number {
|
||||
return value >> 3;
|
||||
}
|
||||
public static createPropertyValue(state: number, width: number, shouldJoin: boolean = false): UnicodeCharProperties {
|
||||
return ((state & 0xffffff) << 3) | ((width & 3) << 1) | (shouldJoin?1:0);
|
||||
}
|
||||
|
||||
constructor() {
|
||||
const defaultProvider = new UnicodeV6();
|
||||
this.register(defaultProvider);
|
||||
@@ -51,7 +64,7 @@ export class UnicodeService implements IUnicodeService {
|
||||
/**
|
||||
* Unicode version dependent interface.
|
||||
*/
|
||||
public wcwidth(num: number): number {
|
||||
public wcwidth(num: number): UnicodeCharWidth {
|
||||
return this._activeProvider.wcwidth(num);
|
||||
}
|
||||
|
||||
@@ -83,4 +96,8 @@ export class UnicodeService implements IUnicodeService {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
charProperties(codepoint: number, preceding: UnicodeCharProperties): UnicodeCharProperties {
|
||||
return this._activeProvider.charProperties(codepoint, preceding);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user