@shadr/iterm2-ts 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -9
- package/dist/cli.cjs +1115 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +2 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +1108 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +26 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +26 -3
- package/dist/index.js.map +1 -1
- package/package.json +10 -6
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
1
2
|
import { create, toBinary, fromBinary } from '@bufbuild/protobuf';
|
|
2
3
|
import { execFileSync } from 'child_process';
|
|
3
4
|
import net from 'net';
|
|
@@ -7,7 +8,6 @@ import { existsSync } from 'fs';
|
|
|
7
8
|
import { homedir } from 'os';
|
|
8
9
|
import { join } from 'path';
|
|
9
10
|
|
|
10
|
-
// src/api/client.ts
|
|
11
11
|
var cookieArgs = () => ["-e", 'tell application "iTerm2" to request cookie'];
|
|
12
12
|
var cookieAndKeyArgs = (name) => [
|
|
13
13
|
"-e",
|
|
@@ -501,6 +501,29 @@ var splitPane = async (conn, sessionId, options = {}) => {
|
|
|
501
501
|
}
|
|
502
502
|
return { id: newSessionId, name: "" };
|
|
503
503
|
};
|
|
504
|
+
function expandCells(chars, offset, numCodePoints, repeats, parts) {
|
|
505
|
+
for (let i = 0; i < repeats; i++) {
|
|
506
|
+
if (numCodePoints === 0) {
|
|
507
|
+
parts.push(" ");
|
|
508
|
+
} else {
|
|
509
|
+
parts.push(chars.slice(offset, offset + numCodePoints).join(""));
|
|
510
|
+
offset += numCodePoints;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
return offset;
|
|
514
|
+
}
|
|
515
|
+
function expandLineText(line) {
|
|
516
|
+
const text = line.text ?? "";
|
|
517
|
+
if (!line.codePointsPerCell || line.codePointsPerCell.length === 0)
|
|
518
|
+
return text.replaceAll("\0", " ");
|
|
519
|
+
const chars = [...text];
|
|
520
|
+
const parts = [];
|
|
521
|
+
let offset = 0;
|
|
522
|
+
for (const cppc of line.codePointsPerCell) {
|
|
523
|
+
offset = expandCells(chars, offset, cppc.numCodePoints, cppc.repeats || 1, parts);
|
|
524
|
+
}
|
|
525
|
+
return parts.join("").replaceAll("\0", " ");
|
|
526
|
+
}
|
|
504
527
|
var getScreenContents = async (conn, sessionId) => {
|
|
505
528
|
const response = await conn.send({
|
|
506
529
|
case: "getBufferRequest",
|
|
@@ -516,7 +539,7 @@ var getScreenContents = async (conn, sessionId) => {
|
|
|
516
539
|
if (bufferResponse.status !== 0 /* OK */) {
|
|
517
540
|
throw new Error(`getScreenContents failed: status ${bufferResponse.status}`);
|
|
518
541
|
}
|
|
519
|
-
return bufferResponse.contents.map(
|
|
542
|
+
return bufferResponse.contents.map(expandLineText).join("\n");
|
|
520
543
|
};
|
|
521
544
|
var getBuffer = async (conn, sessionId, trailingLines) => {
|
|
522
545
|
const lineRange = trailingLines != null ? create(LineRangeSchema, { trailingLines }) : create(LineRangeSchema, { screenContentsOnly: true });
|
|
@@ -535,7 +558,7 @@ var getBuffer = async (conn, sessionId, trailingLines) => {
|
|
|
535
558
|
throw new Error(`getBuffer failed: status ${bufferResponse.status}`);
|
|
536
559
|
}
|
|
537
560
|
return bufferResponse.contents.map((line) => ({
|
|
538
|
-
text: line
|
|
561
|
+
text: expandLineText(line),
|
|
539
562
|
continuation: line.continuation === 2 /* SOFT_EOL */ ? "soft" : "hard"
|
|
540
563
|
}));
|
|
541
564
|
};
|