@junheep/gwt 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/gwt.mjs +50 -11
- package/package.json +1 -1
package/bin/gwt.mjs
CHANGED
|
@@ -711,22 +711,19 @@ async function chooseWorktree(repository) {
|
|
|
711
711
|
|
|
712
712
|
const terminalWidth = Math.max(48, process.stdout.columns ?? 100)
|
|
713
713
|
const idWidth = 8
|
|
714
|
-
const setupWidth = Math.max(5, ...filtered.map((choice) => choice.setup
|
|
715
|
-
const longestBranch = Math.max(12, ...filtered.map((choice) => choice.branch
|
|
714
|
+
const setupWidth = Math.max(5, ...filtered.map((choice) => displayWidth(choice.setup)))
|
|
715
|
+
const longestBranch = Math.max(12, ...filtered.map((choice) => displayWidth(choice.branch)))
|
|
716
716
|
const flexibleWidth = terminalWidth - idWidth - setupWidth - 10
|
|
717
717
|
const branchWidth = Math.min(32, longestBranch, Math.max(8, flexibleWidth - 8))
|
|
718
718
|
const pathWidth = Math.max(8, flexibleWidth - branchWidth)
|
|
719
|
-
const fit = (value, width) => value.length > width
|
|
720
|
-
? `${value.slice(0, Math.max(0, width - 1))}…`
|
|
721
|
-
: value.padEnd(width)
|
|
722
719
|
const visibleCount = Math.max(3, (process.stdout.rows ?? 24) - 5)
|
|
723
720
|
const start = Math.max(0, Math.min(selected - Math.floor(visibleCount / 2), filtered.length - visibleCount))
|
|
724
721
|
const visible = filtered.slice(start, start + visibleCount)
|
|
725
722
|
const escapeAction = filtering ? "clear" : "cancel"
|
|
726
723
|
const lines = [
|
|
727
|
-
`${colors.dim}${
|
|
728
|
-
...(filtering ? [
|
|
729
|
-
`${colors.dim} ${
|
|
724
|
+
`${colors.dim}${fitDisplay(`Switch worktree Esc ${escapeAction} · Enter select · ↑↓/jk/C-n/C-p · / filter`, terminalWidth)}${colors.reset}`,
|
|
725
|
+
...(filtering ? [fitDisplay(`Filter: /${query}`, terminalWidth)] : []),
|
|
726
|
+
`${colors.dim} ${fitDisplay("BRANCH", branchWidth)} ${fitDisplay("ID", idWidth)} ${fitDisplay("SETUP", setupWidth)} ${fitDisplay("PATH", pathWidth)}${colors.reset}`,
|
|
730
727
|
]
|
|
731
728
|
|
|
732
729
|
if (visible.length === 0) {
|
|
@@ -736,7 +733,7 @@ async function chooseWorktree(repository) {
|
|
|
736
733
|
const index = start + visibleIndex
|
|
737
734
|
const selection = index === selected ? `${colors.cyan}>${colors.reset}` : " "
|
|
738
735
|
const currentMarker = choice.current ? `${colors.yellow}*${colors.reset}` : " "
|
|
739
|
-
lines.push(`${selection} ${currentMarker} ${
|
|
736
|
+
lines.push(`${selection} ${currentMarker} ${fitDisplay(choice.branch, branchWidth)} ${fitDisplay(choice.id, idWidth)} ${fitDisplay(choice.setup, setupWidth)} ${fitDisplay(choice.path, pathWidth)}`)
|
|
740
737
|
})
|
|
741
738
|
}
|
|
742
739
|
|
|
@@ -854,6 +851,38 @@ function padDisplay(value, width) {
|
|
|
854
851
|
return `${value}${" ".repeat(Math.max(0, width - displayWidth(value)))}`
|
|
855
852
|
}
|
|
856
853
|
|
|
854
|
+
function fitDisplay(value, width) {
|
|
855
|
+
const normalized = value.normalize("NFC")
|
|
856
|
+
if (displayWidth(normalized) <= width) return padDisplay(normalized, width)
|
|
857
|
+
|
|
858
|
+
const contentWidth = width - displayWidth("…")
|
|
859
|
+
let fitted = ""
|
|
860
|
+
let fittedWidth = 0
|
|
861
|
+
for (const character of normalized) {
|
|
862
|
+
const characterWidth = displayWidth(character)
|
|
863
|
+
if (fittedWidth + characterWidth > contentWidth) break
|
|
864
|
+
fitted += character
|
|
865
|
+
fittedWidth += characterWidth
|
|
866
|
+
}
|
|
867
|
+
return padDisplay(`${fitted}…`, width)
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
function truncateDisplayTail(value, width) {
|
|
871
|
+
const normalized = value.normalize("NFC")
|
|
872
|
+
if (displayWidth(normalized) <= width) return normalized
|
|
873
|
+
|
|
874
|
+
const contentWidth = width - displayWidth("…")
|
|
875
|
+
let fitted = ""
|
|
876
|
+
let fittedWidth = 0
|
|
877
|
+
for (const character of [...normalized].reverse()) {
|
|
878
|
+
const characterWidth = displayWidth(character)
|
|
879
|
+
if (fittedWidth + characterWidth > contentWidth) break
|
|
880
|
+
fitted = `${character}${fitted}`
|
|
881
|
+
fittedWidth += characterWidth
|
|
882
|
+
}
|
|
883
|
+
return `…${fitted}`
|
|
884
|
+
}
|
|
885
|
+
|
|
857
886
|
function commandList(args) {
|
|
858
887
|
if (args.length > 0) throw new CliError("Usage: gwt list")
|
|
859
888
|
const repository = discoverRepository()
|
|
@@ -864,10 +893,20 @@ function commandList(args) {
|
|
|
864
893
|
id: Math.max(2, ...rows.map((row) => displayWidth(row.id))),
|
|
865
894
|
setup: Math.max(5, ...rows.map((row) => displayWidth(row.setup))),
|
|
866
895
|
}
|
|
867
|
-
|
|
896
|
+
let pathWidth = null
|
|
897
|
+
if (process.stdout.isTTY) {
|
|
898
|
+
const minimumWidth = 8 + 6 + widths.id + widths.setup + 4
|
|
899
|
+
const terminalWidth = Math.max(minimumWidth, process.stdout.columns || 100)
|
|
900
|
+
const flexibleWidth = terminalWidth - widths.id - widths.setup - 8
|
|
901
|
+
widths.branch = Math.min(32, widths.branch, Math.max(6, flexibleWidth - 12))
|
|
902
|
+
pathWidth = flexibleWidth - widths.branch
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
console.log(`${colors.dim} ${fitDisplay("BRANCH", widths.branch)} ${fitDisplay("ID", widths.id)} ${fitDisplay("SETUP", widths.setup)} PATH${colors.reset}`)
|
|
868
906
|
for (const row of rows) {
|
|
869
907
|
const currentMarker = row.current ? `${colors.yellow}*${colors.reset}` : " "
|
|
870
|
-
|
|
908
|
+
const path = pathWidth === null ? row.path : truncateDisplayTail(row.path, pathWidth)
|
|
909
|
+
console.log(`${currentMarker} ${fitDisplay(row.branch, widths.branch)} ${fitDisplay(row.id, widths.id)} ${fitDisplay(row.setup, widths.setup)} ${path}`)
|
|
871
910
|
}
|
|
872
911
|
}
|
|
873
912
|
|