Skip to content

Commit 7b61c1f

Browse files
committed
Add offset value to ParseToken
1 parent 99a10cd commit 7b61c1f

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ interface ParseToken {
2424
background: Color | null;
2525
// A Set of the applied decorations
2626
decorations: Set<DecorationType>;
27+
// Offset from the beginning of the input value
28+
offset: number;
2729
}
2830
```
2931

src/parser.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@ import { Color, namedColors } from './colors';
22
import { DecorationType, decorations } from './decorations';
33

44
export interface ParseToken {
5+
/** The text content of the token. */
56
value: string;
7+
/** The foreground color */
68
foreground: Color | null;
9+
/** The background color. */
710
background: Color | null;
11+
/** A Set of the applied decorations. */
812
decorations: Set<DecorationType>;
13+
/** Offset from the beginning of the input value. */
14+
offset: number;
915
}
1016

1117
function findSequence(value: string, position: number) {
@@ -153,6 +159,7 @@ export function createAnsiSequenceParser() {
153159
let foreground: Color | null = null;
154160
let background: Color | null = null;
155161
let decorations: Set<DecorationType> = new Set();
162+
let chunkOffset = 0;
156163

157164
return {
158165
parse(value: string) {
@@ -172,6 +179,7 @@ export function createAnsiSequenceParser() {
172179
foreground,
173180
background,
174181
decorations: new Set(decorations),
182+
offset: chunkOffset + position
175183
});
176184
}
177185

@@ -208,6 +216,8 @@ export function createAnsiSequenceParser() {
208216
position = findResult.position;
209217
} while (position < value.length);
210218

219+
chunkOffset += value.length;
220+
211221
return tokens;
212222
},
213223
};

0 commit comments

Comments
 (0)