vde-worktree 0.0.13 → 0.0.14

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/index.mjs CHANGED
@@ -1200,7 +1200,11 @@ const RESERVED_FZF_ARGS = new Set([
1200
1200
  "height",
1201
1201
  "border"
1202
1202
  ]);
1203
+ const ANSI_ESCAPE_SEQUENCE_PATTERN = String.raw`\u001B\[[0-?]*[ -/]*[@-~]`;
1204
+ const ANSI_ESCAPE_SEQUENCE_REGEX = new RegExp(ANSI_ESCAPE_SEQUENCE_PATTERN, "g");
1203
1205
  const sanitizeCandidate = (value) => value.replace(/[\r\n]+/g, " ").trim();
1206
+ const stripAnsi = (value) => value.replace(ANSI_ESCAPE_SEQUENCE_REGEX, "");
1207
+ const stripTrailingNewlines = (value) => value.replace(/[\r\n]+$/g, "");
1204
1208
  const buildFzfInput = (candidates) => {
1205
1209
  return candidates.map((candidate) => sanitizeCandidate(candidate)).filter((candidate) => candidate.length > 0).join("\n");
1206
1210
  };
@@ -1256,14 +1260,14 @@ const selectPathWithFzf = async ({ candidates, prompt = "worktree> ", fzfExtraAr
1256
1260
  });
1257
1261
  const input = buildFzfInput(candidates);
1258
1262
  if (input.length === 0) throw new Error("All candidates are empty after sanitization");
1259
- const candidateSet = new Set(input.split("\n"));
1263
+ const candidateSet = new Set(input.split("\n").map((candidate) => stripAnsi(candidate)));
1260
1264
  try {
1261
- const selectedPath = (await runFzf({
1265
+ const selectedPath = stripAnsi(stripTrailingNewlines((await runFzf({
1262
1266
  args,
1263
1267
  input,
1264
1268
  cwd,
1265
1269
  env
1266
- })).stdout.trim();
1270
+ })).stdout));
1267
1271
  if (selectedPath.length === 0) return { status: "cancelled" };
1268
1272
  if (!candidateSet.has(selectedPath)) throw new Error("fzf returned a value that is not in the candidate list");
1269
1273
  return {