@poe-platform/safe-bash 0.1.755 → 0.1.757
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/image-ast/index.browser.js +30 -6
- package/dist/image-ast/index.js +30 -6
- package/dist/pdf-ast/canvas.d.ts +1 -0
- package/dist/pdf-ast/index.js +26 -2
- package/dist/safe-bash/chunks/{chunk-LESPJ3OG.js → chunk-WNWIBBJZ.js} +15 -2
- package/dist/safe-bash/command-chunks/{chunk-S4J6MSLY.js → chunk-444OTXM7.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-6AIOGLZO.js → chunk-CE6Z2ULX.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-5VSGEE6J.js → chunk-F4IQCXZG.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-F5MORDSU.js → chunk-FDNCPZQS.js} +32 -1
- package/dist/safe-bash/command-chunks/{chunk-SG3ZDZCX.js → chunk-FLMLM7Y4.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-XRVNFK7Z.js → chunk-H2FQA4OU.js} +26 -2
- package/dist/safe-bash/command-chunks/{chunk-CT3FB722.js → chunk-J7UMKBRK.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-KB2LQ4HG.js → chunk-KBBI4CSU.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-QQOAK7JQ.js → chunk-KKJCKPTA.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-7KS6PX4U.js → chunk-KSIGF4AG.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-4HQ7WYSI.js → chunk-MED2BOOW.js} +30 -5
- package/dist/safe-bash/command-chunks/{chunk-JRNLDPLI.js → chunk-OZSWW23M.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-DKQ5REXF.js → chunk-QDPRSPHQ.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-WOPU2VWF.js → chunk-RID3B5RE.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-DVZCHNB5.js → chunk-S4MLIYSN.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-REYTQLLB.js → chunk-TT2DMDBY.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-UGX6MXDD.js → chunk-UIIT4ULR.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-MENC7RPR.js → chunk-WI35236J.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-A6NFLWZI.js → chunk-WKPOGTZY.js} +22 -6
- package/dist/safe-bash/command-chunks/{chunk-3DOHQQJR.js → chunk-Y64PA6IA.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-6Z7OS3TZ.js → chunk-ZP5KDHB4.js} +7 -7
- package/dist/safe-bash/commands/pandoc/index.d.ts +1 -1
- package/dist/safe-bash/commands/pandoc/index.js +5 -3
- package/dist/safe-bash/commands/python/index.browser.js +1 -1
- package/dist/safe-bash/commands/python/index.js +6 -0
- package/dist/safe-bash/commands/python/jspi.js +11 -2
- package/dist/safe-bash/core.browser.js +6 -4
- package/dist/safe-bash-command-csvkit/index.js +8 -8
- package/dist/safe-bash-command-ffmpeg/index.js +20 -2
- package/dist/safe-bash-command-imagemagick/index.js +2 -2
- package/dist/safe-bash-command-pandoc/command.js +3 -3
- package/dist/safe-bash-command-pandoc/index.js +3 -3
- package/dist/safe-bash-command-pdfimages/index.js +26 -2
- package/dist/safe-bash-command-pdfinfo/index.js +26 -2
- package/dist/safe-bash-command-pdftk/index.js +26 -2
- package/dist/safe-bash-command-pdftoppm/index.js +26 -2
- package/dist/safe-bash-command-pdftotext/index.js +26 -2
- package/dist/safe-bash-command-qpdf/index.js +26 -2
- package/dist/safe-bash-command-sips/index.js +2 -2
- package/dist/safe-bash-command-soffice/index.js +17 -17
- package/dist/safe-bash-command-ssconvert/core.js +8 -8
- package/dist/safe-bash-command-ssconvert/formats/csv.js +9 -9
- package/dist/safe-bash-command-ssconvert/formats/ods.js +8 -8
- package/dist/safe-bash-command-ssconvert/formats/spreadsheetml.js +1 -1
- package/dist/safe-bash-command-ssconvert/formats/xls.js +9 -8
- package/dist/safe-bash-command-ssconvert/formats/xlsx.js +8 -8
- package/dist/safe-bash-command-ssconvert/index.js +133 -29
- package/dist/safe-bash-command-wkhtmltopdf/index.js +26 -2
- package/dist/safe-bash-contracts/filesystem-descriptor.js +1 -1
- package/dist/safe-bash-contracts/filesystem-output.js +1 -1
- package/dist/safe-bash-mcp/index.js +4 -4
- package/dist/spreadsheet-engine/formulas/ast.d.ts +13 -0
- package/dist/spreadsheet-engine/formulas/conventions.js +1 -1
- package/dist/spreadsheet-engine/formulas/dependencies.js +2 -2
- package/dist/spreadsheet-engine/formulas/evaluator.js +2 -2
- package/dist/spreadsheet-engine/formulas/named-expressions.d.ts +2 -2
- package/dist/spreadsheet-engine/formulas/named-expressions.js +31 -5
- package/dist/spreadsheet-engine/formulas/parser.js +34 -0
- package/dist/spreadsheet-engine/formulas/rewriting.js +19 -1
- package/dist/spreadsheet-engine/formulas/serialization.js +6 -0
- package/dist/spreadsheet-format-xls/biff-write-formulas.js +2 -0
- package/dist/xlsx-ast/formula-semantics.js +2 -0
- package/package.json +2 -2
- package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +1 -1
- package/dist/safe-bash/chunks/browser-ECQX6GMK.js +0 -6766
- package/dist/safe-bash/chunks/bz2-4OP3OWW3.js +0 -8
- package/dist/safe-bash/chunks/chunk-22XPAAOI.js +0 -173
- package/dist/safe-bash/chunks/chunk-44WUNUPV.js +0 -649
- package/dist/safe-bash/chunks/chunk-4E3SGG37.js +0 -876
- package/dist/safe-bash/chunks/chunk-4QTSSQKP.js +0 -898
- package/dist/safe-bash/chunks/chunk-5UVGPVXP.js +0 -410
- package/dist/safe-bash/chunks/chunk-64OE6Q6X.js +0 -3487
- package/dist/safe-bash/chunks/chunk-6IIFUPN2.js +0 -1526
- package/dist/safe-bash/chunks/chunk-6XDKK63A.js +0 -38959
- package/dist/safe-bash/chunks/chunk-BENDLTQD.js +0 -7065
- package/dist/safe-bash/chunks/chunk-BMO5LWEX.js +0 -534
- package/dist/safe-bash/chunks/chunk-BPMCPTNP.js +0 -1920
- package/dist/safe-bash/chunks/chunk-BRJTAWP5.js +0 -2955
- package/dist/safe-bash/chunks/chunk-C3GEIN7Q.js +0 -20054
- package/dist/safe-bash/chunks/chunk-CEWCRI6H.js +0 -2813
- package/dist/safe-bash/chunks/chunk-CGL53DQQ.js +0 -37
- package/dist/safe-bash/chunks/chunk-CTYJJD4O.js +0 -869
- package/dist/safe-bash/chunks/chunk-CWSS4MQA.js +0 -7
- package/dist/safe-bash/chunks/chunk-DLIGMTCP.js +0 -3266
- package/dist/safe-bash/chunks/chunk-EMAJ7WUW.js +0 -1031
- package/dist/safe-bash/chunks/chunk-FDKIZ2IJ.js +0 -1950
- package/dist/safe-bash/chunks/chunk-FZWJ2A7V.js +0 -3093
- package/dist/safe-bash/chunks/chunk-G2VCIF2J.js +0 -22
- package/dist/safe-bash/chunks/chunk-GVKBUQDX.js +0 -2649
- package/dist/safe-bash/chunks/chunk-IO2OGW3E.js +0 -28051
- package/dist/safe-bash/chunks/chunk-ISCZG7WA.js +0 -2648
- package/dist/safe-bash/chunks/chunk-JEFBTRY7.js +0 -174814
- package/dist/safe-bash/chunks/chunk-KJHDD4A2.js +0 -759
- package/dist/safe-bash/chunks/chunk-LB6HVRXS.js +0 -857
- package/dist/safe-bash/chunks/chunk-LLWAJOZH.js +0 -15
- package/dist/safe-bash/chunks/chunk-LMUKYZIJ.js +0 -708
- package/dist/safe-bash/chunks/chunk-M5SCNKIK.js +0 -2012
- package/dist/safe-bash/chunks/chunk-MJPFHANT.js +0 -3350
- package/dist/safe-bash/chunks/chunk-MZQW2DOL.js +0 -82
- package/dist/safe-bash/chunks/chunk-NB2V7EOY.js +0 -1348
- package/dist/safe-bash/chunks/chunk-NJVGOIYN.js +0 -17
- package/dist/safe-bash/chunks/chunk-OLNZHDIQ.js +0 -5141
- package/dist/safe-bash/chunks/chunk-OUUVROTM.js +0 -38
- package/dist/safe-bash/chunks/chunk-PA6GYKBQ.js +0 -151
- package/dist/safe-bash/chunks/chunk-PEFHZ226.js +0 -6957
- package/dist/safe-bash/chunks/chunk-QBB5P5KW.js +0 -4839
- package/dist/safe-bash/chunks/chunk-QHB7HBLA.js +0 -2317
- package/dist/safe-bash/chunks/chunk-RSAWYAEH.js +0 -973
- package/dist/safe-bash/chunks/chunk-UWLYRWT4.js +0 -739
- package/dist/safe-bash/chunks/chunk-V463NBQH.js +0 -13
- package/dist/safe-bash/chunks/chunk-WPUALYUS.js +0 -843
- package/dist/safe-bash/chunks/chunk-XHKFSRGU.js +0 -5747
- package/dist/safe-bash/chunks/chunk-XHRCLZ3N.js +0 -13391
- package/dist/safe-bash/chunks/chunk-XPF5XHLY.js +0 -15
- package/dist/safe-bash/chunks/chunk-ZBFOWARG.js +0 -305
- package/dist/safe-bash/chunks/chunk-ZG7GWQ5P.js +0 -1859
- package/dist/safe-bash/chunks/model-store-EIY3ZQLZ.js +0 -10
- package/dist/safe-bash/chunks/pdf-renderer-XIFUTX34.js +0 -22
- package/dist/safe-bash/chunks/pptx-ZL6L7KP2-O425BFIU.js +0 -30658
- package/dist/safe-bash/chunks/src-HHEPGR7U.js +0 -18969
- package/dist/safe-bash/chunks/src-V4VCM5OX.js +0 -187
- package/dist/safe-bash/chunks/usage-6TGVA2OM.js +0 -35
- package/dist/safe-bash/chunks/xz-EGQGQUEI.js +0 -8
- package/dist/safe-bash/chunks/xz-K2E2WLM6.js +0 -9
- package/dist/safe-bash/chunks/zstd-6JBLP5EF.js +0 -8
- package/dist/safe-bash/git_rust-C3QYOAZL.wasm +0 -0
|
@@ -1,2012 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CommandFailure,
|
|
3
|
-
TimeZone,
|
|
4
|
-
builtInDirectContextExecutors,
|
|
5
|
-
checkSize,
|
|
6
|
-
floorDivide,
|
|
7
|
-
monthNames,
|
|
8
|
-
nanosecondsPerSecond,
|
|
9
|
-
utcMilliseconds,
|
|
10
|
-
utf8ByteLength,
|
|
11
|
-
weekdayNames
|
|
12
|
-
} from "./chunk-ISCZG7WA.js";
|
|
13
|
-
import {
|
|
14
|
-
init_platform
|
|
15
|
-
} from "./chunk-ZG7GWQ5P.js";
|
|
16
|
-
|
|
17
|
-
// packages/safe-bash/src/commands/pr/index.ts
|
|
18
|
-
init_platform();
|
|
19
|
-
|
|
20
|
-
// packages/safe-bash-command-pr/src/index.ts
|
|
21
|
-
init_platform();
|
|
22
|
-
|
|
23
|
-
// packages/safe-bash-command-pr/src/command.ts
|
|
24
|
-
init_platform();
|
|
25
|
-
import { FsError as FsError2 } from "../../safe-bash-contracts/index.js";
|
|
26
|
-
import { createOutputOperation } from "../../safe-bash-contracts/output.js";
|
|
27
|
-
import { publicDiagnosticMessage } from "../../safe-bash-contracts/diagnostics.js";
|
|
28
|
-
|
|
29
|
-
// packages/safe-bash-command-pr/src/internal.ts
|
|
30
|
-
init_platform();
|
|
31
|
-
import { getCommandArguments } from "../../safe-bash-contracts/index.js";
|
|
32
|
-
import { shellValueByteLength, shellValueBytes } from "../../safe-bash-contracts/value.js";
|
|
33
|
-
import { hasYieldCheckpoint, inheritYieldCheckpoint, monotonicNow, runYieldCheckpoint, yieldTurn } from "../../safe-bash-contracts/yield.js";
|
|
34
|
-
import { PublicDiagnostic } from "../../safe-bash-contracts/diagnostics.js";
|
|
35
|
-
function settings(options) {
|
|
36
|
-
const limits = {
|
|
37
|
-
maxArguments: Infinity,
|
|
38
|
-
maxArgumentBytes: Infinity,
|
|
39
|
-
maxFiles: Infinity,
|
|
40
|
-
maxColumns: Infinity,
|
|
41
|
-
maxPageLines: Infinity,
|
|
42
|
-
maxPageWidth: Infinity,
|
|
43
|
-
maxPages: Infinity,
|
|
44
|
-
maxInputBytes: Infinity,
|
|
45
|
-
maxBufferedBytes: Infinity,
|
|
46
|
-
maxLineBytes: Infinity,
|
|
47
|
-
maxLines: Infinity,
|
|
48
|
-
maxOutputBytes: Infinity,
|
|
49
|
-
maxDiagnosticBytes: Infinity,
|
|
50
|
-
maxWork: Infinity,
|
|
51
|
-
maxEmptyChunks: Infinity,
|
|
52
|
-
...options.limits
|
|
53
|
-
};
|
|
54
|
-
for (const [name, value] of Object.entries(limits)) {
|
|
55
|
-
if (value !== Infinity && !Number.isSafeInteger(value) || value < 1) throw new RangeError(`Invalid pr limit: ${name}`);
|
|
56
|
-
}
|
|
57
|
-
if (options.clock !== void 0 && typeof options.clock !== "function") throw new TypeError("pr clock must be a function");
|
|
58
|
-
return Object.freeze(limits);
|
|
59
|
-
}
|
|
60
|
-
var PrError = class extends PublicDiagnostic {
|
|
61
|
-
constructor(message, usage = false) {
|
|
62
|
-
super(message);
|
|
63
|
-
this.usage = usage;
|
|
64
|
-
}
|
|
65
|
-
usage;
|
|
66
|
-
};
|
|
67
|
-
var PrReadError = class extends PrError {
|
|
68
|
-
};
|
|
69
|
-
function raw(value) {
|
|
70
|
-
let text = "";
|
|
71
|
-
for (const byte of value) text += String.fromCharCode(byte);
|
|
72
|
-
return text;
|
|
73
|
-
}
|
|
74
|
-
function bytes(value) {
|
|
75
|
-
const len = value.length;
|
|
76
|
-
const out = new Uint8Array(len);
|
|
77
|
-
for (let i = 0; i < len; i++) out[i] = value.charCodeAt(i);
|
|
78
|
-
return out;
|
|
79
|
-
}
|
|
80
|
-
function pathText(value) {
|
|
81
|
-
try {
|
|
82
|
-
return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes(value));
|
|
83
|
-
} catch {
|
|
84
|
-
throw new PrError("filesystem paths must be valid UTF-8");
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
function quote(value) {
|
|
88
|
-
const escapes = { "\x07": "\\a", "\b": "\\b", "\f": "\\f", "\n": "\\n", "\r": "\\r", " ": "\\t", "\v": "\\v", "\\": "\\\\", "'": "\\'" };
|
|
89
|
-
let result = "'";
|
|
90
|
-
for (const character of value) {
|
|
91
|
-
const code = character.charCodeAt(0);
|
|
92
|
-
result += escapes[character] ?? (code >= 32 && code < 127 ? character : `\\${code.toString(8).padStart(3, "0")}`);
|
|
93
|
-
}
|
|
94
|
-
return `${result}'`;
|
|
95
|
-
}
|
|
96
|
-
function fileQuote(value) {
|
|
97
|
-
let safe = value.length > 0, escaped = false;
|
|
98
|
-
for (const character of value) {
|
|
99
|
-
const code = character.charCodeAt(0);
|
|
100
|
-
if (!(character >= "a" && character <= "z" || character >= "A" && character <= "Z" || character >= "0" && character <= "9" || "_./-".includes(character))) safe = false;
|
|
101
|
-
if (code < 32 || code >= 127) escaped = true;
|
|
102
|
-
}
|
|
103
|
-
if (safe) return value;
|
|
104
|
-
if (!escaped) {
|
|
105
|
-
if (value.includes("'") && !["$", "`", "\\", '"'].some((character) => value.includes(character))) return `"${value}"`;
|
|
106
|
-
return `'${value.split("'").join("'\\''")}'`;
|
|
107
|
-
}
|
|
108
|
-
let result = "'", inEscape = false;
|
|
109
|
-
for (const character of value) {
|
|
110
|
-
const code = character.charCodeAt(0);
|
|
111
|
-
if (code < 32 || code >= 127) {
|
|
112
|
-
if (!inEscape) {
|
|
113
|
-
result += "'$'";
|
|
114
|
-
inEscape = true;
|
|
115
|
-
}
|
|
116
|
-
result += quote(character).slice(1, -1);
|
|
117
|
-
} else {
|
|
118
|
-
if (inEscape) {
|
|
119
|
-
result += "''";
|
|
120
|
-
inEscape = false;
|
|
121
|
-
}
|
|
122
|
-
result += character === "'" ? "'\\''" : character;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return `${result}'`;
|
|
126
|
-
}
|
|
127
|
-
var Budget = class {
|
|
128
|
-
constructor(context, limits, signal) {
|
|
129
|
-
this.context = context;
|
|
130
|
-
this.limits = limits;
|
|
131
|
-
this.signal = signal;
|
|
132
|
-
inheritYieldCheckpoint(context.signal, signal);
|
|
133
|
-
this.signalAborted = signal.aborted;
|
|
134
|
-
this.pollSignal = Object.prototype.hasOwnProperty.call(signal, "aborted");
|
|
135
|
-
if (!this.signalAborted && !this.pollSignal) {
|
|
136
|
-
signal.addEventListener("abort", () => {
|
|
137
|
-
this.signalAborted = true;
|
|
138
|
-
}, { once: true });
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
context;
|
|
142
|
-
limits;
|
|
143
|
-
signal;
|
|
144
|
-
work = 0;
|
|
145
|
-
checkpoint = 0;
|
|
146
|
-
lastYield = monotonicNow();
|
|
147
|
-
retained = 0;
|
|
148
|
-
input = 0;
|
|
149
|
-
lines = 0;
|
|
150
|
-
pages = 0;
|
|
151
|
-
output = 0;
|
|
152
|
-
diagnostics = 0;
|
|
153
|
-
signalAborted;
|
|
154
|
-
pollSignal;
|
|
155
|
-
assertSignalOpen() {
|
|
156
|
-
if (this.pollSignal ? this.signal.aborted : this.signalAborted) this.signal.throwIfAborted();
|
|
157
|
-
}
|
|
158
|
-
check(value, maximum, label) {
|
|
159
|
-
if (value > maximum || value < 0 || (value | 0) !== value && !Number.isSafeInteger(value)) throw new PrError(`${label} limit exceeded`);
|
|
160
|
-
}
|
|
161
|
-
charge(amount = 1) {
|
|
162
|
-
this.assertSignalOpen();
|
|
163
|
-
this.work += amount;
|
|
164
|
-
this.check(this.work, this.limits.maxWork, "work");
|
|
165
|
-
}
|
|
166
|
-
checkpointWork() {
|
|
167
|
-
this.assertSignalOpen();
|
|
168
|
-
if (this.work - this.checkpoint < 4096) return;
|
|
169
|
-
this.checkpoint = this.work;
|
|
170
|
-
if (!hasYieldCheckpoint(this.signal) && monotonicNow() - this.lastYield < 25) {
|
|
171
|
-
runYieldCheckpoint(this.signal);
|
|
172
|
-
this.assertSignalOpen();
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
return yieldTurn(this.signal).then(() => {
|
|
176
|
-
this.lastYield = monotonicNow();
|
|
177
|
-
this.assertSignalOpen();
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
retain(amount) {
|
|
181
|
-
this.check(this.retained + amount, this.limits.maxBufferedBytes, "buffered bytes");
|
|
182
|
-
this.retained += amount;
|
|
183
|
-
}
|
|
184
|
-
admitString(length) {
|
|
185
|
-
this.assertSignalOpen();
|
|
186
|
-
this.check(length, this.limits.maxWork - this.work, "work");
|
|
187
|
-
this.check(this.retained + length * 2, this.limits.maxBufferedBytes, "buffered bytes");
|
|
188
|
-
}
|
|
189
|
-
inputBytes(amount) {
|
|
190
|
-
this.input += amount;
|
|
191
|
-
this.check(this.input, this.limits.maxInputBytes, "input bytes");
|
|
192
|
-
}
|
|
193
|
-
line() {
|
|
194
|
-
this.check(++this.lines, this.limits.maxLines, "input lines");
|
|
195
|
-
}
|
|
196
|
-
page() {
|
|
197
|
-
this.check(++this.pages, this.limits.maxPages, "pages");
|
|
198
|
-
this.charge();
|
|
199
|
-
}
|
|
200
|
-
admitOutput(amount) {
|
|
201
|
-
this.assertSignalOpen();
|
|
202
|
-
this.check(this.output + amount, this.limits.maxOutputBytes, "output bytes");
|
|
203
|
-
}
|
|
204
|
-
emitted(amount, diagnostic) {
|
|
205
|
-
if (diagnostic) {
|
|
206
|
-
this.diagnostics += amount;
|
|
207
|
-
this.check(this.diagnostics, this.limits.maxDiagnosticBytes, "diagnostic bytes");
|
|
208
|
-
} else {
|
|
209
|
-
this.output += amount;
|
|
210
|
-
this.check(this.output, this.limits.maxOutputBytes, "output bytes");
|
|
211
|
-
}
|
|
212
|
-
if (!diagnostic) this.charge(amount);
|
|
213
|
-
}
|
|
214
|
-
arguments() {
|
|
215
|
-
this.check(this.context.args.length, this.limits.maxArguments, "argument count");
|
|
216
|
-
let total = 0;
|
|
217
|
-
for (const argument of this.context.args) {
|
|
218
|
-
total += argument.length;
|
|
219
|
-
this.check(total, this.limits.maxArgumentBytes, "argument bytes");
|
|
220
|
-
for (let offset = 0; offset < argument.length; offset++) {
|
|
221
|
-
const unit = argument.charCodeAt(offset);
|
|
222
|
-
if (unit >= 55296 && unit <= 56319) {
|
|
223
|
-
const next = argument.charCodeAt(++offset);
|
|
224
|
-
if (!(next >= 56320 && next <= 57343)) throw new PrError("arguments must contain well-formed Unicode");
|
|
225
|
-
} else if (unit >= 56320 && unit <= 57343) throw new PrError("arguments must contain well-formed Unicode");
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
total = 0;
|
|
229
|
-
return getCommandArguments(this.context).values.map((argument) => {
|
|
230
|
-
total += shellValueByteLength(argument);
|
|
231
|
-
this.check(total, this.limits.maxArgumentBytes, "argument bytes");
|
|
232
|
-
const value = shellValueBytes(argument);
|
|
233
|
-
this.charge(value.length);
|
|
234
|
-
if (value.includes(0)) throw new PrError("NUL is not supported in arguments");
|
|
235
|
-
return raw(value);
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
// packages/safe-bash-command-pr/src/io.ts
|
|
241
|
-
init_platform();
|
|
242
|
-
import { FsError, resolvePath } from "../../safe-bash-contracts/index.js";
|
|
243
|
-
var Lifecycle = class {
|
|
244
|
-
constructor(budget, output) {
|
|
245
|
-
this.budget = budget;
|
|
246
|
-
output.registerCleanup(() => this.close());
|
|
247
|
-
}
|
|
248
|
-
budget;
|
|
249
|
-
pending = /* @__PURE__ */ new Set();
|
|
250
|
-
cleanups = [];
|
|
251
|
-
closing;
|
|
252
|
-
pendingStdout = "";
|
|
253
|
-
cleanup(action) {
|
|
254
|
-
this.assertOpen();
|
|
255
|
-
this.cleanups.push(action);
|
|
256
|
-
}
|
|
257
|
-
assertOpen() {
|
|
258
|
-
this.budget.assertSignalOpen();
|
|
259
|
-
if (this.closing) throw new PrError("command is closed");
|
|
260
|
-
}
|
|
261
|
-
hasPendingStdout() {
|
|
262
|
-
return this.pendingStdout.length > 0;
|
|
263
|
-
}
|
|
264
|
-
takeStdoutSync() {
|
|
265
|
-
const chunk = this.pendingStdout;
|
|
266
|
-
this.pendingStdout = "";
|
|
267
|
-
this.budget.retain(-chunk.length * 3);
|
|
268
|
-
return chunk;
|
|
269
|
-
}
|
|
270
|
-
async operation(action, admitted = false) {
|
|
271
|
-
this.assertOpen();
|
|
272
|
-
if (!admitted) this.budget.charge();
|
|
273
|
-
const pending = Promise.resolve().then(() => {
|
|
274
|
-
this.assertOpen();
|
|
275
|
-
return action();
|
|
276
|
-
});
|
|
277
|
-
this.pending.add(pending);
|
|
278
|
-
try {
|
|
279
|
-
const value = await pending;
|
|
280
|
-
this.assertOpen();
|
|
281
|
-
return value;
|
|
282
|
-
} finally {
|
|
283
|
-
this.pending.delete(pending);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
close() {
|
|
287
|
-
return this.closing ??= Promise.resolve().then(async () => {
|
|
288
|
-
while (this.pending.size) await Promise.allSettled([...this.pending]);
|
|
289
|
-
const failures = [];
|
|
290
|
-
for (const cleanup of this.cleanups) {
|
|
291
|
-
try {
|
|
292
|
-
await cleanup();
|
|
293
|
-
} catch (error) {
|
|
294
|
-
failures.push(error);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
if (failures.length === 1) throw failures[0];
|
|
298
|
-
if (failures.length > 1) throw new AggregateError(failures, "pr cleanup failed");
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
async flush() {
|
|
302
|
-
if (!this.pendingStdout.length) return;
|
|
303
|
-
const chunk = this.pendingStdout;
|
|
304
|
-
this.pendingStdout = "";
|
|
305
|
-
const { budget } = this;
|
|
306
|
-
try {
|
|
307
|
-
await this.operation(async () => {
|
|
308
|
-
const sink = budget.context.stdout;
|
|
309
|
-
this.assertOpen();
|
|
310
|
-
const destination = sink.ownedOutput ?? sink;
|
|
311
|
-
this.assertOpen();
|
|
312
|
-
const write = destination.write;
|
|
313
|
-
this.assertOpen();
|
|
314
|
-
await Reflect.apply(write, destination, [bytes(chunk)]);
|
|
315
|
-
}, true);
|
|
316
|
-
} finally {
|
|
317
|
-
budget.retain(-chunk.length * 3);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
async write(value, diagnostic = false) {
|
|
321
|
-
const p = this.writeSyncOrAsync(value, diagnostic);
|
|
322
|
-
if (p) await p;
|
|
323
|
-
}
|
|
324
|
-
writeSyncOrAsync(value, diagnostic = false) {
|
|
325
|
-
const { budget } = this;
|
|
326
|
-
if (!diagnostic) {
|
|
327
|
-
budget.emitted(value.length, false);
|
|
328
|
-
this.assertOpen();
|
|
329
|
-
budget.charge();
|
|
330
|
-
if (!value.length) return;
|
|
331
|
-
budget.retain(value.length * 3);
|
|
332
|
-
this.pendingStdout += value;
|
|
333
|
-
if (Number.isFinite(budget.limits.maxBufferedBytes) || this.pendingStdout.length >= 16384) return this.flush();
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
return this.writeDiagnosticSlow(value);
|
|
337
|
-
}
|
|
338
|
-
async writeDiagnosticSlow(value) {
|
|
339
|
-
const { budget } = this;
|
|
340
|
-
if (this.pendingStdout.length) await this.flush();
|
|
341
|
-
budget.emitted(value.length, true);
|
|
342
|
-
await this.operation(async () => {
|
|
343
|
-
const sink = budget.context.stderr;
|
|
344
|
-
this.assertOpen();
|
|
345
|
-
const destination = sink.ownedOutput ?? sink;
|
|
346
|
-
this.assertOpen();
|
|
347
|
-
const write = destination.write;
|
|
348
|
-
this.assertOpen();
|
|
349
|
-
await Reflect.apply(write, destination, [bytes(value)]);
|
|
350
|
-
}, true);
|
|
351
|
-
}
|
|
352
|
-
};
|
|
353
|
-
var Reader = class {
|
|
354
|
-
constructor(name, lifecycle) {
|
|
355
|
-
this.name = name;
|
|
356
|
-
this.lifecycle = lifecycle;
|
|
357
|
-
lifecycle.cleanup(async () => {
|
|
358
|
-
try {
|
|
359
|
-
if (!this.ended) await this.iterator?.return?.();
|
|
360
|
-
} finally {
|
|
361
|
-
this.iterator = void 0;
|
|
362
|
-
this.releaseSnapshot();
|
|
363
|
-
lifecycle.budget.retain(-this.chunk.length);
|
|
364
|
-
this.chunk = new Uint8Array();
|
|
365
|
-
}
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
name;
|
|
369
|
-
lifecycle;
|
|
370
|
-
iterator;
|
|
371
|
-
chunk = new Uint8Array();
|
|
372
|
-
offset = 0;
|
|
373
|
-
pushed = -1;
|
|
374
|
-
ended = false;
|
|
375
|
-
empties = 0;
|
|
376
|
-
length = 0;
|
|
377
|
-
snapshotBytes = 0;
|
|
378
|
-
path;
|
|
379
|
-
stat;
|
|
380
|
-
releaseSnapshot = () => {
|
|
381
|
-
this.lifecycle.budget.retain(-this.snapshotBytes);
|
|
382
|
-
this.snapshotBytes = 0;
|
|
383
|
-
};
|
|
384
|
-
async open() {
|
|
385
|
-
if (this.name === "-") return;
|
|
386
|
-
const { budget } = this.lifecycle;
|
|
387
|
-
this.path = resolvePath(budget.context.cwd, pathText(this.name));
|
|
388
|
-
this.stat = await this.lifecycle.operation(() => {
|
|
389
|
-
const fs = budget.context.fs;
|
|
390
|
-
this.lifecycle.assertOpen();
|
|
391
|
-
const stat = fs.stat;
|
|
392
|
-
this.lifecycle.assertOpen();
|
|
393
|
-
return Reflect.apply(stat, fs, [this.path, { signal: budget.signal }]);
|
|
394
|
-
});
|
|
395
|
-
if (this.stat.type !== "file" && this.stat.type !== "directory" && this.stat.type !== "character") throw new FsError("ENOTSUP", { path: this.path });
|
|
396
|
-
}
|
|
397
|
-
async acquire() {
|
|
398
|
-
const { budget } = this.lifecycle;
|
|
399
|
-
await this.lifecycle.operation(async () => {
|
|
400
|
-
let source;
|
|
401
|
-
let needsAcquisitionCleanup = false;
|
|
402
|
-
if (this.path === void 0) source = budget.context.stdin;
|
|
403
|
-
else {
|
|
404
|
-
const fs = budget.context.fs;
|
|
405
|
-
this.lifecycle.assertOpen();
|
|
406
|
-
const capabilitiesFor = fs.capabilitiesFor;
|
|
407
|
-
this.lifecycle.assertOpen();
|
|
408
|
-
const selected = capabilitiesFor ? await Reflect.apply(capabilitiesFor, fs, [this.path, { signal: budget.signal }]) : void 0;
|
|
409
|
-
this.lifecycle.assertOpen();
|
|
410
|
-
const capabilities = selected ?? fs.capabilities;
|
|
411
|
-
this.lifecycle.assertOpen();
|
|
412
|
-
const readStream = fs.readStream;
|
|
413
|
-
this.lifecycle.assertOpen();
|
|
414
|
-
const streamingRead = readStream && capabilities.streamingRead !== false;
|
|
415
|
-
this.lifecycle.assertOpen();
|
|
416
|
-
if (readStream && streamingRead) {
|
|
417
|
-
source = Reflect.apply(readStream, fs, [this.path, { signal: budget.signal, chunkSize: 16384 }]);
|
|
418
|
-
needsAcquisitionCleanup = budget.signal.aborted;
|
|
419
|
-
} else {
|
|
420
|
-
const maximum = Math.min(budget.limits.maxInputBytes, Math.floor(budget.limits.maxBufferedBytes / 2));
|
|
421
|
-
budget.check(this.stat.size, maximum, "buffered input bytes");
|
|
422
|
-
const reserved = Number.isFinite(maximum) ? maximum : 0;
|
|
423
|
-
budget.retain(reserved);
|
|
424
|
-
this.snapshotBytes = reserved;
|
|
425
|
-
const readFile = fs.readFile;
|
|
426
|
-
this.lifecycle.assertOpen();
|
|
427
|
-
const content = await Reflect.apply(readFile, fs, [this.path, { signal: budget.signal, ...Number.isFinite(maximum) ? { maxBytes: maximum } : {} }]);
|
|
428
|
-
if (!(content instanceof Uint8Array)) throw new TypeError("pr input requires bytes");
|
|
429
|
-
budget.check(content.length, maximum, "buffered input bytes");
|
|
430
|
-
budget.retain(content.length - reserved);
|
|
431
|
-
this.snapshotBytes = content.length;
|
|
432
|
-
const { releaseSnapshot } = this;
|
|
433
|
-
source = { async *[Symbol.asyncIterator]() {
|
|
434
|
-
try {
|
|
435
|
-
yield content;
|
|
436
|
-
} finally {
|
|
437
|
-
releaseSnapshot();
|
|
438
|
-
}
|
|
439
|
-
} };
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
if (!needsAcquisitionCleanup) this.lifecycle.assertOpen();
|
|
443
|
-
const factory = source[Symbol.asyncIterator];
|
|
444
|
-
if (!needsAcquisitionCleanup) this.lifecycle.assertOpen();
|
|
445
|
-
this.iterator = Reflect.apply(factory, source, []);
|
|
446
|
-
});
|
|
447
|
-
}
|
|
448
|
-
initFromBytes(content) {
|
|
449
|
-
this.chunk = content;
|
|
450
|
-
this.offset = 0;
|
|
451
|
-
this.ended = true;
|
|
452
|
-
}
|
|
453
|
-
unget(value) {
|
|
454
|
-
this.pushed = value;
|
|
455
|
-
}
|
|
456
|
-
get() {
|
|
457
|
-
const { budget } = this.lifecycle;
|
|
458
|
-
budget.charge();
|
|
459
|
-
const cp = budget.checkpointWork();
|
|
460
|
-
if (!cp && this.stat?.type !== "directory") {
|
|
461
|
-
if (this.pushed >= 0) {
|
|
462
|
-
const value = this.pushed;
|
|
463
|
-
this.pushed = -1;
|
|
464
|
-
return value;
|
|
465
|
-
}
|
|
466
|
-
if (this.offset < this.chunk.length) {
|
|
467
|
-
const value = this.chunk[this.offset++];
|
|
468
|
-
if (value === 10 || value === 12) {
|
|
469
|
-
this.length = 0;
|
|
470
|
-
budget.line();
|
|
471
|
-
} else budget.check(++this.length, budget.limits.maxLineBytes, "input line bytes");
|
|
472
|
-
return value;
|
|
473
|
-
}
|
|
474
|
-
if (this.ended) {
|
|
475
|
-
if (this.length > 0) {
|
|
476
|
-
this.length = 0;
|
|
477
|
-
budget.line();
|
|
478
|
-
}
|
|
479
|
-
return -1;
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
return this.getSlow(cp);
|
|
483
|
-
}
|
|
484
|
-
async getSlow(cp) {
|
|
485
|
-
const { budget } = this.lifecycle;
|
|
486
|
-
if (cp) await cp;
|
|
487
|
-
if (this.stat?.type === "directory") throw new PrReadError(`${fileQuote(this.name)}: Is a directory`);
|
|
488
|
-
if (this.pushed >= 0) {
|
|
489
|
-
const value2 = this.pushed;
|
|
490
|
-
this.pushed = -1;
|
|
491
|
-
return value2;
|
|
492
|
-
}
|
|
493
|
-
while (this.offset === this.chunk.length) {
|
|
494
|
-
if (this.ended) return -1;
|
|
495
|
-
if (this.lifecycle.hasPendingStdout()) await this.lifecycle.flush();
|
|
496
|
-
let next;
|
|
497
|
-
try {
|
|
498
|
-
if (!this.iterator) await this.acquire();
|
|
499
|
-
next = await this.lifecycle.operation(() => {
|
|
500
|
-
const iterator = this.iterator;
|
|
501
|
-
const advance = iterator.next;
|
|
502
|
-
this.lifecycle.assertOpen();
|
|
503
|
-
return Reflect.apply(advance, iterator, []);
|
|
504
|
-
});
|
|
505
|
-
} catch (error) {
|
|
506
|
-
if (error instanceof FsError) throw new PrReadError(`${fileQuote(this.name === "-" ? "standard input" : this.name)}: ${fsDetail(error)}`);
|
|
507
|
-
throw error;
|
|
508
|
-
}
|
|
509
|
-
budget.retain(-this.chunk.length);
|
|
510
|
-
this.chunk = new Uint8Array();
|
|
511
|
-
this.offset = 0;
|
|
512
|
-
if (next.done) {
|
|
513
|
-
this.ended = true;
|
|
514
|
-
this.iterator = void 0;
|
|
515
|
-
if (this.length > 0) {
|
|
516
|
-
this.length = 0;
|
|
517
|
-
budget.line();
|
|
518
|
-
}
|
|
519
|
-
return -1;
|
|
520
|
-
}
|
|
521
|
-
if (!(next.value instanceof Uint8Array)) throw new TypeError("pr input requires bytes");
|
|
522
|
-
budget.inputBytes(next.value.length);
|
|
523
|
-
budget.retain(next.value.length);
|
|
524
|
-
this.chunk = Uint8Array.from(next.value);
|
|
525
|
-
if (!this.chunk.length) budget.check(++this.empties, budget.limits.maxEmptyChunks, "empty input chunks");
|
|
526
|
-
}
|
|
527
|
-
const value = this.chunk[this.offset++];
|
|
528
|
-
if (value === 10 || value === 12) {
|
|
529
|
-
this.length = 0;
|
|
530
|
-
budget.line();
|
|
531
|
-
} else budget.check(++this.length, budget.limits.maxLineBytes, "input line bytes");
|
|
532
|
-
return value;
|
|
533
|
-
}
|
|
534
|
-
};
|
|
535
|
-
function fsDetail(error) {
|
|
536
|
-
const details = {
|
|
537
|
-
EACCES: "Permission denied",
|
|
538
|
-
EPERM: "Operation not permitted",
|
|
539
|
-
ENOENT: "No such file or directory",
|
|
540
|
-
EISDIR: "Is a directory",
|
|
541
|
-
ENOTDIR: "Not a directory",
|
|
542
|
-
EIO: "Input/output error",
|
|
543
|
-
ELOOP: "Too many levels of symbolic links",
|
|
544
|
-
ENAMETOOLONG: "File name too long",
|
|
545
|
-
ENOTSUP: "Operation not supported"
|
|
546
|
-
};
|
|
547
|
-
return details[error.code] ?? error.message;
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
// packages/safe-bash-command-pr/src/options.ts
|
|
551
|
-
init_platform();
|
|
552
|
-
function digit(value) {
|
|
553
|
-
return value >= "0" && value <= "9";
|
|
554
|
-
}
|
|
555
|
-
function integer(value, minimum, label) {
|
|
556
|
-
let offset = 0;
|
|
557
|
-
while (" \r\n\v\f".includes(value[offset] ?? "!") && offset < value.length) offset++;
|
|
558
|
-
if (value[offset] === "+" || value[offset] === "-") offset++;
|
|
559
|
-
const start = offset;
|
|
560
|
-
while (offset < value.length && digit(value[offset])) offset++;
|
|
561
|
-
if (offset !== value.length || offset === start) throw new PrError(`${label}: ${quote(value)}`);
|
|
562
|
-
const result = Number(value);
|
|
563
|
-
if (result < minimum || result > 2147483647 || !Number.isSafeInteger(result)) throw new PrError(`${label}: ${quote(value)}: Numerical result out of range`);
|
|
564
|
-
return result;
|
|
565
|
-
}
|
|
566
|
-
function pages(value, options) {
|
|
567
|
-
const colon = value.indexOf(":");
|
|
568
|
-
options.firstPage = integer(colon < 0 ? value : value.slice(0, colon), 1, "invalid page range");
|
|
569
|
-
options.lastPage = colon < 0 ? 2147483647 : integer(value.slice(colon + 1), options.firstPage, "invalid page range");
|
|
570
|
-
}
|
|
571
|
-
function parseOptions(args, budget) {
|
|
572
|
-
const options = {
|
|
573
|
-
files: [],
|
|
574
|
-
columns: 1,
|
|
575
|
-
explicitColumns: false,
|
|
576
|
-
merge: false,
|
|
577
|
-
across: false,
|
|
578
|
-
length: 66,
|
|
579
|
-
firstPage: 1,
|
|
580
|
-
lastPage: 2147483647,
|
|
581
|
-
width: 72,
|
|
582
|
-
header: void 0,
|
|
583
|
-
dateFormat: void 0,
|
|
584
|
-
extremities: true,
|
|
585
|
-
keepFF: false,
|
|
586
|
-
formFeed: false,
|
|
587
|
-
numbered: false,
|
|
588
|
-
digits: 5,
|
|
589
|
-
numberSeparator: " ",
|
|
590
|
-
startNumber: 1,
|
|
591
|
-
separator: "",
|
|
592
|
-
useSeparator: false,
|
|
593
|
-
truncate: false,
|
|
594
|
-
join: false,
|
|
595
|
-
doubleSpace: false,
|
|
596
|
-
margin: 0,
|
|
597
|
-
expand: false,
|
|
598
|
-
tabify: false,
|
|
599
|
-
inputTab: " ",
|
|
600
|
-
inputTabWidth: 8,
|
|
601
|
-
outputTab: " ",
|
|
602
|
-
outputTabWidth: 8,
|
|
603
|
-
control: false,
|
|
604
|
-
octal: false,
|
|
605
|
-
quiet: false,
|
|
606
|
-
information: void 0
|
|
607
|
-
};
|
|
608
|
-
const long = {
|
|
609
|
-
"date-format": "\0",
|
|
610
|
-
columns: "#",
|
|
611
|
-
pages: "p",
|
|
612
|
-
across: "a",
|
|
613
|
-
"show-control-chars": "c",
|
|
614
|
-
"double-space": "d",
|
|
615
|
-
"expand-tabs": "e",
|
|
616
|
-
"form-feed": "f",
|
|
617
|
-
header: "h",
|
|
618
|
-
"output-tabs": "i",
|
|
619
|
-
"join-lines": "J",
|
|
620
|
-
length: "l",
|
|
621
|
-
merge: "m",
|
|
622
|
-
"number-lines": "n",
|
|
623
|
-
"first-line-number": "N",
|
|
624
|
-
indent: "o",
|
|
625
|
-
"no-file-warnings": "r",
|
|
626
|
-
separator: "s",
|
|
627
|
-
"sep-string": "S",
|
|
628
|
-
"omit-header": "t",
|
|
629
|
-
"omit-pagination": "T",
|
|
630
|
-
"show-nonprinting": "v",
|
|
631
|
-
width: "w",
|
|
632
|
-
"page-width": "W"
|
|
633
|
-
};
|
|
634
|
-
let oldWidth = false, oldSeparator = false, oldOptions = false, stop = false;
|
|
635
|
-
let columnDigits;
|
|
636
|
-
let accumulating = false;
|
|
637
|
-
for (let index = 0; index < args.length; index++) {
|
|
638
|
-
const argument = args[index];
|
|
639
|
-
budget.charge(argument.length);
|
|
640
|
-
if (stop) {
|
|
641
|
-
options.files.push(argument);
|
|
642
|
-
continue;
|
|
643
|
-
}
|
|
644
|
-
if (argument === "--") {
|
|
645
|
-
stop = true;
|
|
646
|
-
continue;
|
|
647
|
-
}
|
|
648
|
-
if (argument === "--help" || argument === "--version") {
|
|
649
|
-
options.information = argument === "--help" ? "help" : "version";
|
|
650
|
-
return options;
|
|
651
|
-
}
|
|
652
|
-
if (argument.startsWith("+") && digit(argument[1] ?? "")) {
|
|
653
|
-
accumulating = false;
|
|
654
|
-
pages(argument.slice(1), options);
|
|
655
|
-
continue;
|
|
656
|
-
}
|
|
657
|
-
if (!argument.startsWith("-") || argument === "-") {
|
|
658
|
-
accumulating = false;
|
|
659
|
-
options.files.push(argument);
|
|
660
|
-
continue;
|
|
661
|
-
}
|
|
662
|
-
const isLong = argument.startsWith("--");
|
|
663
|
-
let switches = argument.slice(1), attached;
|
|
664
|
-
if (isLong) {
|
|
665
|
-
const equal = argument.indexOf("=");
|
|
666
|
-
const name = argument.slice(2, equal < 0 ? void 0 : equal);
|
|
667
|
-
const candidates = Object.keys(long).filter((candidate) => candidate.startsWith(name));
|
|
668
|
-
if (!Object.hasOwn(long, name) && candidates.length > 1) throw new PrError(`option ${quote(argument)} is ambiguous; possibilities:${candidates.map((candidate) => ` '--${candidate}'`).join("")}`, true);
|
|
669
|
-
switches = long[name] ?? (candidates.length === 1 ? long[candidates[0]] : void 0) ?? "";
|
|
670
|
-
if (!switches) throw new PrError(`unrecognized option ${quote(argument)}`, true);
|
|
671
|
-
if (equal >= 0) attached = argument.slice(equal + 1);
|
|
672
|
-
}
|
|
673
|
-
for (let offset = 0; offset < switches.length; offset++) {
|
|
674
|
-
const option = switches[offset];
|
|
675
|
-
if (digit(option)) {
|
|
676
|
-
columnDigits = (accumulating ? columnDigits ?? "" : "") + option;
|
|
677
|
-
accumulating = true;
|
|
678
|
-
continue;
|
|
679
|
-
}
|
|
680
|
-
accumulating = false;
|
|
681
|
-
const required = "\0#phlwWNo".includes(option);
|
|
682
|
-
const optional = "nseiS".includes(option);
|
|
683
|
-
let value = attached;
|
|
684
|
-
if (required || optional) {
|
|
685
|
-
if (!isLong && offset + 1 < switches.length) value = switches.slice(offset + 1);
|
|
686
|
-
if (required && value === void 0) {
|
|
687
|
-
value = args[++index];
|
|
688
|
-
if (value === void 0) throw new PrError(isLong ? `option ${quote(argument)} requires an argument` : `option requires an argument -- '${option}'`, true);
|
|
689
|
-
}
|
|
690
|
-
offset = switches.length;
|
|
691
|
-
} else if (attached !== void 0) throw new PrError(`option ${quote(argument.slice(0, argument.indexOf("=")))} doesn't allow an argument`, true);
|
|
692
|
-
switch (option) {
|
|
693
|
-
case "p":
|
|
694
|
-
if (!isLong) throw new PrError("invalid option -- 'p'", true);
|
|
695
|
-
pages(value, options);
|
|
696
|
-
break;
|
|
697
|
-
case "\0":
|
|
698
|
-
options.dateFormat = value;
|
|
699
|
-
break;
|
|
700
|
-
case "#":
|
|
701
|
-
options.columns = integer(value, 1, "invalid number of columns");
|
|
702
|
-
options.explicitColumns = true;
|
|
703
|
-
columnDigits = void 0;
|
|
704
|
-
break;
|
|
705
|
-
case "h":
|
|
706
|
-
options.header = value;
|
|
707
|
-
break;
|
|
708
|
-
case "l":
|
|
709
|
-
options.length = integer(value, 1, "'-l PAGE_LENGTH' invalid number of lines");
|
|
710
|
-
break;
|
|
711
|
-
case "w":
|
|
712
|
-
oldWidth = true;
|
|
713
|
-
oldOptions = true;
|
|
714
|
-
{
|
|
715
|
-
const width = integer(value, 1, "'-w PAGE_WIDTH' invalid number of characters");
|
|
716
|
-
if (!options.truncate) options.width = width;
|
|
717
|
-
}
|
|
718
|
-
break;
|
|
719
|
-
case "W":
|
|
720
|
-
oldWidth = false;
|
|
721
|
-
options.truncate = true;
|
|
722
|
-
options.width = integer(value, 1, "'-W PAGE_WIDTH' invalid number of characters");
|
|
723
|
-
break;
|
|
724
|
-
case "m":
|
|
725
|
-
options.merge = true;
|
|
726
|
-
break;
|
|
727
|
-
case "a":
|
|
728
|
-
options.across = true;
|
|
729
|
-
break;
|
|
730
|
-
case "b":
|
|
731
|
-
break;
|
|
732
|
-
case "d":
|
|
733
|
-
options.doubleSpace = true;
|
|
734
|
-
break;
|
|
735
|
-
case "f":
|
|
736
|
-
case "F":
|
|
737
|
-
options.formFeed = true;
|
|
738
|
-
break;
|
|
739
|
-
case "J":
|
|
740
|
-
options.join = true;
|
|
741
|
-
break;
|
|
742
|
-
case "N":
|
|
743
|
-
options.startNumber = integer(value, -2147483648, "'-N NUMBER' invalid starting line number");
|
|
744
|
-
break;
|
|
745
|
-
case "o":
|
|
746
|
-
options.margin = integer(value, 0, "'-o MARGIN' invalid line offset");
|
|
747
|
-
break;
|
|
748
|
-
case "r":
|
|
749
|
-
options.quiet = true;
|
|
750
|
-
break;
|
|
751
|
-
case "s":
|
|
752
|
-
oldOptions = true;
|
|
753
|
-
oldSeparator = true;
|
|
754
|
-
if (!options.useSeparator && value !== void 0) options.separator = value;
|
|
755
|
-
break;
|
|
756
|
-
case "S":
|
|
757
|
-
oldSeparator = false;
|
|
758
|
-
options.useSeparator = true;
|
|
759
|
-
options.separator = value ?? "";
|
|
760
|
-
break;
|
|
761
|
-
case "t":
|
|
762
|
-
options.extremities = false;
|
|
763
|
-
options.keepFF = true;
|
|
764
|
-
break;
|
|
765
|
-
case "T":
|
|
766
|
-
options.extremities = false;
|
|
767
|
-
options.keepFF = false;
|
|
768
|
-
break;
|
|
769
|
-
case "c":
|
|
770
|
-
options.control = true;
|
|
771
|
-
break;
|
|
772
|
-
case "v":
|
|
773
|
-
options.octal = true;
|
|
774
|
-
break;
|
|
775
|
-
case "n":
|
|
776
|
-
case "e":
|
|
777
|
-
case "i": {
|
|
778
|
-
if (option === "n") options.numbered = true;
|
|
779
|
-
if (option === "e") options.expand = true;
|
|
780
|
-
if (option === "i") options.tabify = true;
|
|
781
|
-
if (value === void 0 || !value.length) break;
|
|
782
|
-
let character;
|
|
783
|
-
if (!digit(value[0])) {
|
|
784
|
-
character = value[0];
|
|
785
|
-
value = value.slice(1);
|
|
786
|
-
}
|
|
787
|
-
let count;
|
|
788
|
-
if (value.length) {
|
|
789
|
-
try {
|
|
790
|
-
count = integer(value, 1, "invalid number");
|
|
791
|
-
} catch {
|
|
792
|
-
throw new PrError(`'-${option}' extra characters or invalid number in the argument: ${quote(value)}${Number(value) > 2147483647 ? ": Value too large for defined data type" : ""}`, true);
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
if (option === "n") {
|
|
796
|
-
options.numberSeparator = character ?? options.numberSeparator;
|
|
797
|
-
options.digits = count ?? options.digits;
|
|
798
|
-
}
|
|
799
|
-
if (option === "e") {
|
|
800
|
-
options.inputTab = character ?? options.inputTab;
|
|
801
|
-
options.inputTabWidth = count ?? options.inputTabWidth;
|
|
802
|
-
}
|
|
803
|
-
if (option === "i") {
|
|
804
|
-
options.outputTab = character ?? options.outputTab;
|
|
805
|
-
options.outputTabWidth = count ?? options.outputTabWidth;
|
|
806
|
-
}
|
|
807
|
-
break;
|
|
808
|
-
}
|
|
809
|
-
default:
|
|
810
|
-
throw new PrError(`invalid option -- '${option}'`, true);
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
if (columnDigits !== void 0) {
|
|
815
|
-
options.columns = integer(columnDigits, 1, "invalid number of columns");
|
|
816
|
-
options.explicitColumns = true;
|
|
817
|
-
}
|
|
818
|
-
if (options.merge && options.explicitColumns) throw new PrError("cannot specify number of columns when printing in parallel");
|
|
819
|
-
if (options.merge && options.across) throw new PrError("cannot specify both printing across and printing in parallel");
|
|
820
|
-
if (oldOptions) {
|
|
821
|
-
if (oldWidth) {
|
|
822
|
-
if (options.merge || options.explicitColumns) {
|
|
823
|
-
options.truncate = true;
|
|
824
|
-
if (oldSeparator) options.useSeparator = true;
|
|
825
|
-
} else options.join = true;
|
|
826
|
-
} else if (!options.useSeparator && oldSeparator && (options.merge || options.explicitColumns)) {
|
|
827
|
-
if (!options.truncate) {
|
|
828
|
-
options.join = true;
|
|
829
|
-
if (options.separator.length) options.useSeparator = true;
|
|
830
|
-
} else options.useSeparator = true;
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
const { limits } = budget;
|
|
834
|
-
budget.check(options.files.length, limits.maxFiles, "input files");
|
|
835
|
-
budget.check(options.merge ? Math.max(1, options.files.length) : options.columns, limits.maxColumns, "columns");
|
|
836
|
-
budget.check(options.length, limits.maxPageLines, "page lines");
|
|
837
|
-
for (const width of [options.width, options.margin, options.digits, options.inputTabWidth, options.outputTabWidth]) budget.check(width, limits.maxPageWidth, "page width");
|
|
838
|
-
return options;
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
// packages/safe-bash-command-pr/src/format.ts
|
|
842
|
-
init_platform();
|
|
843
|
-
var Formatter = class {
|
|
844
|
-
constructor(options, lifecycle, count) {
|
|
845
|
-
this.options = options;
|
|
846
|
-
this.lifecycle = lifecycle;
|
|
847
|
-
this.budget = lifecycle.budget;
|
|
848
|
-
if (options.length <= 10) {
|
|
849
|
-
options.extremities = false;
|
|
850
|
-
options.keepFF = true;
|
|
851
|
-
}
|
|
852
|
-
this.body = Math.floor((options.extremities ? options.length - 10 : options.length) / (options.doubleSpace ? 2 : 1));
|
|
853
|
-
if (this.body < 1) throw new PrError("page has no text lines");
|
|
854
|
-
options.columns = options.merge ? count : options.columns;
|
|
855
|
-
if (options.columns > 1) {
|
|
856
|
-
if (!options.useSeparator) {
|
|
857
|
-
options.useSeparator = true;
|
|
858
|
-
options.separator = options.join ? " " : " ";
|
|
859
|
-
} else if (!options.join && options.separator === " ") options.separator = " ";
|
|
860
|
-
options.truncate = true;
|
|
861
|
-
options.expand = true;
|
|
862
|
-
options.tabify = true;
|
|
863
|
-
}
|
|
864
|
-
if (options.join) options.truncate = false;
|
|
865
|
-
this.numberWidth = options.numberSeparator === " " ? options.digits + 8 - options.digits % 8 : options.digits + 1;
|
|
866
|
-
this.columnWidth = Math.trunc((options.width - (options.merge && options.numbered ? this.numberWidth : 0) - (options.columns - 1) * options.separator.length) / options.columns);
|
|
867
|
-
if (this.columnWidth < 1) throw new PrError("page width too narrow");
|
|
868
|
-
this.store = options.columns > 1 && !options.merge && !options.across;
|
|
869
|
-
this.lineNumber = options.startNumber;
|
|
870
|
-
lifecycle.cleanup(async () => {
|
|
871
|
-
this.budget.retain(-this.pageRetained - this.rendered.length * 2);
|
|
872
|
-
this.pageRetained = 0;
|
|
873
|
-
this.rendered = "";
|
|
874
|
-
this.columns = [];
|
|
875
|
-
});
|
|
876
|
-
}
|
|
877
|
-
options;
|
|
878
|
-
lifecycle;
|
|
879
|
-
budget;
|
|
880
|
-
body;
|
|
881
|
-
columnWidth;
|
|
882
|
-
numberWidth;
|
|
883
|
-
store;
|
|
884
|
-
columns = [];
|
|
885
|
-
lineNumber;
|
|
886
|
-
pageNumber = 1;
|
|
887
|
-
inputPosition = 0;
|
|
888
|
-
outputPosition = 0;
|
|
889
|
-
spaces = 0;
|
|
890
|
-
separators = 0;
|
|
891
|
-
padding = 0;
|
|
892
|
-
vertical = false;
|
|
893
|
-
empty = true;
|
|
894
|
-
alignEmpty = false;
|
|
895
|
-
feedOnly = false;
|
|
896
|
-
printFeed = false;
|
|
897
|
-
needHeader = false;
|
|
898
|
-
storing = false;
|
|
899
|
-
stored = "";
|
|
900
|
-
rendered = "";
|
|
901
|
-
pageRetained = 0;
|
|
902
|
-
append(value) {
|
|
903
|
-
this.budget.charge(value.length);
|
|
904
|
-
if (this.pageNumber < this.options.firstPage) return;
|
|
905
|
-
this.budget.admitOutput(this.rendered.length + value.length);
|
|
906
|
-
this.budget.retain(value.length * 2);
|
|
907
|
-
this.rendered += value;
|
|
908
|
-
}
|
|
909
|
-
repeat(value, count, construction = false) {
|
|
910
|
-
this.budget.admitString(value.length * count);
|
|
911
|
-
if (!construction && this.pageNumber >= this.options.firstPage) this.budget.admitOutput(this.rendered.length + value.length * count);
|
|
912
|
-
if (construction) this.budget.charge(value.length * count);
|
|
913
|
-
return value.repeat(count);
|
|
914
|
-
}
|
|
915
|
-
async flush() {
|
|
916
|
-
const p = this.flushSyncOrAsync();
|
|
917
|
-
if (p) await p;
|
|
918
|
-
}
|
|
919
|
-
flushSyncOrAsync() {
|
|
920
|
-
const text = this.rendered;
|
|
921
|
-
if (!text) return;
|
|
922
|
-
this.rendered = "";
|
|
923
|
-
this.budget.retain(-text.length * 2);
|
|
924
|
-
return this.lifecycle.writeSyncOrAsync(text);
|
|
925
|
-
}
|
|
926
|
-
white() {
|
|
927
|
-
let position = this.outputPosition;
|
|
928
|
-
const goal = position + this.spaces;
|
|
929
|
-
this.budget.check(Math.max(0, this.spaces), this.budget.limits.maxBufferedBytes, "horizontal padding");
|
|
930
|
-
while (goal - position > 1) {
|
|
931
|
-
const next = position + this.options.outputTabWidth - position % this.options.outputTabWidth;
|
|
932
|
-
if (next > goal) break;
|
|
933
|
-
this.append(this.options.outputTab);
|
|
934
|
-
position = next;
|
|
935
|
-
}
|
|
936
|
-
if (goal > position) this.append(this.repeat(" ", goal - position));
|
|
937
|
-
this.outputPosition = goal;
|
|
938
|
-
this.spaces = 0;
|
|
939
|
-
}
|
|
940
|
-
pad(position) {
|
|
941
|
-
if (this.options.tabify) this.spaces = position - this.outputPosition;
|
|
942
|
-
else {
|
|
943
|
-
if (position > this.outputPosition) this.append(this.repeat(" ", position - this.outputPosition));
|
|
944
|
-
this.outputPosition = position;
|
|
945
|
-
}
|
|
946
|
-
}
|
|
947
|
-
separator() {
|
|
948
|
-
if (this.separators <= 0) {
|
|
949
|
-
if (this.spaces > 0) this.white();
|
|
950
|
-
return;
|
|
951
|
-
}
|
|
952
|
-
let offset = 0;
|
|
953
|
-
for (; this.separators > 0; this.separators--) {
|
|
954
|
-
while (offset < this.options.separator.length) {
|
|
955
|
-
const character = this.options.separator[offset++];
|
|
956
|
-
if (character === " ") this.spaces++;
|
|
957
|
-
else {
|
|
958
|
-
if (this.spaces > 0) this.white();
|
|
959
|
-
this.append(character);
|
|
960
|
-
this.outputPosition++;
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
if (this.spaces > 0) this.white();
|
|
964
|
-
}
|
|
965
|
-
}
|
|
966
|
-
character(character) {
|
|
967
|
-
if (this.storing) {
|
|
968
|
-
this.budget.charge(character.length);
|
|
969
|
-
this.budget.retain(character.length * 2);
|
|
970
|
-
this.pageRetained += character.length * 2;
|
|
971
|
-
this.stored += character;
|
|
972
|
-
return;
|
|
973
|
-
}
|
|
974
|
-
if (this.options.tabify) {
|
|
975
|
-
if (character === " ") {
|
|
976
|
-
this.spaces++;
|
|
977
|
-
return;
|
|
978
|
-
}
|
|
979
|
-
if (this.spaces > 0) this.white();
|
|
980
|
-
if (character >= " " && character <= "~") this.outputPosition++;
|
|
981
|
-
else if (character === "\b") this.outputPosition--;
|
|
982
|
-
}
|
|
983
|
-
this.append(character);
|
|
984
|
-
}
|
|
985
|
-
number(column) {
|
|
986
|
-
this.budget.admitString(this.options.digits);
|
|
987
|
-
const text = String(this.lineNumber++).padStart(this.options.digits, " ").slice(-this.options.digits);
|
|
988
|
-
for (const character of text) this.character(character);
|
|
989
|
-
if (this.columns.length > 1 && this.options.numberSeparator === " ") {
|
|
990
|
-
for (let count = this.numberWidth - this.options.digits; count > 0; count--) this.character(" ");
|
|
991
|
-
} else {
|
|
992
|
-
this.character(this.options.numberSeparator);
|
|
993
|
-
if (this.columns.length === 1 && this.options.numberSeparator === " ") this.outputPosition += this.options.outputTabWidth - this.outputPosition % this.options.outputTabWidth;
|
|
994
|
-
}
|
|
995
|
-
if (this.options.truncate && !this.options.merge) this.inputPosition += this.numberWidth;
|
|
996
|
-
this.budget.charge(column.numbered ? 1 : 0);
|
|
997
|
-
}
|
|
998
|
-
align(column) {
|
|
999
|
-
this.padding = column.start;
|
|
1000
|
-
if (this.options.separator.length < this.padding) {
|
|
1001
|
-
this.pad(this.padding - this.options.separator.length);
|
|
1002
|
-
this.padding = 0;
|
|
1003
|
-
}
|
|
1004
|
-
if (this.options.useSeparator) this.separator();
|
|
1005
|
-
if (column.numbered) this.number(column);
|
|
1006
|
-
}
|
|
1007
|
-
clump(byte) {
|
|
1008
|
-
const character = String.fromCharCode(byte);
|
|
1009
|
-
let width;
|
|
1010
|
-
let text = character;
|
|
1011
|
-
if (character === this.options.inputTab || byte === 9) {
|
|
1012
|
-
const tab = character === this.options.inputTab ? this.options.inputTabWidth : 8;
|
|
1013
|
-
width = tab - this.inputPosition % tab;
|
|
1014
|
-
if (this.options.expand) text = this.repeat(" ", width, true);
|
|
1015
|
-
} else if (byte < 32 || byte > 126) {
|
|
1016
|
-
if (this.options.octal || this.options.control && byte >= 128) {
|
|
1017
|
-
text = `\\${byte.toString(8).padStart(3, "0")}`;
|
|
1018
|
-
width = 4;
|
|
1019
|
-
} else if (this.options.control) {
|
|
1020
|
-
text = `^${String.fromCharCode(byte ^ 64)}`;
|
|
1021
|
-
width = 2;
|
|
1022
|
-
} else width = byte === 8 ? -1 : 0;
|
|
1023
|
-
} else width = 1;
|
|
1024
|
-
if (width < 0 && this.inputPosition === 0) return "";
|
|
1025
|
-
this.inputPosition = Math.max(0, this.inputPosition + width);
|
|
1026
|
-
return text;
|
|
1027
|
-
}
|
|
1028
|
-
close(column) {
|
|
1029
|
-
for (const current of this.options.merge ? [column] : this.columns) {
|
|
1030
|
-
current.status = "closed";
|
|
1031
|
-
if (!current.lines.length) current.remaining = 0;
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
hold(column) {
|
|
1035
|
-
for (const current of this.options.merge ? [column] : this.columns) current.status = this.store ? "feed" : "held";
|
|
1036
|
-
column.remaining = 0;
|
|
1037
|
-
}
|
|
1038
|
-
async feed(column) {
|
|
1039
|
-
const r = column.reader.get();
|
|
1040
|
-
const next = typeof r === "number" ? r : await r;
|
|
1041
|
-
if (next !== 10) column.reader.unget(next);
|
|
1042
|
-
this.hold(column);
|
|
1043
|
-
}
|
|
1044
|
-
async rest(column) {
|
|
1045
|
-
const p = this.restSyncOrAsync(column);
|
|
1046
|
-
if (p) await p;
|
|
1047
|
-
}
|
|
1048
|
-
restSyncOrAsync(column) {
|
|
1049
|
-
for (; ; ) {
|
|
1050
|
-
const r = column.reader.get();
|
|
1051
|
-
if (typeof r !== "number") return this.restSlow(column, r);
|
|
1052
|
-
if (r === 10) return;
|
|
1053
|
-
if (r === 12) return this.feed(column).then(() => {
|
|
1054
|
-
if (this.options.keepFF) this.printFeed = true;
|
|
1055
|
-
});
|
|
1056
|
-
if (r < 0) {
|
|
1057
|
-
this.close(column);
|
|
1058
|
-
return;
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1062
|
-
async restSlow(column, firstPending) {
|
|
1063
|
-
const firstByte = await firstPending;
|
|
1064
|
-
if (firstByte === 10) return;
|
|
1065
|
-
if (firstByte === 12) {
|
|
1066
|
-
await this.feed(column);
|
|
1067
|
-
if (this.options.keepFF) this.printFeed = true;
|
|
1068
|
-
return;
|
|
1069
|
-
}
|
|
1070
|
-
if (firstByte < 0) {
|
|
1071
|
-
this.close(column);
|
|
1072
|
-
return;
|
|
1073
|
-
}
|
|
1074
|
-
for (; ; ) {
|
|
1075
|
-
const r = column.reader.get();
|
|
1076
|
-
const byte = typeof r === "number" ? r : await r;
|
|
1077
|
-
if (byte === 10) return;
|
|
1078
|
-
if (byte === 12) {
|
|
1079
|
-
await this.feed(column);
|
|
1080
|
-
if (this.options.keepFF) this.printFeed = true;
|
|
1081
|
-
return;
|
|
1082
|
-
}
|
|
1083
|
-
if (byte < 0) {
|
|
1084
|
-
this.close(column);
|
|
1085
|
-
return;
|
|
1086
|
-
}
|
|
1087
|
-
}
|
|
1088
|
-
}
|
|
1089
|
-
header(date, name) {
|
|
1090
|
-
const { env } = this.budget.context;
|
|
1091
|
-
if (![void 0, "", "UTC", "UTC0", ":UTC", "GMT", "GMT0"].includes(env.TZ)) throw new PrError("only UTC timezones are supported for headers");
|
|
1092
|
-
const ctype = env.LC_ALL || env.LC_CTYPE || env.LANG || "C";
|
|
1093
|
-
if (ctype === "C.UTF-8" || ctype === "C.utf8") {
|
|
1094
|
-
for (const character of name) if (character.charCodeAt(0) >= 128) throw new PrError("non-ASCII headers require the C locale");
|
|
1095
|
-
}
|
|
1096
|
-
this.outputPosition = 0;
|
|
1097
|
-
this.pad(this.options.margin);
|
|
1098
|
-
this.white();
|
|
1099
|
-
const width = (text) => {
|
|
1100
|
-
this.budget.charge(text.length);
|
|
1101
|
-
let result = 0;
|
|
1102
|
-
for (const character of text) if (character >= " " && character !== "\x7F") result++;
|
|
1103
|
-
return result;
|
|
1104
|
-
};
|
|
1105
|
-
const page = `Page ${this.pageNumber}`;
|
|
1106
|
-
const available = Math.max(0, this.options.width - width(date) - width(name) - width(page));
|
|
1107
|
-
const left = Math.floor(available / 2);
|
|
1108
|
-
const length = 5 + this.options.margin + date.length + name.length + page.length + Math.max(1, left) + Math.max(1, available - left);
|
|
1109
|
-
this.budget.admitString(length);
|
|
1110
|
-
if (this.pageNumber >= this.options.firstPage) this.budget.admitOutput(this.rendered.length + length);
|
|
1111
|
-
this.append(`
|
|
1112
|
-
|
|
1113
|
-
${this.repeat(" ", this.options.margin)}${date}${this.repeat(" ", Math.max(1, left))}${name}${this.repeat(" ", Math.max(1, available - left))}${page}
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
`);
|
|
1117
|
-
this.needHeader = false;
|
|
1118
|
-
this.outputPosition = 0;
|
|
1119
|
-
}
|
|
1120
|
-
async read(column, date, name) {
|
|
1121
|
-
const p = this.readSyncOrAsync(column, date, name);
|
|
1122
|
-
if (p) await p;
|
|
1123
|
-
}
|
|
1124
|
-
readSyncOrAsync(column, date, name) {
|
|
1125
|
-
const r0 = column.reader.get();
|
|
1126
|
-
if (typeof r0 === "number" && r0 !== 12) {
|
|
1127
|
-
column.full = false;
|
|
1128
|
-
if (r0 < 0) {
|
|
1129
|
-
this.close(column);
|
|
1130
|
-
return;
|
|
1131
|
-
}
|
|
1132
|
-
let clump = r0 === 10 ? "" : this.clump(r0);
|
|
1133
|
-
if (this.options.truncate && this.inputPosition > this.columnWidth) {
|
|
1134
|
-
this.inputPosition = 0;
|
|
1135
|
-
return this.restSyncOrAsync(column);
|
|
1136
|
-
}
|
|
1137
|
-
if (!this.storing) {
|
|
1138
|
-
this.vertical = true;
|
|
1139
|
-
if (this.needHeader && !this.store) this.header(date, name);
|
|
1140
|
-
if (this.options.merge && this.alignEmpty) {
|
|
1141
|
-
const pending = this.separators;
|
|
1142
|
-
this.separators = 0;
|
|
1143
|
-
for (let index = 0; index < pending; index++) {
|
|
1144
|
-
this.align(this.columns[index]);
|
|
1145
|
-
this.separators++;
|
|
1146
|
-
}
|
|
1147
|
-
this.padding = column.start;
|
|
1148
|
-
this.spaces = this.options.truncate ? this.columnWidth : 0;
|
|
1149
|
-
this.alignEmpty = false;
|
|
1150
|
-
}
|
|
1151
|
-
if (this.options.separator.length < this.padding) {
|
|
1152
|
-
this.pad(this.padding - this.options.separator.length);
|
|
1153
|
-
this.padding = 0;
|
|
1154
|
-
}
|
|
1155
|
-
if (this.options.useSeparator) this.separator();
|
|
1156
|
-
}
|
|
1157
|
-
if (column.numbered) this.number(column);
|
|
1158
|
-
this.empty = false;
|
|
1159
|
-
if (r0 === 10) return;
|
|
1160
|
-
for (let i = 0; i < clump.length; i++) this.character(clump[i]);
|
|
1161
|
-
for (; ; ) {
|
|
1162
|
-
const rn = column.reader.get();
|
|
1163
|
-
if (typeof rn !== "number") return this.readRemainderSlow(column, rn);
|
|
1164
|
-
if (rn === 10) return;
|
|
1165
|
-
if (rn === 12) return this.feed(column).then(() => {
|
|
1166
|
-
if (this.options.keepFF) this.printFeed = true;
|
|
1167
|
-
});
|
|
1168
|
-
if (rn < 0) {
|
|
1169
|
-
this.close(column);
|
|
1170
|
-
return;
|
|
1171
|
-
}
|
|
1172
|
-
const previous = this.inputPosition;
|
|
1173
|
-
clump = this.clump(rn);
|
|
1174
|
-
if (this.options.truncate && this.inputPosition > this.columnWidth) {
|
|
1175
|
-
this.inputPosition = previous;
|
|
1176
|
-
return this.restSyncOrAsync(column);
|
|
1177
|
-
}
|
|
1178
|
-
for (let i = 0; i < clump.length; i++) this.character(clump[i]);
|
|
1179
|
-
}
|
|
1180
|
-
}
|
|
1181
|
-
return this.readSlow(column, date, name, r0);
|
|
1182
|
-
}
|
|
1183
|
-
async readRemainderSlow(column, firstPending) {
|
|
1184
|
-
let byte = await firstPending;
|
|
1185
|
-
for (; ; ) {
|
|
1186
|
-
if (byte === 10) return;
|
|
1187
|
-
if (byte === 12) {
|
|
1188
|
-
await this.feed(column);
|
|
1189
|
-
if (this.options.keepFF) this.printFeed = true;
|
|
1190
|
-
return;
|
|
1191
|
-
}
|
|
1192
|
-
if (byte < 0) {
|
|
1193
|
-
this.close(column);
|
|
1194
|
-
return;
|
|
1195
|
-
}
|
|
1196
|
-
const previous = this.inputPosition;
|
|
1197
|
-
const clump = this.clump(byte);
|
|
1198
|
-
if (this.options.truncate && this.inputPosition > this.columnWidth) {
|
|
1199
|
-
this.inputPosition = previous;
|
|
1200
|
-
await this.rest(column);
|
|
1201
|
-
return;
|
|
1202
|
-
}
|
|
1203
|
-
for (let i = 0; i < clump.length; i++) this.character(clump[i]);
|
|
1204
|
-
const rn = column.reader.get();
|
|
1205
|
-
byte = typeof rn === "number" ? rn : await rn;
|
|
1206
|
-
}
|
|
1207
|
-
}
|
|
1208
|
-
async readSlow(column, date, name, r0) {
|
|
1209
|
-
let byte = typeof r0 === "number" ? r0 : await r0;
|
|
1210
|
-
if (byte === 12 && column.full) {
|
|
1211
|
-
const r1 = column.reader.get();
|
|
1212
|
-
byte = typeof r1 === "number" ? r1 : await r1;
|
|
1213
|
-
if (byte === 10) {
|
|
1214
|
-
const r2 = column.reader.get();
|
|
1215
|
-
byte = typeof r2 === "number" ? r2 : await r2;
|
|
1216
|
-
}
|
|
1217
|
-
}
|
|
1218
|
-
column.full = false;
|
|
1219
|
-
if (byte === 12) {
|
|
1220
|
-
await this.feed(column);
|
|
1221
|
-
this.feedOnly = true;
|
|
1222
|
-
if (this.needHeader && !this.store) {
|
|
1223
|
-
this.vertical = true;
|
|
1224
|
-
this.header(date, name);
|
|
1225
|
-
} else if (this.options.keepFF) this.printFeed = true;
|
|
1226
|
-
return;
|
|
1227
|
-
}
|
|
1228
|
-
if (byte < 0) {
|
|
1229
|
-
this.close(column);
|
|
1230
|
-
return;
|
|
1231
|
-
}
|
|
1232
|
-
let clump = byte === 10 ? "" : this.clump(byte);
|
|
1233
|
-
if (this.options.truncate && this.inputPosition > this.columnWidth) {
|
|
1234
|
-
this.inputPosition = 0;
|
|
1235
|
-
await this.rest(column);
|
|
1236
|
-
return;
|
|
1237
|
-
}
|
|
1238
|
-
if (!this.storing) {
|
|
1239
|
-
this.vertical = true;
|
|
1240
|
-
if (this.needHeader && !this.store) this.header(date, name);
|
|
1241
|
-
if (this.options.merge && this.alignEmpty) {
|
|
1242
|
-
const pending = this.separators;
|
|
1243
|
-
this.separators = 0;
|
|
1244
|
-
for (let index = 0; index < pending; index++) {
|
|
1245
|
-
this.align(this.columns[index]);
|
|
1246
|
-
this.separators++;
|
|
1247
|
-
}
|
|
1248
|
-
this.padding = column.start;
|
|
1249
|
-
this.spaces = this.options.truncate ? this.columnWidth : 0;
|
|
1250
|
-
this.alignEmpty = false;
|
|
1251
|
-
}
|
|
1252
|
-
if (this.options.separator.length < this.padding) {
|
|
1253
|
-
this.pad(this.padding - this.options.separator.length);
|
|
1254
|
-
this.padding = 0;
|
|
1255
|
-
}
|
|
1256
|
-
if (this.options.useSeparator) this.separator();
|
|
1257
|
-
}
|
|
1258
|
-
if (column.numbered) this.number(column);
|
|
1259
|
-
this.empty = false;
|
|
1260
|
-
if (byte === 10) return;
|
|
1261
|
-
for (const character of clump) this.character(character);
|
|
1262
|
-
for (; ; ) {
|
|
1263
|
-
const rn = column.reader.get();
|
|
1264
|
-
byte = typeof rn === "number" ? rn : await rn;
|
|
1265
|
-
if (byte === 10) return;
|
|
1266
|
-
if (byte === 12) {
|
|
1267
|
-
await this.feed(column);
|
|
1268
|
-
if (this.options.keepFF) this.printFeed = true;
|
|
1269
|
-
return;
|
|
1270
|
-
}
|
|
1271
|
-
if (byte < 0) {
|
|
1272
|
-
this.close(column);
|
|
1273
|
-
return;
|
|
1274
|
-
}
|
|
1275
|
-
const previous = this.inputPosition;
|
|
1276
|
-
clump = this.clump(byte);
|
|
1277
|
-
if (this.options.truncate && this.inputPosition > this.columnWidth) {
|
|
1278
|
-
this.inputPosition = previous;
|
|
1279
|
-
await this.rest(column);
|
|
1280
|
-
return;
|
|
1281
|
-
}
|
|
1282
|
-
for (const character of clump) this.character(character);
|
|
1283
|
-
}
|
|
1284
|
-
}
|
|
1285
|
-
ready() {
|
|
1286
|
-
return this.columns.some((column) => column.status === "open" || column.status === "feed" || this.store && column.remaining > 0 && column.lines.length > 0);
|
|
1287
|
-
}
|
|
1288
|
-
async storePage(date, name) {
|
|
1289
|
-
this.budget.retain(-this.pageRetained);
|
|
1290
|
-
this.pageRetained = 0;
|
|
1291
|
-
const lines = [];
|
|
1292
|
-
this.storing = true;
|
|
1293
|
-
for (const column of this.columns) {
|
|
1294
|
-
column.lines = [];
|
|
1295
|
-
column.current = 0;
|
|
1296
|
-
}
|
|
1297
|
-
try {
|
|
1298
|
-
for (const column of this.columns) {
|
|
1299
|
-
for (let count = 0; count < this.body && column.status === "open"; count++) {
|
|
1300
|
-
this.stored = "";
|
|
1301
|
-
this.inputPosition = 0;
|
|
1302
|
-
const rp = this.readSyncOrAsync(column, date, name);
|
|
1303
|
-
if (rp) await rp;
|
|
1304
|
-
if (column.status === "open" || this.stored.length) {
|
|
1305
|
-
this.budget.retain(32);
|
|
1306
|
-
this.pageRetained += 32;
|
|
1307
|
-
lines.push({ text: this.stored, end: this.inputPosition });
|
|
1308
|
-
}
|
|
1309
|
-
}
|
|
1310
|
-
}
|
|
1311
|
-
} finally {
|
|
1312
|
-
this.storing = false;
|
|
1313
|
-
}
|
|
1314
|
-
let start = 0;
|
|
1315
|
-
for (let index = 0; index < this.columns.length; index++) {
|
|
1316
|
-
const column = this.columns[index];
|
|
1317
|
-
const count = Math.floor(lines.length / this.columns.length) + (index < lines.length % this.columns.length ? 1 : 0);
|
|
1318
|
-
column.lines = lines.slice(start, start + count);
|
|
1319
|
-
column.remaining = count;
|
|
1320
|
-
start += count;
|
|
1321
|
-
}
|
|
1322
|
-
}
|
|
1323
|
-
storedLine(column, date, name) {
|
|
1324
|
-
this.vertical = true;
|
|
1325
|
-
if (this.needHeader) this.header(date, name);
|
|
1326
|
-
if (column.status === "feed") {
|
|
1327
|
-
for (const current of this.columns) current.status = "held";
|
|
1328
|
-
if (this.columns[0].remaining <= 0) {
|
|
1329
|
-
if (!this.options.extremities) this.vertical = false;
|
|
1330
|
-
return;
|
|
1331
|
-
}
|
|
1332
|
-
}
|
|
1333
|
-
const line = column.lines[column.current++];
|
|
1334
|
-
if (!line) return;
|
|
1335
|
-
if (this.options.separator.length < this.padding) {
|
|
1336
|
-
this.pad(this.padding - this.options.separator.length);
|
|
1337
|
-
this.padding = 0;
|
|
1338
|
-
}
|
|
1339
|
-
if (this.options.useSeparator) this.separator();
|
|
1340
|
-
for (const character of line.text) this.character(character);
|
|
1341
|
-
if (this.spaces === 0) {
|
|
1342
|
-
this.outputPosition = column.start + line.end;
|
|
1343
|
-
if (column.start - this.options.separator.length === this.options.margin) this.outputPosition -= this.options.separator.length;
|
|
1344
|
-
}
|
|
1345
|
-
}
|
|
1346
|
-
runSync(readers, date, name) {
|
|
1347
|
-
const count = this.options.merge ? readers.length : this.options.columns;
|
|
1348
|
-
for (let index = 0; index < count; index++) {
|
|
1349
|
-
const start = index === 0 ? this.options.margin + this.options.separator.length : this.options.truncate ? this.options.margin + index * (this.columnWidth + this.options.separator.length) + (this.options.merge && this.options.numbered ? this.numberWidth : 0) : 0;
|
|
1350
|
-
this.columns.push({
|
|
1351
|
-
reader: readers[this.options.merge ? index : 0],
|
|
1352
|
-
status: "open",
|
|
1353
|
-
full: false,
|
|
1354
|
-
numbered: this.options.numbered && (!this.options.merge || index === 0),
|
|
1355
|
-
start,
|
|
1356
|
-
lines: [],
|
|
1357
|
-
current: 0,
|
|
1358
|
-
remaining: 0
|
|
1359
|
-
});
|
|
1360
|
-
}
|
|
1361
|
-
while (this.pageNumber <= this.options.lastPage) {
|
|
1362
|
-
if (this.store) {
|
|
1363
|
-
this.budget.retain(-this.pageRetained);
|
|
1364
|
-
this.pageRetained = 0;
|
|
1365
|
-
const lines = [];
|
|
1366
|
-
this.storing = true;
|
|
1367
|
-
for (const column of this.columns) {
|
|
1368
|
-
column.lines = [];
|
|
1369
|
-
column.current = 0;
|
|
1370
|
-
}
|
|
1371
|
-
try {
|
|
1372
|
-
for (const column of this.columns) {
|
|
1373
|
-
for (let c = 0; c < this.body && column.status === "open"; c++) {
|
|
1374
|
-
this.stored = "";
|
|
1375
|
-
this.inputPosition = 0;
|
|
1376
|
-
const rp = this.readSyncOrAsync(column, date, name);
|
|
1377
|
-
if (rp) return false;
|
|
1378
|
-
if (column.status === "open" || this.stored.length) {
|
|
1379
|
-
this.budget.retain(32);
|
|
1380
|
-
this.pageRetained += 32;
|
|
1381
|
-
lines.push({ text: this.stored, end: this.inputPosition });
|
|
1382
|
-
}
|
|
1383
|
-
}
|
|
1384
|
-
}
|
|
1385
|
-
} finally {
|
|
1386
|
-
this.storing = false;
|
|
1387
|
-
}
|
|
1388
|
-
let start = 0;
|
|
1389
|
-
for (let index = 0; index < this.columns.length; index++) {
|
|
1390
|
-
const column = this.columns[index];
|
|
1391
|
-
const cnt = Math.floor(lines.length / this.columns.length) + (index < lines.length % this.columns.length ? 1 : 0);
|
|
1392
|
-
column.lines = lines.slice(start, start + cnt);
|
|
1393
|
-
column.remaining = cnt;
|
|
1394
|
-
start += cnt;
|
|
1395
|
-
}
|
|
1396
|
-
} else {
|
|
1397
|
-
for (const column of this.columns) column.remaining = column.status === "open" ? this.body : 0;
|
|
1398
|
-
}
|
|
1399
|
-
if (!this.ready()) break;
|
|
1400
|
-
this.budget.page();
|
|
1401
|
-
this.needHeader = this.options.extremities;
|
|
1402
|
-
let printed = false;
|
|
1403
|
-
let left = this.body * (this.options.doubleSpace ? 2 : 1);
|
|
1404
|
-
while (left > 0 && this.ready()) {
|
|
1405
|
-
this.outputPosition = 0;
|
|
1406
|
-
this.spaces = 0;
|
|
1407
|
-
this.separators = 0;
|
|
1408
|
-
this.vertical = false;
|
|
1409
|
-
this.alignEmpty = false;
|
|
1410
|
-
this.empty = true;
|
|
1411
|
-
for (const column of this.columns) {
|
|
1412
|
-
this.budget.charge();
|
|
1413
|
-
this.inputPosition = 0;
|
|
1414
|
-
if (column.remaining > 0 || column.status === "feed") {
|
|
1415
|
-
this.feedOnly = false;
|
|
1416
|
-
this.padding = column.start;
|
|
1417
|
-
if (this.store) this.storedLine(column, date, name);
|
|
1418
|
-
else {
|
|
1419
|
-
const rp = this.readSyncOrAsync(column, date, name);
|
|
1420
|
-
if (rp) return false;
|
|
1421
|
-
}
|
|
1422
|
-
printed ||= this.vertical;
|
|
1423
|
-
column.remaining--;
|
|
1424
|
-
if (column.remaining <= 0 && !this.ready()) break;
|
|
1425
|
-
if (this.options.merge && column.status !== "open") {
|
|
1426
|
-
if (this.empty) this.alignEmpty = true;
|
|
1427
|
-
else if (column.status === "closed" || this.feedOnly) this.align(column);
|
|
1428
|
-
}
|
|
1429
|
-
} else if (this.options.merge) {
|
|
1430
|
-
if (this.empty) this.alignEmpty = true;
|
|
1431
|
-
else this.align(column);
|
|
1432
|
-
}
|
|
1433
|
-
if (this.options.useSeparator) this.separators++;
|
|
1434
|
-
}
|
|
1435
|
-
if (this.vertical) {
|
|
1436
|
-
this.append("\n");
|
|
1437
|
-
left--;
|
|
1438
|
-
}
|
|
1439
|
-
if (!this.ready() && !this.options.extremities) {
|
|
1440
|
-
if (this.flushSyncOrAsync()) return false;
|
|
1441
|
-
break;
|
|
1442
|
-
}
|
|
1443
|
-
if (this.options.doubleSpace && printed) {
|
|
1444
|
-
this.append("\n");
|
|
1445
|
-
left--;
|
|
1446
|
-
}
|
|
1447
|
-
if (this.flushSyncOrAsync()) return false;
|
|
1448
|
-
}
|
|
1449
|
-
if (left === 0) {
|
|
1450
|
-
for (const column of this.columns) if (column.status === "open") column.full = true;
|
|
1451
|
-
}
|
|
1452
|
-
if (printed && this.options.extremities) this.append(this.options.formFeed ? "\f" : this.repeat("\n", left + 5));
|
|
1453
|
-
else if (this.options.keepFF && this.printFeed) {
|
|
1454
|
-
this.append("\f");
|
|
1455
|
-
this.printFeed = false;
|
|
1456
|
-
}
|
|
1457
|
-
if (this.flushSyncOrAsync()) return false;
|
|
1458
|
-
this.pageNumber++;
|
|
1459
|
-
for (const column of this.columns) if (column.status === "held") column.status = "open";
|
|
1460
|
-
}
|
|
1461
|
-
return true;
|
|
1462
|
-
}
|
|
1463
|
-
async run(readers, date, name) {
|
|
1464
|
-
const count = this.options.merge ? readers.length : this.options.columns;
|
|
1465
|
-
for (let index = 0; index < count; index++) {
|
|
1466
|
-
const start = index === 0 ? this.options.margin + this.options.separator.length : this.options.truncate ? this.options.margin + index * (this.columnWidth + this.options.separator.length) + (this.options.merge && this.options.numbered ? this.numberWidth : 0) : 0;
|
|
1467
|
-
this.columns.push({
|
|
1468
|
-
reader: readers[this.options.merge ? index : 0],
|
|
1469
|
-
status: "open",
|
|
1470
|
-
full: false,
|
|
1471
|
-
numbered: this.options.numbered && (!this.options.merge || index === 0),
|
|
1472
|
-
start,
|
|
1473
|
-
lines: [],
|
|
1474
|
-
current: 0,
|
|
1475
|
-
remaining: 0
|
|
1476
|
-
});
|
|
1477
|
-
}
|
|
1478
|
-
try {
|
|
1479
|
-
await this.pages(date, name);
|
|
1480
|
-
await this.lifecycle.flush();
|
|
1481
|
-
} catch (error) {
|
|
1482
|
-
if (error instanceof PrReadError) {
|
|
1483
|
-
await this.flush();
|
|
1484
|
-
await this.lifecycle.flush();
|
|
1485
|
-
}
|
|
1486
|
-
throw error;
|
|
1487
|
-
}
|
|
1488
|
-
}
|
|
1489
|
-
async pages(date, name) {
|
|
1490
|
-
while (this.pageNumber <= this.options.lastPage) {
|
|
1491
|
-
if (this.store) await this.storePage(date, name);
|
|
1492
|
-
else for (const column of this.columns) column.remaining = column.status === "open" ? this.body : 0;
|
|
1493
|
-
if (!this.ready()) return;
|
|
1494
|
-
this.budget.page();
|
|
1495
|
-
this.needHeader = this.options.extremities;
|
|
1496
|
-
let printed = false;
|
|
1497
|
-
let left = this.body * (this.options.doubleSpace ? 2 : 1);
|
|
1498
|
-
while (left > 0 && this.ready()) {
|
|
1499
|
-
this.outputPosition = 0;
|
|
1500
|
-
this.spaces = 0;
|
|
1501
|
-
this.separators = 0;
|
|
1502
|
-
this.vertical = false;
|
|
1503
|
-
this.alignEmpty = false;
|
|
1504
|
-
this.empty = true;
|
|
1505
|
-
for (const column of this.columns) {
|
|
1506
|
-
this.budget.charge();
|
|
1507
|
-
this.inputPosition = 0;
|
|
1508
|
-
if (column.remaining > 0 || column.status === "feed") {
|
|
1509
|
-
this.feedOnly = false;
|
|
1510
|
-
this.padding = column.start;
|
|
1511
|
-
if (this.store) this.storedLine(column, date, name);
|
|
1512
|
-
else {
|
|
1513
|
-
const rp = this.readSyncOrAsync(column, date, name);
|
|
1514
|
-
if (rp) await rp;
|
|
1515
|
-
}
|
|
1516
|
-
printed ||= this.vertical;
|
|
1517
|
-
column.remaining--;
|
|
1518
|
-
if (column.remaining <= 0 && !this.ready()) break;
|
|
1519
|
-
if (this.options.merge && column.status !== "open") {
|
|
1520
|
-
if (this.empty) this.alignEmpty = true;
|
|
1521
|
-
else if (column.status === "closed" || this.feedOnly) this.align(column);
|
|
1522
|
-
}
|
|
1523
|
-
} else if (this.options.merge) {
|
|
1524
|
-
if (this.empty) this.alignEmpty = true;
|
|
1525
|
-
else this.align(column);
|
|
1526
|
-
}
|
|
1527
|
-
if (this.options.useSeparator) this.separators++;
|
|
1528
|
-
}
|
|
1529
|
-
if (this.vertical) {
|
|
1530
|
-
this.append("\n");
|
|
1531
|
-
left--;
|
|
1532
|
-
}
|
|
1533
|
-
if (!this.ready() && !this.options.extremities) {
|
|
1534
|
-
const fp2 = this.flushSyncOrAsync();
|
|
1535
|
-
if (fp2) await fp2;
|
|
1536
|
-
break;
|
|
1537
|
-
}
|
|
1538
|
-
if (this.options.doubleSpace && printed) {
|
|
1539
|
-
this.append("\n");
|
|
1540
|
-
left--;
|
|
1541
|
-
}
|
|
1542
|
-
const fp = this.flushSyncOrAsync();
|
|
1543
|
-
if (fp) await fp;
|
|
1544
|
-
}
|
|
1545
|
-
if (left === 0) {
|
|
1546
|
-
for (const column of this.columns) if (column.status === "open") column.full = true;
|
|
1547
|
-
}
|
|
1548
|
-
if (printed && this.options.extremities) this.append(this.options.formFeed ? "\f" : this.repeat("\n", left + 5));
|
|
1549
|
-
else if (this.options.keepFF && this.printFeed) {
|
|
1550
|
-
this.append("\f");
|
|
1551
|
-
this.printFeed = false;
|
|
1552
|
-
}
|
|
1553
|
-
await this.flush();
|
|
1554
|
-
this.pageNumber++;
|
|
1555
|
-
for (const column of this.columns) if (column.status === "held") column.status = "open";
|
|
1556
|
-
}
|
|
1557
|
-
}
|
|
1558
|
-
};
|
|
1559
|
-
|
|
1560
|
-
// packages/safe-bash-calendar-engine/src/time-env/format.ts
|
|
1561
|
-
init_platform();
|
|
1562
|
-
function offsetText(offset, colons) {
|
|
1563
|
-
const sign = offset < 0 ? "-" : "+";
|
|
1564
|
-
const total = Math.abs(offset);
|
|
1565
|
-
const hours = Math.floor(total / 3600);
|
|
1566
|
-
const minutes = Math.floor(total % 3600 / 60).toString().padStart(2, "0");
|
|
1567
|
-
const seconds = (total % 60).toString().padStart(2, "0");
|
|
1568
|
-
if (colons === 0) return { value: `${sign}${hours * 100 + Number(minutes)}`, width: 5 };
|
|
1569
|
-
if (colons === 2 || colons === 3 && seconds !== "00") return { value: `${sign}${hours}:${minutes}:${seconds}`, width: 9 };
|
|
1570
|
-
if (colons === 1 || minutes !== "00") return { value: `${sign}${hours}:${minutes}`, width: 6 };
|
|
1571
|
-
return { value: `${sign}${hours}`, width: 3 };
|
|
1572
|
-
}
|
|
1573
|
-
function formatDate(format, instant, zone, limits) {
|
|
1574
|
-
const fields = zone.fields(instant);
|
|
1575
|
-
const midnight = utcMilliseconds({ ...fields, hour: 0, minute: 0, second: 0 });
|
|
1576
|
-
const weekday = new Date(midnight).getUTCDay();
|
|
1577
|
-
const ordinal = Math.floor((midnight - utcMilliseconds({ ...fields, month: 1, day: 1, hour: 0, minute: 0, second: 0 })) / 864e5) + 1;
|
|
1578
|
-
const thursday = new Date(midnight + (3 - (weekday + 6) % 7) * 864e5);
|
|
1579
|
-
const isoYear = thursday.getUTCFullYear();
|
|
1580
|
-
const isoWeek = 1 + Math.floor((thursday.getTime() - utcMilliseconds({ year: isoYear, month: 1, day: 1, hour: 0, minute: 0, second: 0 })) / 6048e5);
|
|
1581
|
-
const nano = (instant - floorDivide(instant, nanosecondsPerSecond) * nanosecondsPerSecond).toString().padStart(9, "0");
|
|
1582
|
-
const number = (value, width = 2, padding = "0") => value < 0 && padding === "0" ? `-${Math.abs(value).toString().padStart(Math.max(0, width - 1), padding)}` : value.toString().padStart(width, padding);
|
|
1583
|
-
const time = `${number(fields.hour)}:${number(fields.minute)}:${number(fields.second)}`;
|
|
1584
|
-
const hour12 = fields.hour % 12 || 12;
|
|
1585
|
-
const meridian = fields.hour < 12 ? "AM" : "PM";
|
|
1586
|
-
const pieces = [];
|
|
1587
|
-
let size = 0;
|
|
1588
|
-
const append = (value) => {
|
|
1589
|
-
size += utf8ByteLength(value);
|
|
1590
|
-
checkSize(size + 1, limits.maxOutputBytes, "output");
|
|
1591
|
-
pieces.push(value);
|
|
1592
|
-
};
|
|
1593
|
-
for (let offset = 0; offset < format.length; ) {
|
|
1594
|
-
const next = format.indexOf("%", offset);
|
|
1595
|
-
if (next < 0) {
|
|
1596
|
-
append(format.slice(offset));
|
|
1597
|
-
break;
|
|
1598
|
-
}
|
|
1599
|
-
append(format.slice(offset, next));
|
|
1600
|
-
offset = next + 1;
|
|
1601
|
-
let padding, upper = false, swap = false;
|
|
1602
|
-
while (offset < format.length && "-_0^#".includes(format[offset])) {
|
|
1603
|
-
const flag = format[offset++];
|
|
1604
|
-
if (flag === "^") upper = true;
|
|
1605
|
-
else if (flag === "#") swap = true;
|
|
1606
|
-
else padding = flag === "-" ? "" : flag === "_" ? " " : "0";
|
|
1607
|
-
}
|
|
1608
|
-
let widthText = "";
|
|
1609
|
-
while (offset < format.length && /[0-9]/.test(format[offset])) widthText += format[offset++];
|
|
1610
|
-
const width = widthText ? Number(widthText) : void 0;
|
|
1611
|
-
if (width !== void 0) checkSize(width, limits.maxFormatWidth, "format width");
|
|
1612
|
-
let colons = 0;
|
|
1613
|
-
while (format[offset] === ":") {
|
|
1614
|
-
colons++;
|
|
1615
|
-
offset++;
|
|
1616
|
-
}
|
|
1617
|
-
const modifier = format[offset] === "E" || format[offset] === "O" ? format[offset++] : void 0;
|
|
1618
|
-
const code = format[offset++];
|
|
1619
|
-
if (!code || colons > 3 || colons && code !== "z") throw new CommandFailure("unsupported date format directive");
|
|
1620
|
-
if (code === "%" && (padding !== void 0 || upper || swap || width !== void 0 || modifier)) {
|
|
1621
|
-
throw new CommandFailure("only an unmodified %% literal is supported");
|
|
1622
|
-
}
|
|
1623
|
-
if (modifier && !(modifier === "E" ? "cCxXyY" : "deHImMSuUVwWy").includes(code)) throw new CommandFailure(`unsupported date format modifier: %${modifier}${code}`);
|
|
1624
|
-
let value, defaultWidth = 0, defaultPadding = "0";
|
|
1625
|
-
switch (code) {
|
|
1626
|
-
case "%":
|
|
1627
|
-
value = "%";
|
|
1628
|
-
break;
|
|
1629
|
-
case "a":
|
|
1630
|
-
value = weekdayNames[weekday].slice(0, 3);
|
|
1631
|
-
break;
|
|
1632
|
-
case "A":
|
|
1633
|
-
value = weekdayNames[weekday];
|
|
1634
|
-
break;
|
|
1635
|
-
case "b":
|
|
1636
|
-
case "h":
|
|
1637
|
-
value = monthNames[fields.month - 1].slice(0, 3);
|
|
1638
|
-
break;
|
|
1639
|
-
case "B":
|
|
1640
|
-
value = monthNames[fields.month - 1];
|
|
1641
|
-
break;
|
|
1642
|
-
case "c":
|
|
1643
|
-
value = `${weekdayNames[weekday].slice(0, 3)} ${monthNames[fields.month - 1].slice(0, 3)} ${number(fields.day, 2, " ")} ${time} ${number(fields.year, 4)}`;
|
|
1644
|
-
break;
|
|
1645
|
-
case "C":
|
|
1646
|
-
value = String(Math.floor(fields.year / 100));
|
|
1647
|
-
defaultWidth = 2;
|
|
1648
|
-
break;
|
|
1649
|
-
case "d":
|
|
1650
|
-
case "e":
|
|
1651
|
-
value = String(fields.day);
|
|
1652
|
-
defaultWidth = 2;
|
|
1653
|
-
if (code === "e") defaultPadding = " ";
|
|
1654
|
-
break;
|
|
1655
|
-
case "D":
|
|
1656
|
-
value = `${number(fields.month)}/${number(fields.day)}/${number(Math.abs(fields.year % 100), 2, padding ?? "0")}`;
|
|
1657
|
-
break;
|
|
1658
|
-
case "x":
|
|
1659
|
-
value = `${number(fields.month)}/${number(fields.day)}/${number(Math.abs(fields.year % 100))}`;
|
|
1660
|
-
break;
|
|
1661
|
-
case "F": {
|
|
1662
|
-
const yearWidth = width === void 0 && padding === void 0 ? 4 : Math.max(0, (width ?? 0) - 6);
|
|
1663
|
-
const year = padding === "" ? String(fields.year) : number(fields.year, yearWidth, padding ?? "0");
|
|
1664
|
-
append(`${year}-${number(fields.month)}-${number(fields.day)}`);
|
|
1665
|
-
continue;
|
|
1666
|
-
}
|
|
1667
|
-
case "g":
|
|
1668
|
-
value = String(Math.abs(isoYear % 100));
|
|
1669
|
-
defaultWidth = 2;
|
|
1670
|
-
break;
|
|
1671
|
-
case "G":
|
|
1672
|
-
value = String(isoYear);
|
|
1673
|
-
defaultWidth = 4;
|
|
1674
|
-
break;
|
|
1675
|
-
case "H":
|
|
1676
|
-
case "k":
|
|
1677
|
-
value = String(fields.hour);
|
|
1678
|
-
defaultWidth = 2;
|
|
1679
|
-
if (code === "k") defaultPadding = " ";
|
|
1680
|
-
break;
|
|
1681
|
-
case "I":
|
|
1682
|
-
case "l":
|
|
1683
|
-
value = String(hour12);
|
|
1684
|
-
defaultWidth = 2;
|
|
1685
|
-
if (code === "l") defaultPadding = " ";
|
|
1686
|
-
break;
|
|
1687
|
-
case "j":
|
|
1688
|
-
value = String(ordinal);
|
|
1689
|
-
defaultWidth = 3;
|
|
1690
|
-
break;
|
|
1691
|
-
case "m":
|
|
1692
|
-
value = String(fields.month);
|
|
1693
|
-
defaultWidth = 2;
|
|
1694
|
-
break;
|
|
1695
|
-
case "M":
|
|
1696
|
-
value = String(fields.minute);
|
|
1697
|
-
defaultWidth = 2;
|
|
1698
|
-
break;
|
|
1699
|
-
case "n":
|
|
1700
|
-
value = "\n";
|
|
1701
|
-
break;
|
|
1702
|
-
case "N": {
|
|
1703
|
-
if (format.slice(next, offset) === "%-N") {
|
|
1704
|
-
append(nano.slice(0, 6));
|
|
1705
|
-
continue;
|
|
1706
|
-
}
|
|
1707
|
-
const precision = width ?? 9;
|
|
1708
|
-
const digits = nano.slice(0, precision).replace(/0+$/, "") || "0";
|
|
1709
|
-
const length = padding === "" ? digits.length : precision;
|
|
1710
|
-
checkSize(size + length + 1, limits.maxOutputBytes, "output");
|
|
1711
|
-
append(padding === "" ? digits : digits.padEnd(precision, padding ?? "0"));
|
|
1712
|
-
continue;
|
|
1713
|
-
}
|
|
1714
|
-
case "p":
|
|
1715
|
-
value = meridian;
|
|
1716
|
-
break;
|
|
1717
|
-
case "P":
|
|
1718
|
-
value = meridian.toLowerCase();
|
|
1719
|
-
break;
|
|
1720
|
-
case "q":
|
|
1721
|
-
value = String(Math.ceil(fields.month / 3));
|
|
1722
|
-
defaultWidth = 1;
|
|
1723
|
-
break;
|
|
1724
|
-
case "r":
|
|
1725
|
-
value = `${number(hour12)}:${number(fields.minute)}:${number(fields.second)} ${meridian}`;
|
|
1726
|
-
break;
|
|
1727
|
-
case "R":
|
|
1728
|
-
value = `${number(fields.hour)}:${number(fields.minute)}`;
|
|
1729
|
-
break;
|
|
1730
|
-
case "s":
|
|
1731
|
-
value = floorDivide(instant, nanosecondsPerSecond).toString();
|
|
1732
|
-
defaultWidth = 1;
|
|
1733
|
-
break;
|
|
1734
|
-
case "S":
|
|
1735
|
-
value = String(fields.second);
|
|
1736
|
-
defaultWidth = 2;
|
|
1737
|
-
break;
|
|
1738
|
-
case "t":
|
|
1739
|
-
value = " ";
|
|
1740
|
-
break;
|
|
1741
|
-
case "T":
|
|
1742
|
-
case "X":
|
|
1743
|
-
value = time;
|
|
1744
|
-
break;
|
|
1745
|
-
case "u":
|
|
1746
|
-
value = String(weekday || 7);
|
|
1747
|
-
defaultWidth = 1;
|
|
1748
|
-
break;
|
|
1749
|
-
case "U":
|
|
1750
|
-
value = String(Math.floor((ordinal - 1 + 7 - weekday) / 7));
|
|
1751
|
-
defaultWidth = 2;
|
|
1752
|
-
break;
|
|
1753
|
-
case "V":
|
|
1754
|
-
value = String(isoWeek);
|
|
1755
|
-
defaultWidth = 2;
|
|
1756
|
-
break;
|
|
1757
|
-
case "w":
|
|
1758
|
-
value = String(weekday);
|
|
1759
|
-
defaultWidth = 1;
|
|
1760
|
-
break;
|
|
1761
|
-
case "W":
|
|
1762
|
-
value = String(Math.floor((ordinal - 1 + 7 - (weekday + 6) % 7) / 7));
|
|
1763
|
-
defaultWidth = 2;
|
|
1764
|
-
break;
|
|
1765
|
-
case "y":
|
|
1766
|
-
value = String(Math.abs(fields.year % 100));
|
|
1767
|
-
defaultWidth = 2;
|
|
1768
|
-
break;
|
|
1769
|
-
case "Y":
|
|
1770
|
-
value = String(fields.year);
|
|
1771
|
-
defaultWidth = 4;
|
|
1772
|
-
break;
|
|
1773
|
-
case "z": {
|
|
1774
|
-
const offset2 = offsetText(fields.offset, colons);
|
|
1775
|
-
value = offset2.value;
|
|
1776
|
-
defaultWidth = offset2.width;
|
|
1777
|
-
break;
|
|
1778
|
-
}
|
|
1779
|
-
case "Z":
|
|
1780
|
-
value = fields.zone;
|
|
1781
|
-
break;
|
|
1782
|
-
default:
|
|
1783
|
-
throw new CommandFailure(`unsupported date format directive: %${code}`);
|
|
1784
|
-
}
|
|
1785
|
-
if (code === "P" || swap && "pZ".includes(code)) value = value.toLowerCase();
|
|
1786
|
-
else if (upper || swap && "aAbBh".includes(code)) value = value.toUpperCase();
|
|
1787
|
-
const fill = padding ?? (defaultWidth || code === "z" ? defaultPadding : " ");
|
|
1788
|
-
const minimum = width ?? defaultWidth;
|
|
1789
|
-
if (fill && minimum > value.length) value = /^[+-]/.test(value) && fill === "0" ? `${value[0]}${value.slice(1).padStart(minimum - 1, fill)}` : value.padStart(minimum, fill);
|
|
1790
|
-
append(value);
|
|
1791
|
-
}
|
|
1792
|
-
return pieces.join("") + "\n";
|
|
1793
|
-
}
|
|
1794
|
-
|
|
1795
|
-
// packages/safe-bash-command-pr/src/command.ts
|
|
1796
|
-
function createPrCommand(options = {}) {
|
|
1797
|
-
const limits = settings(options);
|
|
1798
|
-
const def = { name: "pr", description: "Paginate files and print balanced or merged columns", async execute(context) {
|
|
1799
|
-
const output = createOutputOperation(context, context.stdout);
|
|
1800
|
-
const budget = new Budget(context, limits, output.signal);
|
|
1801
|
-
let lifecycle;
|
|
1802
|
-
let failure;
|
|
1803
|
-
let primary;
|
|
1804
|
-
let exitCode = 0;
|
|
1805
|
-
try {
|
|
1806
|
-
lifecycle = new Lifecycle(budget, output);
|
|
1807
|
-
const parsed = parseOptions(budget.arguments(), budget);
|
|
1808
|
-
if (parsed.information) {
|
|
1809
|
-
await lifecycle.write(parsed.information === "version" ? "pr (virtual-bash)\n" : "Usage: pr [OPTION]... [FILE]...\nPaginate or columnate files for printing.\nOptions: -COLUMNS -h HEADER -l LENGTH -w WIDTH -t -n[SEP[DIGITS]] -m -s[SEP]\n --date-format=FORMAT format the header date\n");
|
|
1810
|
-
await lifecycle.flush();
|
|
1811
|
-
} else {
|
|
1812
|
-
const ctype = context.env.LC_ALL || context.env.LC_CTYPE || context.env.LANG || "C";
|
|
1813
|
-
const timeLocale = context.env.LC_ALL || context.env.LC_TIME || context.env.LANG || "C";
|
|
1814
|
-
for (const locale of [ctype, timeLocale]) if (!["C", "POSIX", "C.UTF-8", "C.utf8"].includes(locale)) throw new PrError(`unsupported locale ${quote(locale)}`);
|
|
1815
|
-
let sampled;
|
|
1816
|
-
const date = (reader) => {
|
|
1817
|
-
let milliseconds;
|
|
1818
|
-
if (reader?.stat) milliseconds = reader.stat.mtimeMs;
|
|
1819
|
-
else milliseconds = sampled ??= (options.clock ?? Date.now)();
|
|
1820
|
-
const value = new Date(milliseconds);
|
|
1821
|
-
if (!Number.isFinite(milliseconds) || Number.isNaN(value.getTime())) throw new PrError("invalid header timestamp");
|
|
1822
|
-
if (parsed.dateFormat !== void 0) {
|
|
1823
|
-
try {
|
|
1824
|
-
return formatDate(parsed.dateFormat, BigInt(Math.trunc(milliseconds)) * 1000000n, new TimeZone("UTC"), {
|
|
1825
|
-
maxArguments: limits.maxArguments,
|
|
1826
|
-
maxArgumentBytes: limits.maxArgumentBytes,
|
|
1827
|
-
maxOutputBytes: Math.min(limits.maxBufferedBytes, limits.maxOutputBytes),
|
|
1828
|
-
maxEnvironmentEntries: 1,
|
|
1829
|
-
maxFormatWidth: limits.maxPageWidth
|
|
1830
|
-
}).slice(0, -1);
|
|
1831
|
-
} catch (error) {
|
|
1832
|
-
if (error instanceof CommandFailure || error instanceof FsError2) throw new PrError(error.message);
|
|
1833
|
-
throw error;
|
|
1834
|
-
}
|
|
1835
|
-
}
|
|
1836
|
-
const year = String(value.getUTCFullYear()).padStart(4, "0");
|
|
1837
|
-
const month = String(value.getUTCMonth() + 1).padStart(2, "0");
|
|
1838
|
-
const day = String(value.getUTCDate()).padStart(2, "0");
|
|
1839
|
-
const time = `${String(value.getUTCHours()).padStart(2, "0")}:${String(value.getUTCMinutes()).padStart(2, "0")}`;
|
|
1840
|
-
if (context.env.POSIXLY_CORRECT !== void 0 && (timeLocale === "C" || timeLocale === "POSIX")) return `${["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][value.getUTCMonth()]} ${String(value.getUTCDate()).padStart(2, " ")} ${time} ${year}`;
|
|
1841
|
-
return `${year}-${month}-${day} ${time}`;
|
|
1842
|
-
};
|
|
1843
|
-
let stdin;
|
|
1844
|
-
const open = async (name) => {
|
|
1845
|
-
if (name === "-" && stdin) return stdin;
|
|
1846
|
-
const reader = new Reader(name, lifecycle);
|
|
1847
|
-
try {
|
|
1848
|
-
await reader.open();
|
|
1849
|
-
} catch (error) {
|
|
1850
|
-
if (!(error instanceof FsError2)) throw error;
|
|
1851
|
-
exitCode = 1;
|
|
1852
|
-
if (!parsed.quiet) {
|
|
1853
|
-
await lifecycle.write(`pr: ${fileQuote(name)}: ${fsDetail(error)}
|
|
1854
|
-
`, true);
|
|
1855
|
-
}
|
|
1856
|
-
return void 0;
|
|
1857
|
-
}
|
|
1858
|
-
if (name === "-") stdin = reader;
|
|
1859
|
-
return reader;
|
|
1860
|
-
};
|
|
1861
|
-
const names = parsed.files.length ? parsed.files : ["-"];
|
|
1862
|
-
if (!parsed.files.length) parsed.merge = false;
|
|
1863
|
-
const groups = parsed.merge ? [names] : names.map((name) => [name]);
|
|
1864
|
-
for (const group of groups) {
|
|
1865
|
-
const formatter = new Formatter({ ...parsed }, lifecycle, group.length);
|
|
1866
|
-
const readers = [];
|
|
1867
|
-
for (const name of group) {
|
|
1868
|
-
const reader = await open(name);
|
|
1869
|
-
if (reader) readers.push(reader);
|
|
1870
|
-
}
|
|
1871
|
-
if (!readers.length) continue;
|
|
1872
|
-
const title = parsed.header ?? (parsed.merge || readers[0].name === "-" ? "" : readers[0].name);
|
|
1873
|
-
await formatter.run(readers, date(parsed.merge ? void 0 : readers[0]), title);
|
|
1874
|
-
await lifecycle.flush();
|
|
1875
|
-
}
|
|
1876
|
-
}
|
|
1877
|
-
} catch (error) {
|
|
1878
|
-
primary = { reason: error };
|
|
1879
|
-
failure = { reason: error };
|
|
1880
|
-
if (!output.signal.aborted && lifecycle && error instanceof PrError) {
|
|
1881
|
-
exitCode = 1;
|
|
1882
|
-
try {
|
|
1883
|
-
await lifecycle.write(`pr: ${publicDiagnosticMessage(error, context.onInternalError)}
|
|
1884
|
-
`, true);
|
|
1885
|
-
if (error.usage) await lifecycle.write("Try 'pr --help' for more information.\n", true);
|
|
1886
|
-
failure = void 0;
|
|
1887
|
-
} catch (reporting) {
|
|
1888
|
-
failure = { reason: new AggregateError([error, reporting], "pr failure reporting failed") };
|
|
1889
|
-
}
|
|
1890
|
-
}
|
|
1891
|
-
}
|
|
1892
|
-
try {
|
|
1893
|
-
await output.close();
|
|
1894
|
-
} catch (cleanup) {
|
|
1895
|
-
const previous = failure ?? primary;
|
|
1896
|
-
failure = { reason: previous ? new AggregateError([previous.reason, cleanup], "pr execution and cleanup failed") : cleanup };
|
|
1897
|
-
}
|
|
1898
|
-
context.signal.throwIfAborted();
|
|
1899
|
-
output.signal.throwIfAborted();
|
|
1900
|
-
if (failure) throw failure.reason;
|
|
1901
|
-
return { exitCode };
|
|
1902
|
-
} };
|
|
1903
|
-
if (options.limits === void 0) builtInDirectContextExecutors.add(def.execute);
|
|
1904
|
-
return def;
|
|
1905
|
-
}
|
|
1906
|
-
|
|
1907
|
-
// packages/safe-bash-command-pr/src/index.ts
|
|
1908
|
-
function createPrCommands(options = {}) {
|
|
1909
|
-
return [createPrCommand(options)];
|
|
1910
|
-
}
|
|
1911
|
-
function prCommands(options = {}) {
|
|
1912
|
-
const commands = createPrCommands(options);
|
|
1913
|
-
return { name: "pr-commands", setup(host) {
|
|
1914
|
-
for (const command of commands) host.commands.register(command, { replace: options.replace ?? false });
|
|
1915
|
-
} };
|
|
1916
|
-
}
|
|
1917
|
-
var _syncPrSignal;
|
|
1918
|
-
var getSyncPrSignal = () => _syncPrSignal ??= new AbortController().signal;
|
|
1919
|
-
var syncPrLimits = settings({});
|
|
1920
|
-
var getSyncPrDummyOutput = () => ({
|
|
1921
|
-
signal: getSyncPrSignal(),
|
|
1922
|
-
output: { async write() {
|
|
1923
|
-
} },
|
|
1924
|
-
registerCleanup() {
|
|
1925
|
-
},
|
|
1926
|
-
async close() {
|
|
1927
|
-
}
|
|
1928
|
-
});
|
|
1929
|
-
var getSyncPrDummyContext = () => ({
|
|
1930
|
-
args: [],
|
|
1931
|
-
cwd: "/",
|
|
1932
|
-
env: { LC_ALL: "C" },
|
|
1933
|
-
signal: getSyncPrSignal()
|
|
1934
|
-
});
|
|
1935
|
-
var prSyncDecoder = new TextDecoder("utf-8", { fatal: false });
|
|
1936
|
-
var prSyncCache = /* @__PURE__ */ new Map();
|
|
1937
|
-
function evalSyncPr(inBytes, opArgs, readFileSync) {
|
|
1938
|
-
let cacheKey;
|
|
1939
|
-
if (inBytes !== void 0 && opArgs.every((a) => a.startsWith("-"))) {
|
|
1940
|
-
cacheKey = `${opArgs.join("\0")}|\0${prSyncDecoder.decode(inBytes)}`;
|
|
1941
|
-
const cached = prSyncCache.get(cacheKey);
|
|
1942
|
-
if (cached !== void 0) return cached;
|
|
1943
|
-
}
|
|
1944
|
-
try {
|
|
1945
|
-
const budget = new Budget(getSyncPrDummyContext(), syncPrLimits, getSyncPrSignal());
|
|
1946
|
-
const parsed = parseOptions([...opArgs], budget);
|
|
1947
|
-
if (parsed.information !== void 0) return void 0;
|
|
1948
|
-
if (parsed.extremities) cacheKey = void 0;
|
|
1949
|
-
const names = parsed.files.length ? parsed.files : ["-"];
|
|
1950
|
-
if (!parsed.files.length) parsed.merge = false;
|
|
1951
|
-
const groups = parsed.merge ? [names] : names.map((name) => [name]);
|
|
1952
|
-
const lifecycle = new Lifecycle(budget, getSyncPrDummyOutput());
|
|
1953
|
-
const nowMs = Date.now();
|
|
1954
|
-
const formatStamp = () => {
|
|
1955
|
-
const value = new Date(nowMs);
|
|
1956
|
-
if (parsed.dateFormat !== void 0) {
|
|
1957
|
-
return formatDate(parsed.dateFormat, BigInt(Math.trunc(nowMs)) * 1000000n, new TimeZone("UTC"), {
|
|
1958
|
-
maxArguments: syncPrLimits.maxArguments,
|
|
1959
|
-
maxArgumentBytes: syncPrLimits.maxArgumentBytes,
|
|
1960
|
-
maxOutputBytes: Math.min(syncPrLimits.maxBufferedBytes, syncPrLimits.maxOutputBytes),
|
|
1961
|
-
maxEnvironmentEntries: 1,
|
|
1962
|
-
maxFormatWidth: syncPrLimits.maxPageWidth
|
|
1963
|
-
}).slice(0, -1);
|
|
1964
|
-
}
|
|
1965
|
-
const year = String(value.getUTCFullYear()).padStart(4, "0");
|
|
1966
|
-
const month = String(value.getUTCMonth() + 1).padStart(2, "0");
|
|
1967
|
-
const day = String(value.getUTCDate()).padStart(2, "0");
|
|
1968
|
-
const time = `${String(value.getUTCHours()).padStart(2, "0")}:${String(value.getUTCMinutes()).padStart(2, "0")}`;
|
|
1969
|
-
return `${year}-${month}-${day} ${time}`;
|
|
1970
|
-
};
|
|
1971
|
-
let totalOut = "";
|
|
1972
|
-
for (const group of groups) {
|
|
1973
|
-
const formatter = new Formatter({ ...parsed }, lifecycle, group.length);
|
|
1974
|
-
const readers = [];
|
|
1975
|
-
for (const name of group) {
|
|
1976
|
-
let srcBytes;
|
|
1977
|
-
if (name === "-") {
|
|
1978
|
-
srcBytes = inBytes;
|
|
1979
|
-
} else {
|
|
1980
|
-
if (parsed.extremities && parsed.dateFormat === void 0) return void 0;
|
|
1981
|
-
if (!readFileSync) return void 0;
|
|
1982
|
-
srcBytes = readFileSync(name);
|
|
1983
|
-
}
|
|
1984
|
-
if (!srcBytes || srcBytes.byteLength > 16384 || srcBytes.includes(12)) return void 0;
|
|
1985
|
-
const reader = new Reader(name, lifecycle);
|
|
1986
|
-
reader.initFromBytes(srcBytes);
|
|
1987
|
-
readers.push(reader);
|
|
1988
|
-
}
|
|
1989
|
-
const title = parsed.header ?? (parsed.merge || readers[0].name === "-" ? "" : readers[0].name);
|
|
1990
|
-
const stamp = parsed.extremities ? formatStamp() : "";
|
|
1991
|
-
if (!formatter.runSync(readers, stamp, title)) return void 0;
|
|
1992
|
-
totalOut += lifecycle.takeStdoutSync();
|
|
1993
|
-
}
|
|
1994
|
-
const res = totalOut.endsWith("\n") ? totalOut.slice(0, -1) : totalOut;
|
|
1995
|
-
if (cacheKey !== void 0) {
|
|
1996
|
-
if (prSyncCache.size >= 8) prSyncCache.clear();
|
|
1997
|
-
prSyncCache.set(cacheKey, res);
|
|
1998
|
-
}
|
|
1999
|
-
return res;
|
|
2000
|
-
} catch {
|
|
2001
|
-
return void 0;
|
|
2002
|
-
}
|
|
2003
|
-
}
|
|
2004
|
-
|
|
2005
|
-
export {
|
|
2006
|
-
formatDate,
|
|
2007
|
-
createPrCommand,
|
|
2008
|
-
createPrCommands,
|
|
2009
|
-
prCommands,
|
|
2010
|
-
evalSyncPr
|
|
2011
|
-
};
|
|
2012
|
-
//# sourceMappingURL=chunk-M5SCNKIK.js.map
|