Skip to content

Commit

Permalink
fix: color tests & locator resolution
Browse files Browse the repository at this point in the history
Signed-off-by: Chapman Pendery <[email protected]>
  • Loading branch information
cpendery committed Feb 9, 2024
1 parent 2910135 commit 5d316c5
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 21 deletions.
170 changes: 154 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/terminal/locator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ export class Locator {
this._cells = [];
for (let y = 0; y < buffer.length; y++) {
for (let x = 0; x < buffer[y].length ?? 0; x++) {
if (x + y >= index && x + y < index + length) {
const pos = x + y * buffer[y].length;
if (pos >= index && pos < index + length) {
this._cells.push({
termCell: this._xterm.buffer.active
.getLine(baseY + y)
Expand Down
10 changes: 6 additions & 4 deletions test/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,19 @@ test.describe("color detection", () => {
os.platform() === "linux",
"checks background color",
async ({ terminal }) => {
terminal.write(String.raw`printf \033[41mHello\n\033[0m\r`);
await expect(terminal.getByText("Hello ")).toHaveBgColor(41);
terminal.write(String.raw`printf "\x1b[42m%s%s\n\x1b[0m" foo bar`);
terminal.write("\r");
await expect(terminal.getByText("foobar")).toHaveBgColor(2);
}
);

test.when(
os.platform() === "linux",
"checks foreground color",
async ({ terminal }) => {
terminal.write(String.raw`printf \033[31mHello\n\033[0m\r`);
await expect(terminal.getByText("Hello ")).toHaveFgColor(31);
terminal.write(String.raw`printf "\x1b[41m%s%s\n\x1b[0m" foo bar`);
terminal.write("\r");
await expect(terminal.getByText("foobar")).toHaveFgColor(1);
}
);

Expand Down

0 comments on commit 5d316c5

Please sign in to comment.