Comparing version 5.4.0-beta.19 to 5.4.0-beta.20
{ | ||
"name": "xterm", | ||
"description": "Full xterm terminal, in your browser", | ||
"version": "5.4.0-beta.19", | ||
"version": "5.4.0-beta.20", | ||
"main": "lib/xterm.js", | ||
@@ -6,0 +6,0 @@ "style": "css/xterm.css", |
@@ -230,3 +230,3 @@ /** | ||
*/ | ||
public addCodepointToCell(index: number, codePoint: number): void { | ||
public addCodepointToCell(index: number, codePoint: number, width: number): void { | ||
let content = this._data[index * CELL_SIZE + Cell.CONTENT]; | ||
@@ -249,4 +249,8 @@ if (content & Content.IS_COMBINED_MASK) { | ||
} | ||
this._data[index * CELL_SIZE + Cell.CONTENT] = content; | ||
} | ||
if (width) { | ||
content &= ~Content.WIDTH_MASK; | ||
content |= width << Content.WIDTH_SHIFT; | ||
} | ||
this._data[index * CELL_SIZE + Cell.CONTENT] = content; | ||
} | ||
@@ -253,0 +257,0 @@ |
@@ -5,6 +5,5 @@ /** | ||
*/ | ||
import { IUnicodeVersionProvider } from 'common/services/Services'; | ||
import { IUnicodeVersionProvider, UnicodeCharProperties, UnicodeCharWidth } from 'common/services/Services'; | ||
import { UnicodeService } from 'common/services/UnicodeService'; | ||
type CharWidth = 0 | 1 | 2; | ||
const BMP_COMBINING = [ | ||
@@ -125,6 +124,6 @@ [0x0300, 0x036F], [0x0483, 0x0486], [0x0488, 0x0489], | ||
public wcwidth(num: number): CharWidth { | ||
public wcwidth(num: number): UnicodeCharWidth { | ||
if (num < 32) return 0; | ||
if (num < 127) return 1; | ||
if (num < 65536) return table[num] as CharWidth; | ||
if (num < 65536) return table[num] as UnicodeCharWidth; | ||
if (bisearch(num, HIGH_COMBINING)) return 0; | ||
@@ -134,2 +133,16 @@ if ((num >= 0x20000 && num <= 0x2fffd) || (num >= 0x30000 && num <= 0x3fffd)) return 2; | ||
} | ||
public charProperties(codepoint: number, preceding: UnicodeCharProperties): UnicodeCharProperties { | ||
let width = this.wcwidth(codepoint); | ||
let shouldJoin = width === 0 && preceding !== 0; | ||
if (shouldJoin) { | ||
const oldWidth = UnicodeService.extractWidth(preceding); | ||
if (oldWidth === 0) { | ||
shouldJoin = false; | ||
} else if (oldWidth > width) { | ||
width = oldWidth; | ||
} | ||
} | ||
return UnicodeService.createPropertyValue(0, width, shouldJoin); | ||
} | ||
} |
@@ -233,3 +233,3 @@ /** | ||
public currentState: number; | ||
public precedingCodepoint: number; | ||
public precedingJoinState: number; // UnicodeJoinProperties | ||
@@ -275,3 +275,3 @@ // buffers over several parse calls | ||
this._collect = 0; | ||
this.precedingCodepoint = 0; | ||
this.precedingJoinState = 0; | ||
@@ -453,3 +453,3 @@ // set default fallback handlers and handler lookup containers | ||
this._collect = 0; | ||
this.precedingCodepoint = 0; | ||
this.precedingJoinState = 0; | ||
// abort pending continuation from async handler | ||
@@ -616,3 +616,3 @@ // Here the RESET type indicates, that the next parse call will | ||
start = this._parseStack.chunkPos + 1; | ||
this.precedingCodepoint = 0; | ||
this.precedingJoinState = 0; | ||
this.currentState = this._parseStack.transition & TableAccess.TRANSITION_STATE_MASK; | ||
@@ -660,3 +660,3 @@ } | ||
else this._executeHandlerFb(code); | ||
this.precedingCodepoint = 0; | ||
this.precedingJoinState = 0; | ||
break; | ||
@@ -696,3 +696,3 @@ case ParserAction.IGNORE: | ||
} | ||
this.precedingCodepoint = 0; | ||
this.precedingJoinState = 0; | ||
break; | ||
@@ -736,3 +736,3 @@ case ParserAction.PARAM: | ||
} | ||
this.precedingCodepoint = 0; | ||
this.precedingJoinState = 0; | ||
break; | ||
@@ -768,3 +768,3 @@ case ParserAction.CLEAR: | ||
this._collect = 0; | ||
this.precedingCodepoint = 0; | ||
this.precedingJoinState = 0; | ||
break; | ||
@@ -794,3 +794,3 @@ case ParserAction.OSC_START: | ||
this._collect = 0; | ||
this.precedingCodepoint = 0; | ||
this.precedingJoinState = 0; | ||
break; | ||
@@ -797,0 +797,0 @@ } |
@@ -149,7 +149,8 @@ /** | ||
/** | ||
* Preceding codepoint to get REP working correctly. | ||
* This must be set by the print handler as last action. | ||
* It gets reset by the parser for any valid sequence beside REP itself. | ||
* Preceding grapheme-join-state. | ||
* Used for joining grapheme clusters across calls to `print`. | ||
* Also used by REP to check if repeating a character is allowed. | ||
* It gets reset by the parser for any valid sequence besides text. | ||
*/ | ||
precedingCodepoint: number; | ||
precedingJoinState: number; // More specifically: UnicodeJoinProperties | ||
@@ -156,0 +157,0 @@ /** |
@@ -299,2 +299,25 @@ /** | ||
/* | ||
* Width and Grapheme_Cluster_Break properties of a character as a bit mask. | ||
* | ||
* bit 0: shouldJoin - should combine with preceding character. | ||
* bit 1..2: wcwidth - see UnicodeCharWidth. | ||
* bit 3..31: class of character (currently only 4 bits are used). | ||
* This is used to determined grapheme clustering - i.e. which codepoints | ||
* are to be combined into a single compound character. | ||
* | ||
* Use the UnicodeService static function createPropertyValue to create a | ||
* UnicodeCharProperties; use extractShouldJoin, extractWidth, and | ||
* extractCharKind to extract the components. | ||
*/ | ||
export type UnicodeCharProperties = number; | ||
/** | ||
* Width in columns of a character. | ||
* In a CJK context, "half-width" characters (such as Latin) are width 1, | ||
* while "full-width" characters (such as Kanji) are 2 columns wide. | ||
* Combining characters (such as accents) are width 0. | ||
*/ | ||
export type UnicodeCharWidth = 0 | 1 | 2; | ||
export const IUnicodeService = createDecorator<IUnicodeService>('UnicodeService'); | ||
@@ -315,4 +338,10 @@ export interface IUnicodeService { | ||
*/ | ||
wcwidth(codepoint: number): number; | ||
wcwidth(codepoint: number): UnicodeCharWidth; | ||
getStringCellWidth(s: string): number; | ||
/** | ||
* Return character width and type for grapheme clustering. | ||
* If preceding != 0, it is the return code from the previous character; | ||
* in that case the result specifies if the characters should be joined. | ||
*/ | ||
charProperties(codepoint: number, preceding: UnicodeCharProperties): UnicodeCharProperties; | ||
} | ||
@@ -322,3 +351,4 @@ | ||
readonly version: string; | ||
wcwidth(ucs: number): 0 | 1 | 2; | ||
wcwidth(ucs: number): UnicodeCharWidth; | ||
charProperties(codepoint: number, preceding: UnicodeCharProperties): UnicodeCharProperties; | ||
} | ||
@@ -325,0 +355,0 @@ |
@@ -5,5 +5,6 @@ /** | ||
*/ | ||
import { EventEmitter } from 'common/EventEmitter'; | ||
import { UnicodeV6 } from 'common/input/UnicodeV6'; | ||
import { IUnicodeService, IUnicodeVersionProvider } from 'common/services/Services'; | ||
import { IUnicodeService, IUnicodeVersionProvider, UnicodeCharProperties, UnicodeCharWidth } from 'common/services/Services'; | ||
@@ -20,2 +21,15 @@ export class UnicodeService implements IUnicodeService { | ||
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() { | ||
@@ -56,3 +70,3 @@ const defaultProvider = new UnicodeV6(); | ||
*/ | ||
public wcwidth(num: number): number { | ||
public wcwidth(num: number): UnicodeCharWidth { | ||
return this._activeProvider.wcwidth(num); | ||
@@ -63,2 +77,3 @@ } | ||
let result = 0; | ||
let precedingInfo = 0; | ||
const length = s.length; | ||
@@ -86,6 +101,16 @@ for (let i = 0; i < length; ++i) { | ||
} | ||
result += this.wcwidth(code); | ||
const currentInfo = this.charProperties(code, precedingInfo); | ||
let chWidth = UnicodeService.extractWidth(currentInfo); | ||
if (UnicodeService.extractShouldJoin(currentInfo)) { | ||
chWidth -= UnicodeService.extractWidth(precedingInfo); | ||
} | ||
result += chWidth; | ||
precedingInfo = currentInfo; | ||
} | ||
return result; | ||
} | ||
public charProperties(codepoint: number, preceding: UnicodeCharProperties): UnicodeCharProperties { | ||
return this._activeProvider.charProperties(codepoint, preceding); | ||
} | ||
} |
@@ -237,3 +237,3 @@ /** | ||
setCellFromCodePoint(index: number, codePoint: number, width: number, fg: number, bg: number, eAttrs: IExtendedAttrs): void; | ||
addCodepointToCell(index: number, codePoint: number): void; | ||
addCodepointToCell(index: number, codePoint: number, width: number): void; | ||
insertCells(pos: number, n: number, ch: ICellData, eraseAttr?: IAttributeData): void; | ||
@@ -240,0 +240,0 @@ deleteCells(pos: number, n: number, fill: ICellData, eraseAttr?: IAttributeData): void; |
@@ -1776,2 +1776,3 @@ /** | ||
wcwidth(codepoint: number): 0 | 1 | 2; | ||
charProperties(codepoint: number, preceding: number): number; | ||
} | ||
@@ -1778,0 +1779,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2348958
24505