git-clone-resume 0.1.3 → 0.1.4

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.
@@ -539,6 +539,42 @@ function Get-GcrHistoryPath {
539
539
  return (Join-Path (Join-Path $root "git-clone-resume") "history.json")
540
540
  }
541
541
 
542
+ function Get-GcrSettingsPath {
543
+ $historyPath = Get-GcrHistoryPath
544
+ return (Join-Path (Split-Path -Parent $historyPath) "settings.json")
545
+ }
546
+
547
+ function Get-GcrLanguagePreference {
548
+ try {
549
+ $path = Get-GcrSettingsPath
550
+ if (-not (Test-Path -LiteralPath $path)) { return $null }
551
+ $settings = Get-Content -Raw -LiteralPath $path | ConvertFrom-Json
552
+ if ($settings.language -eq "en-US" -or $settings.language -eq "zh-CN") {
553
+ return [string]$settings.language
554
+ }
555
+ } catch { }
556
+ return $null
557
+ }
558
+
559
+ function Save-GcrLanguagePreference {
560
+ param([ValidateSet("zh-CN", "en-US")][string]$Language)
561
+ try {
562
+ $path = Get-GcrSettingsPath
563
+ $dir = Split-Path -Parent $path
564
+ if (-not (Test-Path -LiteralPath $dir)) {
565
+ New-Item -ItemType Directory -Path $dir -Force | Out-Null
566
+ }
567
+ $settings = @{ language = $Language; updated = (Get-Date).ToString("o") }
568
+ [System.IO.File]::WriteAllText($path, (ConvertTo-Json $settings), (New-Object System.Text.UTF8Encoding $false))
569
+ } catch { }
570
+ }
571
+
572
+ function Set-GcrLanguage {
573
+ param([ValidateSet("zh-CN", "en-US")][string]$Language)
574
+ $script:GcrLanguage = $Language
575
+ Save-GcrLanguagePreference -Language $Language
576
+ }
577
+
542
578
  function Get-GcrHistory {
543
579
  $path = Get-GcrHistoryPath
544
580
  if (-not (Test-Path -LiteralPath $path)) { return @() }
@@ -609,6 +645,12 @@ function Format-GcrAgo {
609
645
  $dt = [datetime]$When
610
646
  } catch { return "" }
611
647
  $d = (Get-Date) - $dt
648
+ if ($script:GcrLanguage -eq "en-US") {
649
+ if ($d.TotalSeconds -lt 60) { return "just now" }
650
+ if ($d.TotalMinutes -lt 60) { return ("{0} minutes ago" -f [int]$d.TotalMinutes) }
651
+ if ($d.TotalHours -lt 24) { return ("{0} hours ago" -f [int]$d.TotalHours) }
652
+ return ("{0} days ago" -f [int]$d.TotalDays)
653
+ }
612
654
  if ($d.TotalSeconds -lt 60) { return "刚刚" }
613
655
  if ($d.TotalMinutes -lt 60) { return ("{0} 分钟前" -f [int]$d.TotalMinutes) }
614
656
  if ($d.TotalHours -lt 24) { return ("{0} 小时前" -f [int]$d.TotalHours) }
@@ -753,7 +795,7 @@ function Invoke-GcrTuiKey {
753
795
  }
754
796
  "H" { $script:GcrTui.Help = $true; $script:GcrTui.Dirty = $true }
755
797
  "L" {
756
- $script:GcrLanguage = $(if ($script:GcrLanguage -eq "en-US") { "zh-CN" } else { "en-US" })
798
+ Set-GcrLanguage -Language $(if ($script:GcrLanguage -eq "en-US") { "zh-CN" } else { "en-US" })
757
799
  $script:GcrTui.Dirty = $true
758
800
  }
759
801
  "F" { $script:GcrTui.FailView = -not $script:GcrTui.FailView; $script:GcrTui.Dirty = $true }
@@ -1294,7 +1336,10 @@ function Render-GcrTuiWizard {
1294
1336
  $mark = " "
1295
1337
  if ($sel -eq $i) { $mark = " " + $script:GcrTui.Box.Pointer }
1296
1338
  $val = [string]$it.Value
1297
- if ($it.Kind -eq "bool") { $val = $(if ($it.Flag) { "开" } else { "关" }) }
1339
+ if ($it.Kind -eq "bool") {
1340
+ if ($script:GcrLanguage -eq "en-US") { $val = $(if ($it.Flag) { "On" } else { "Off" }) }
1341
+ else { $val = $(if ($it.Flag) { "开" } else { "关" }) }
1342
+ }
1298
1343
  if ($St.Edit -and $sel -eq $i) {
1299
1344
  $buf = [string]$St.EditBuf
1300
1345
  $cur = [int]$St.EditCur
@@ -1302,7 +1347,8 @@ function Render-GcrTuiWizard {
1302
1347
  if ($cur -gt $buf.Length) { $cur = $buf.Length }
1303
1348
  $val = $buf.Insert($cur, "|")
1304
1349
  }
1305
- $label = Format-GcrCell $it.Label 14
1350
+ $labelText = Convert-GcrText ([string]$it.Label)
1351
+ $label = Format-GcrCell $labelText 20
1306
1352
  $text = $mark + " " + $label + " " + $val
1307
1353
  $col = $c.W
1308
1354
  if ($it.Kind -eq "start") { $col = $c.G + $c.B }
@@ -1310,15 +1356,31 @@ function Render-GcrTuiWizard {
1310
1356
  }
1311
1357
 
1312
1358
  WBorder "mid"
1313
- WRow " 最近任务 (Tab 切换 · Enter 填入)" $c.D
1314
- $recentSlots = $h - $lines.Count - 4
1359
+ $recentSlots = $h - $lines.Count - 5
1315
1360
  if ($recentSlots -lt 1) { $recentSlots = 1 }
1361
+ $recentTop = [int]$St.RecentTop
1362
+ $maxRecentTop = [Math]::Max(0, $recent.Count - $recentSlots)
1363
+ if ($recentTop -gt $maxRecentTop) { $recentTop = $maxRecentTop; $St.RecentTop = $recentTop }
1364
+ if ($St.Focus -eq "recent") {
1365
+ if ($St.RecentSel -lt $recentTop) { $recentTop = [int]$St.RecentSel; $St.RecentTop = $recentTop }
1366
+ if ($St.RecentSel -ge $recentTop + $recentSlots) {
1367
+ $recentTop = [int]$St.RecentSel - $recentSlots + 1
1368
+ $St.RecentTop = $recentTop
1369
+ }
1370
+ }
1371
+ $recentTitle = " 最近任务 (Tab 切换 · Enter 填入)"
1372
+ if ($recent.Count -gt $recentSlots) {
1373
+ $visibleEnd = [Math]::Min($recent.Count, $recentTop + $recentSlots)
1374
+ $recentTitle = $recentTitle + (" [{0}-{1}/{2}]" -f ($recentTop + 1), $visibleEnd, $recent.Count)
1375
+ }
1376
+ WRow $recentTitle $c.D
1316
1377
  if ($recent.Count -eq 0) {
1317
1378
  WRow " (无。完成一次克隆后会出现在这里)" $c.D
1318
1379
  $recentSlots--
1319
1380
  } else {
1320
- $show = [Math]::Min($recent.Count, [Math]::Max(1, $recentSlots))
1321
- for ($r = 0; $r -lt $show; $r++) {
1381
+ $show = [Math]::Min($recent.Count - $recentTop, [Math]::Max(1, $recentSlots))
1382
+ for ($slot = 0; $slot -lt $show; $slot++) {
1383
+ $r = $recentTop + $slot
1322
1384
  $it = $recent[$r]
1323
1385
  $name = [string]$it.outDir
1324
1386
  if ($name) { $name = Split-Path -Leaf $name }
@@ -1427,6 +1489,7 @@ function Show-GcrTuiWizard {
1427
1489
  DryRun = $false
1428
1490
  Sel = 0
1429
1491
  RecentSel = 0
1492
+ RecentTop = 0
1430
1493
  Focus = "form"
1431
1494
  Edit = $false
1432
1495
  EditBuf = ""
@@ -1546,7 +1609,10 @@ function Show-GcrTuiWizard {
1546
1609
  }
1547
1610
  "UpArrow" {
1548
1611
  if ($st.Focus -eq "recent") {
1549
- if ($st.RecentSel -gt 0) { $st.RecentSel-- }
1612
+ if ($st.RecentSel -gt 0) {
1613
+ $st.RecentSel--
1614
+ if ($st.RecentSel -lt $st.RecentTop) { $st.RecentTop = $st.RecentSel }
1615
+ }
1550
1616
  else { $st.Focus = "form"; $st.Sel = 12 }
1551
1617
  } else {
1552
1618
  if ($st.Sel -gt 0) { $st.Sel-- }
@@ -1554,10 +1620,21 @@ function Show-GcrTuiWizard {
1554
1620
  }
1555
1621
  "DownArrow" {
1556
1622
  if ($st.Focus -eq "recent") {
1557
- if ($st.RecentSel -lt ($st.Recent.Count - 1)) { $st.RecentSel++ }
1623
+ if ($st.RecentSel -lt ($st.Recent.Count - 1)) {
1624
+ $st.RecentSel++
1625
+ $recentVisible = [Math]::Max(1, [int](Get-GcrTuiSize).H - 10)
1626
+ if ($st.RecentSel -ge $st.RecentTop + $recentVisible) {
1627
+ $st.RecentTop = $st.RecentSel - $recentVisible + 1
1628
+ }
1629
+ }
1558
1630
  } else {
1559
1631
  if ($st.Sel -lt 12) { $st.Sel++ }
1560
- elseif ($st.Recent.Count -gt 0) { $st.Focus = "recent"; $st.RecentSel = 0 }
1632
+ elseif ($st.Recent.Count -gt 0) {
1633
+ $st.Focus = "recent"
1634
+ $st.RecentSel = [Math]::Min($st.RecentSel, $st.Recent.Count - 1)
1635
+ $recentVisible = [Math]::Max(1, [int](Get-GcrTuiSize).H - 10)
1636
+ $st.RecentTop = [Math]::Max(0, $st.RecentSel - $recentVisible + 1)
1637
+ }
1561
1638
  }
1562
1639
  }
1563
1640
  "K" {
@@ -1605,7 +1682,7 @@ function Show-GcrTuiWizard {
1605
1682
  if ($st.Sel -eq 8) { $st.Verify = -not $st.Verify }
1606
1683
  elseif ($st.Sel -eq 9) { $st.ForceRefetch = -not $st.ForceRefetch }
1607
1684
  elseif ($st.Sel -eq 10) { $st.DryRun = -not $st.DryRun }
1608
- elseif ($st.Sel -eq 11) { $st.Language = $(if ($st.Language -eq "en-US") { "zh-CN" } else { "en-US" }); $script:GcrLanguage = $st.Language }
1685
+ elseif ($st.Sel -eq 11) { $st.Language = $(if ($st.Language -eq "en-US") { "zh-CN" } else { "en-US" }); Set-GcrLanguage -Language $st.Language }
1609
1686
  }
1610
1687
  }
1611
1688
  "Enter" {
@@ -1634,7 +1711,7 @@ function Show-GcrTuiWizard {
1634
1711
  } elseif ($id -eq "verify") { $st.Verify = -not $st.Verify }
1635
1712
  elseif ($id -eq "force") { $st.ForceRefetch = -not $st.ForceRefetch }
1636
1713
  elseif ($id -eq "dry") { $st.DryRun = -not $st.DryRun }
1637
- elseif ($id -eq "language") { $st.Language = $(if ($st.Language -eq "en-US") { "zh-CN" } else { "en-US" }); $script:GcrLanguage = $st.Language }
1714
+ elseif ($id -eq "language") { $st.Language = $(if ($st.Language -eq "en-US") { "zh-CN" } else { "en-US" }); Set-GcrLanguage -Language $st.Language }
1638
1715
  elseif ($id -eq "batch" -or $id -eq "retry") { }
1639
1716
  else {
1640
1717
  $st.Edit = $true
@@ -1667,7 +1744,7 @@ function Show-GcrTuiWizard {
1667
1744
  default {
1668
1745
  if ($k.KeyChar -eq "l" -or $k.KeyChar -eq "L") {
1669
1746
  $st.Language = $(if ($st.Language -eq "en-US") { "zh-CN" } else { "en-US" })
1670
- $script:GcrLanguage = $st.Language
1747
+ Set-GcrLanguage -Language $st.Language
1671
1748
  }
1672
1749
  if ($k.KeyChar -eq "?") { $st.Error = "Enter 编辑 · Space 开关 · Tab 最近任务 · S 开始 · Q 退出" }
1673
1750
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "git-clone-resume",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Resume-friendly partial clone tool for Windows",
5
5
  "bin": {
6
6
  "gcr": "gcr.cmd",