ptywright 0.4.0 → 0.6.0

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/dist/session.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { t as TerminalSession } from "./terminal_session-DopC7Xg6.mjs";
1
+ import { t as TerminalSession } from "./terminal_session-MX_vWpRG.mjs";
2
2
  export { TerminalSession };
@@ -0,0 +1,65 @@
1
+ //#region src/terminal/style.ts
2
+ const DEFAULT_STYLE = {
3
+ fg: { mode: "default" },
4
+ bg: { mode: "default" },
5
+ bold: false,
6
+ dim: false,
7
+ italic: false,
8
+ underline: false,
9
+ inverse: false,
10
+ strikethrough: false
11
+ };
12
+ function extractStyle(cell) {
13
+ const style = {
14
+ fg: extractColor(cell.isFgDefault(), cell.isFgPalette(), cell.isFgRGB(), cell.getFgColor()),
15
+ bg: extractColor(cell.isBgDefault(), cell.isBgPalette(), cell.isBgRGB(), cell.getBgColor()),
16
+ bold: cell.isBold() !== 0,
17
+ dim: cell.isDim() !== 0,
18
+ italic: cell.isItalic() !== 0,
19
+ underline: cell.isUnderline() !== 0,
20
+ inverse: cell.isInverse() !== 0,
21
+ strikethrough: cell.isStrikethrough() !== 0
22
+ };
23
+ return isDefaultStyle(style) ? DEFAULT_STYLE : style;
24
+ }
25
+ function isDefaultStyle(style) {
26
+ return style.fg.mode === "default" && style.bg.mode === "default" && !style.bold && !style.dim && !style.italic && !style.underline && !style.inverse && !style.strikethrough;
27
+ }
28
+ function styleKey(style) {
29
+ return [
30
+ style.fg.mode === "default" ? "d" : `${style.fg.mode}:${style.fg.value}`,
31
+ style.bg.mode === "default" ? "d" : `${style.bg.mode}:${style.bg.value}`,
32
+ style.bold ? "b" : "",
33
+ style.dim ? "d" : "",
34
+ style.italic ? "i" : "",
35
+ style.underline ? "u" : "",
36
+ style.inverse ? "r" : "",
37
+ style.strikethrough ? "s" : ""
38
+ ].join("|");
39
+ }
40
+ function findMeaningfulEndCol(line, cols, nullCell) {
41
+ if (!line) return 0;
42
+ for (let x = cols - 1; x >= 0; x -= 1) {
43
+ const cell = line.getCell(x, nullCell);
44
+ if (!cell) continue;
45
+ if (cell.getWidth() === 0) continue;
46
+ const chars = cell.getChars();
47
+ const style = extractStyle(cell);
48
+ if (chars !== "" && chars !== " " || !isDefaultStyle(style)) return x + 1;
49
+ }
50
+ return 0;
51
+ }
52
+ function extractColor(isDefault, isPalette, isRgb, value) {
53
+ if (isDefault) return { mode: "default" };
54
+ if (isRgb) return {
55
+ mode: "rgb",
56
+ value
57
+ };
58
+ if (isPalette) return {
59
+ mode: "palette",
60
+ value
61
+ };
62
+ return { mode: "default" };
63
+ }
64
+ //#endregion
65
+ export { styleKey as a, isDefaultStyle as i, extractStyle as n, findMeaningfulEndCol as r, DEFAULT_STYLE as t };