From 18175bf58f8d81e7819d3dc70f377285994527d5 Mon Sep 17 00:00:00 2001
From: wxli
Date: Sun, 18 Aug 2024 00:10:25 +0800
Subject: [PATCH 1/5] feat(menu): add support for tab looping menu
---
module/core/menu/win.ps1 | 55 ++++++++++++++++++++++------------------
1 file changed, 30 insertions(+), 25 deletions(-)
diff --git a/module/core/menu/win.ps1 b/module/core/menu/win.ps1
index b78b4b8..66387aa 100644
--- a/module/core/menu/win.ps1
+++ b/module/core/menu/win.ps1
@@ -493,40 +493,45 @@ Add-Member -InputObject $PSCompletions.menu -MemberType ScriptMethod set_selecti
$Host.UI.RawUI.SetBufferContents(@{ X = $X; Y = $Y }, $LineBuffer)
}
Add-Member -InputObject $PSCompletions.menu -MemberType ScriptMethod move_selection {
- param([int]$count)
+ param([int]$moveDirection)
+
+ $MOVE_UP = -1
+ $MOVE_DOWN = 1
+
+ if ($moveDirection -notin @($MOVE_UP, $MOVE_DOWN)) {
+ throw "Invalid move direction. Use $MOVE_UP for up or $MOVE_DOWN for down."
+ }
+
$is_scroll = $false
$is_move = $false
- if ($this.selected_index + $count -ge 0 -and $this.selected_index + $count -le ($this.filter_list.Count - 1) ) {
- if ($count -gt 0) {
- if ($this.page_current_index -ge $this.page_max_index) {
- $is_scroll = $true
- }
- else {
- $is_move = $true
- }
- }
- else {
- if ($this.page_current_index -le 0) {
- $is_scroll = $true
- }
- else {
- $is_move = $true
- }
- }
+
+ if ($moveDirection -eq $MOVE_DOWN) {
+ $is_move = $this.page_current_index -lt $this.page_max_index
+ }
+ else {
+ $is_move = $this.page_current_index -gt 0
}
+ $is_scroll = !$is_move
+
+ $this.selected_index = ($this.selected_index + $moveDirection + $this.filter_list.Count) % $this.filter_list.Count
+
if ($is_move) {
- $this.page_current_index += $count
- $this.selected_index += $count
- $this.set_selection()
+ $this.page_current_index = ($this.page_current_index + $moveDirection + $this.page_max_index + 1) % ($this.page_max_index + 1)
}
if ($is_scroll) {
- $this.selected_index += $count
- $this.offset += $count
- $this.new_list_buffer($this.offset)
+ if ($moveDirection -eq $MOVE_UP -and $this.selected_index -eq $this.filter_list.Count - 1) {
+ $this.page_current_index += $this.page_max_index
+ }
+ elseif ($moveDirection -eq $MOVE_DOWN -and $this.selected_index -eq 0) {
+ $this.page_current_index -= $this.page_max_index
+ }
+
+ $this.offset = ($this.offset + $moveDirection + $this.filter_list.Count - $this.page_max_index) % ($this.filter_list.Count - $this.page_max_index)
+ $this.new_list_buffer($this.offset)
$this.old_selection = $null
- $this.set_selection()
}
+ $this.set_selection()
}
Add-Member -InputObject $PSCompletions.menu -MemberType ScriptMethod get_prefix {
$prefix = $this.filter_list[-1].CompletionText
From d8b2b6a46767c3df85dc9095f4df6bef451f2fc6 Mon Sep 17 00:00:00 2001
From: abgox
Date: Sun, 18 Aug 2024 09:57:27 +0800
Subject: [PATCH 2/5] refactor(module): update the move_selection method
---
module/core/menu/win.ps1 | 61 ++++++++++++++++++++++++----------------
1 file changed, 37 insertions(+), 24 deletions(-)
diff --git a/module/core/menu/win.ps1 b/module/core/menu/win.ps1
index 66387aa..31c90fb 100644
--- a/module/core/menu/win.ps1
+++ b/module/core/menu/win.ps1
@@ -493,40 +493,53 @@ Add-Member -InputObject $PSCompletions.menu -MemberType ScriptMethod set_selecti
$Host.UI.RawUI.SetBufferContents(@{ X = $X; Y = $Y }, $LineBuffer)
}
Add-Member -InputObject $PSCompletions.menu -MemberType ScriptMethod move_selection {
- param([int]$moveDirection)
+ param([bool]$isDown)
- $MOVE_UP = -1
- $MOVE_DOWN = 1
+ $moveDirection = if ($isDown) { 1 } else { -1 }
- if ($moveDirection -notin @($MOVE_UP, $MOVE_DOWN)) {
- throw "Invalid move direction. Use $MOVE_UP for up or $MOVE_DOWN for down."
+ $is_move = if ($isDown) {
+ $this.page_current_index -lt $this.page_max_index
+ }
+ else {
+ $this.page_current_index -gt 0
}
- $is_scroll = $false
- $is_move = $false
+ $new_selected_index = $this.selected_index + $moveDirection
- if ($moveDirection -eq $MOVE_DOWN) {
- $is_move = $this.page_current_index -lt $this.page_max_index
+ if ($PSCompletions.config.menu_is_loop) {
+ $this.selected_index = ($new_selected_index + $this.filter_list.Count) % $this.filter_list.Count
}
else {
- $is_move = $this.page_current_index -gt 0
+ # Handle no loop
+ $this.selected_index = if ($new_selected_index -lt 0) {
+ 0
+ }
+ elseif ($new_selected_index -ge $this.filter_list.Count) {
+ $this.filter_list.Count - 1
+ }
+ else {
+ $new_selected_index
+ }
}
- $is_scroll = !$is_move
-
- $this.selected_index = ($this.selected_index + $moveDirection + $this.filter_list.Count) % $this.filter_list.Count
if ($is_move) {
- $this.page_current_index = ($this.page_current_index + $moveDirection + $this.page_max_index + 1) % ($this.page_max_index + 1)
+ $this.page_current_index = ($this.page_current_index + $moveDirection) % ($this.page_max_index + 1)
+ if ($this.page_current_index -lt 0) {
+ $this.page_current_index += $this.page_max_index + 1
+ }
}
- if ($is_scroll) {
- if ($moveDirection -eq $MOVE_UP -and $this.selected_index -eq $this.filter_list.Count - 1) {
+ elseif ($PSCompletions.config.menu_is_loop -or ($new_selected_index -ge 0 -and $new_selected_index -lt $this.filter_list.Count)) {
+ if (!$isDown -and $this.selected_index -eq $this.filter_list.Count - 1) {
$this.page_current_index += $this.page_max_index
}
- elseif ($moveDirection -eq $MOVE_DOWN -and $this.selected_index -eq 0) {
+ elseif ($isDown -and $this.selected_index -eq 0) {
$this.page_current_index -= $this.page_max_index
}
- $this.offset = ($this.offset + $moveDirection + $this.filter_list.Count - $this.page_max_index) % ($this.filter_list.Count - $this.page_max_index)
+ $this.offset = ($this.offset + $moveDirection) % ($this.filter_list.Count - $this.page_max_index)
+ if ($this.offset -lt 0) {
+ $this.offset += $this.filter_list.Count - $this.page_max_index
+ }
$this.new_list_buffer($this.offset)
$this.old_selection = $null
@@ -695,14 +708,14 @@ Add-Member -InputObject $PSCompletions.menu -MemberType ScriptMethod show_module
{ $_ -eq 85 -or $_ -eq 80 } {
# 85: Ctrl + u
# 80: Ctrl + p
- $this.move_selection(-1)
+ $this.move_selection($false)
break
}
{ $_ -eq 68 -or $_ -eq 78 } {
# 68: Ctrl + d
# 78: Ctrl + n
- $this.move_selection(1)
+ $this.move_selection($true)
break
}
}
@@ -718,11 +731,11 @@ Add-Member -InputObject $PSCompletions.menu -MemberType ScriptMethod show_module
}
if ($shift_pressed) {
# Up
- $this.move_selection(-1)
+ $this.move_selection($false)
}
else {
# Down
- $this.move_selection(1)
+ $this.move_selection($true)
}
break
}
@@ -743,14 +756,14 @@ Add-Member -InputObject $PSCompletions.menu -MemberType ScriptMethod show_module
# 37: Up
# 38: Left
{ $_ -in @(37, 38) } {
- $this.move_selection(-1)
+ $this.move_selection($false)
break
}
# 向下
# 39: Right
# 40: Down
{ $_ -in @(39, 40) } {
- $this.move_selection(1)
+ $this.move_selection($true)
break
}
# Character/Backspace
From 9625f3bb0079dce97b8bc17ea15c18b5c47f0935 Mon Sep 17 00:00:00 2001
From: abgox
Date: Sun, 18 Aug 2024 10:06:08 +0800
Subject: [PATCH 3/5] feat(module): add menu config menu_is_loop
---
module/PSCompletions.psm1 | 2 +-
module/core/config.ps1 | 1 +
module/core/init.ps1 | 1 +
3 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/module/PSCompletions.psm1 b/module/PSCompletions.psm1
index 3086cd9..b545e6e 100644
--- a/module/PSCompletions.psm1
+++ b/module/PSCompletions.psm1
@@ -692,7 +692,7 @@
return
}
}
- { $_ -in @('menu_enable', 'menu_show_tip', 'menu_list_follow_cursor', 'menu_tip_follow_cursor', 'menu_list_cover_buffer', 'menu_tip_cover_buffer', 'menu_is_prefix_match', 'menu_selection_with_margin', 'enter_when_single', 'menu_completions_sort', 'menu_enhance', 'menu_show_tip_when_enhance') } {
+ { $_ -in @('menu_enable', 'menu_show_tip', 'menu_list_follow_cursor', 'menu_tip_follow_cursor', 'menu_list_cover_buffer', 'menu_tip_cover_buffer', 'menu_is_prefix_match', 'menu_is_loop', 'menu_selection_with_margin', 'enter_when_single', 'menu_completions_sort', 'menu_enhance', 'menu_show_tip_when_enhance') } {
if (!$is_num -or $arg[3] -notin @(1, 0)) {
$cmd_list = $null
$sub_cmd = $arg[3]
diff --git a/module/core/config.ps1 b/module/core/config.ps1
index 21af0ba..f948142 100644
--- a/module/core/config.ps1
+++ b/module/core/config.ps1
@@ -55,6 +55,7 @@ $PSCompletions.default.menu_config = @{
menu_list_margin_right = 0
menu_list_min_width = 10
menu_is_prefix_match = 0
+ menu_is_loop = 1
menu_above_margin_bottom = 0
menu_above_list_max_count = -1
menu_below_list_max_count = -1
diff --git a/module/core/init.ps1 b/module/core/init.ps1
index e1e035c..5e65ad6 100644
--- a/module/core/init.ps1
+++ b/module/core/init.ps1
@@ -45,6 +45,7 @@ $PSCompletions.menu = @{
"menu_list_follow_cursor",
"menu_tip_follow_cursor",
"menu_is_prefix_match",
+ "menu_is_loop",
"enter_when_single",
"menu_selection_with_margin",
"menu_completions_sort"
From 926653352508283a84c2b3a2245feb2e40da0ea6 Mon Sep 17 00:00:00 2001
From: abgox
Date: Sun, 18 Aug 2024 11:19:12 +0800
Subject: [PATCH 4/5] feat(module): update the logic for migrating older
versions
---
module/core/init.ps1 | 51 +++++++++++++++++++++++++++++++++-----------
1 file changed, 39 insertions(+), 12 deletions(-)
diff --git a/module/core/init.ps1 b/module/core/init.ps1
index 5e65ad6..6ae79b9 100644
--- a/module/core/init.ps1
+++ b/module/core/init.ps1
@@ -93,14 +93,27 @@ if (!(Test-Path $PSCompletions.path.config) -and !(Test-Path $PSCompletions.path
if ($old_version -match "^\d+\.\d.*" -and $old_version -ge "4") {
$old_version_dir = Join-Path (Split-Path $this.path.root -Parent) $old_version
if (!(Test-Path $this.path.completions)) { New-Item -ItemType Directory $this.path.completions > $null }
- foreach ($_ in Get-ChildItem "$($old_version_dir)/completions" -ErrorAction SilentlyContinue) {
- Move-Item $_.FullName $this.path.completions -Force -ErrorAction SilentlyContinue
+ $PSCompletions.old_psc = @{}
+ foreach ($_ in Get-ChildItem "$($old_version_dir)/completions" -Directory -ErrorAction SilentlyContinue) {
+ if ($_.Name -eq "psc") {
+ $PSCompletions.old_psc.path = "$($old_version_dir)/completions/psc"
+ $PSCompletions.old_psc.alias = (Get-Content "$($old_version_dir)/completions/psc/alias.txt" -ErrorAction SilentlyContinue).Where({ $_ -ne '' })
+ $old_psc_guid = Get-Content "$($old_version_dir)/completions/psc/guid.txt" -Raw -ErrorAction SilentlyContinue
+ if ($old_psc_guid) { $PSCompletions.old_psc.guid = $old_psc_guid.Trim() }
+ }
+ else {
+ Move-Item $_.FullName $this.path.completions -Force -ErrorAction SilentlyContinue
+ }
}
Move-Item "$($old_version_dir)/config.json" $this.path.config -Force -ErrorAction SilentlyContinue
+ Move-Item "$($old_version_dir)/completions.json" $this.path.completions_json -Force -ErrorAction SilentlyContinue
}
}
}
$PSCompletions.move_old_version()
+ if (!(Test-Path $PSCompletions.path.config) -and !(Test-Path $PSCompletions.path.completions)) {
+ $PSCompletions.is_first_init = $true
+ }
}
. $PSScriptRoot\config.ps1
@@ -418,11 +431,12 @@ Add-Member -InputObject $PSCompletions -MemberType ScriptMethod download_file {
Add-Member -InputObject $PSCompletions -MemberType ScriptMethod add_completion {
param (
[string]$completion,
- [bool]$log = $true
+ [bool]$log = $true,
+ [bool]$is_update = $true
)
$url = "$($this.url)/completions/$($completion)"
- $is_update = Test-Path "$($this.path.completions)/$($completion)"
+ $is_update = (Test-Path "$($this.path.completions)/$($completion)") -and $is_update
$completion_dir = Join-Path $this.path.completions $completion
@@ -575,15 +589,28 @@ Add-Member -InputObject $PSCompletions -MemberType ScriptMethod init_data {
$this.info = ($this.get_raw_content($path_language) | ConvertFrom-Json).info
}
else {
- $this.ensure_dir("$($this.path.completions)/psc")
- $this.ensure_dir("$($this.path.completions)/psc/language")
- $language = $this.get_language('psc')
- $path_language = "$($this.path.completions)/psc/language/$($language).json"
+ if ($PSCompletions.old_psc.guid) {
+ $psc_guid = (Invoke-WebRequest "$($this.url)/completions/psc/guid.txt").Content.Trim()
+ }
+ if ($psc_guid -and $PSCompletions.old_psc.guid -eq $psc_guid) {
+ Move-Item $PSCompletions.old_psc.path $PSCompletions.path.completions -Force
+ $language = $this.get_language('psc')
+ $path_language = "$($this.path.completions)/psc/language/$($language).json"
+ $this.info = ($this.get_raw_content($path_language) | ConvertFrom-Json).info
+ }
+ else {
+ $this.ensure_dir("$($this.path.completions)/psc")
+ $this.ensure_dir("$($this.path.completions)/psc/language")
+ $language = $this.get_language('psc')
+ $path_language = "$($this.path.completions)/psc/language/$($language).json"
- $this.download_file("$($this.url)/completions/psc/language/$($language).json", $path_language)
- $this.info = ($this.get_raw_content($path_language) | ConvertFrom-Json).info
- $this.add_completion('psc')
- $this.is_first_init = $true
+ $this.download_file("$($this.url)/completions/psc/language/$($language).json", $path_language)
+ $this.info = ($this.get_raw_content($path_language) | ConvertFrom-Json).info
+ $this.add_completion('psc', $true, $false)
+ if ($PSCompletions.old_psc.alias) {
+ $PSCompletions.old_psc.alias | Out-File "$($PSCompletions.path.completions)/psc/alias.txt" -encoding utf8 -Force
+ }
+ }
}
if (!(Test-Path $PSCompletions.path.completions_json) -and !($this.download_list())) {
From 6f52019115d0a86a93545a0e7de52d0fa9c30dbe Mon Sep 17 00:00:00 2001
From: abgox
Date: Sun, 18 Aug 2024 12:03:26 +0800
Subject: [PATCH 5/5] feat(module): update version to 4.3.1
---
module/CHANGELOG-CN.md | 10 +++++--
module/CHANGELOG.json | 25 +++++++++++++---
module/CHANGELOG.md | 10 +++++--
module/PSCompletions.psd1 | 2 +-
module/PSCompletions.psm1 | 2 +-
module/core/completion/utils.ps1 | 49 ++++++++++++++------------------
module/core/init.ps1 | 2 +-
module/core/menu/win.ps1 | 2 +-
module/core/utils/Core.ps1 | 10 +++----
module/core/utils/Desktop.ps1 | 10 +++----
module/log.json | 22 +++++++++++---
module/version.txt | 2 +-
12 files changed, 89 insertions(+), 57 deletions(-)
diff --git a/module/CHANGELOG-CN.md b/module/CHANGELOG-CN.md
index 17bac59..f61009a 100644
--- a/module/CHANGELOG-CN.md
+++ b/module/CHANGELOG-CN.md
@@ -3,6 +3,12 @@
简体中文
+## 4.3.1 (2024/8/18)
+
+- 添加一个配置项 `menu_is_loop`, 控制是否循环显示菜单,默认值为 `1`
+ - 禁用它: `psc menu config menu_is_loop 0`
+- 优化旧版本的迁移逻辑
+
## 4.3.0 (2024/8/15)
- 修复在 `Windows PowerShell` 中的模块更新问题
@@ -83,7 +89,7 @@
- 设置: `psc menu config menu_trigger_key `
2. `menu_enhance`: 默认值为 `1`, 用于设置是否启用补全菜单增强功能
- - 设置: `psc menu config menu_enhance 1`
+ - 禁用它: `psc menu config menu_enhance 0`
- 开启后,`PSCompletions` 会拦截所有补全,并使用 `PSCompletions` 提供的补全菜单渲染补全
- 比如,`PowerShell` 中的 `Get-*`,`Set-*` 等命令都会使用 `PSCompletions` 提供的补全菜单渲染补全
- 需要注意,此配置项生效的前提是启用了 `menu_enable`
@@ -91,7 +97,7 @@
3. `menu_show_tip_when_enhance`: 默认值为 `1`, 设置不是通过 `psc add` 添加的补全,是否显示命令提示信息
- - 设置: `psc menu config menu_show_tip_when_enhance 1`
+ - 禁用它: `psc menu config menu_show_tip_when_enhance 0`
- 和 `menu_enhance` 一起使用
- 解决了多字节文字可能导致菜单出现部分渲染错误的问题
diff --git a/module/CHANGELOG.json b/module/CHANGELOG.json
index b1cd22c..0e3b739 100644
--- a/module/CHANGELOG.json
+++ b/module/CHANGELOG.json
@@ -1,4 +1,21 @@
[
+ {
+ "version": "4.3.1",
+ "info": {
+ "zh-CN": [
+ "更新(2024/8/18)\n",
+ "- 添加一个配置项 <@Magenta>menu_is_loop<@Blue>, 控制是否循环显示菜单,默认值为 <@Magenta>1<@Blue>\n",
+ " - 禁用它: <@Magenta>psc menu config menu_is_loop 0<@Blue>\n",
+ "- 优化旧版本的迁移逻辑\n"
+ ],
+ "en-US": [
+ "Update(2024/8/18)\n",
+ "- Add a configuration item <@Magenta>menu_is_loop<@Blue>, controlling whether the menu is looped, with a default value of <@Magenta>1<@Blue>.\n",
+ " - Disable it: <@Magenta>psc menu config menu_is_loop 0<@Blue>\n",
+ "- Optimize the migration logic of old versions.\n"
+ ]
+ }
+ },
{
"version": "4.3.0",
"info": {
@@ -195,7 +212,7 @@
" 1. <@Magenta>menu_trigger_key<@Blue>: 默认值为 <@Magenta>Tab<@Blue>, 用于设置补全菜单的触发按键\n",
" - 设置: <@Magenta>psc menu config menu_trigger_key <@Blue>\n",
" 2. <@Magenta>menu_enhance<@Blue>: 默认值为 <@Magenta>1<@Blue>, 用于设置是否启用补全菜单增强功能\n",
- " - 设置: <@Magenta>psc menu config menu_enhance 1<@Blue>\n",
+ " - 禁用它: <@Magenta>psc menu config menu_enhance 0<@Blue>\n",
" - 开启后,<@Magenta>PSCompletions<@Blue> 会拦截所有补全,并使用 <@Magenta>PSCompletions<@Blue> 提供的补全菜单渲染补全\n",
" - 比如,<@Magenta>PowerShell<@Blue> 中的 <@Magenta>Get-*<@Blue>,<@Magenta>Set-*<@Blue> 等命令都会使用 <@Magenta>PSCompletions<@Blue> 提供的补全菜单渲染补全\n",
" - 需要注意,此配置项生效的前提是启用了 <@Magenta>menu_enable<@Blue>\n",
@@ -203,7 +220,7 @@
" - Github: https://github.com/abgox/PSCompletions/blob/main/README-CN.md#关于菜单增强\n",
" - Gitee: https://gitee.com/abgox/PSCompletions/blob/main/README-CN.md#关于菜单增强\n",
" 3. <@Magenta>menu_show_tip_when_enhance<@Blue>: 默认值为 <@Magenta>1<@Blue>, 设置不是通过 <@Magenta>psc add<@Blue> 添加的补全,是否显示命令提示信息\n",
- " - 设置: <@Magenta>psc menu config menu_show_tip_when_enhance 1<@Blue>\n",
+ " - 禁用它: <@Magenta>psc menu config menu_show_tip_when_enhance 0<@Blue>\n",
" - 和 <@Magenta>menu_enhance<@Blue> 一起使用\n",
" - 解决了多字节文字可能导致菜单出现部分渲染错误的问题\n",
" - 这配合 <@Magenta>menu_enhance<@Blue> 很有用\n",
@@ -221,7 +238,7 @@
" 1. <@Magenta>menu_trigger_key<@Blue>: Default value is <@Magenta>Tab<@Blue>, which is used to set the trigger key of the completion menu.\n",
" - Setting: <@Magenta>psc menu config menu_trigger_key <@Blue>\n",
" 2. <@Magenta>menu_enhance<@Blue>: Default value is <@Magenta>1<@Blue>, which is used to to enable or disable the enhanced completion menu feature.\n",
- " - Setting: <@Magenta>psc menu config menu_enhance 1<@Blue>\n",
+ " - Disable it: <@Magenta>psc menu config menu_enhance 0<@Blue>\n",
" - When enabled, <@Magenta>PSCompletions<@Blue> will intercept all completions and uses the completion menu provided by <@Magenta>PSCompletions<@Blue> to render completions.\n",
" - For example, commands such as <@Magenta>Get-*<@Blue>, <@Magenta>Set-*<@Blue> in <@Magenta>PowerShell<@Blue> will use the completion menu provided by <@Magenta>PSCompletions<@Blue> to render the completion.\n",
" - Note: This setting only takes effect if <@Magenta>menu_enable<@Blue> is also enabled.\n",
@@ -229,7 +246,7 @@
" - Github: https://github.com/abgox/PSCompletions/blob/main/README.md#about-menu-enhance\n",
" - Gitee: https://gitee.com/abgox/PSCompletions/blob/main/README.md#about-menu-enhance\n",
" 3. <@Magenta>menu_show_tip_when_enhance<@Blue>: Default value is <@Magenta>1<@Blue>, which is used to control whether to show command tips for completions that are not added through <@Magenta>psc add<@Blue>.\n",
- " - Setting: <@Magenta>psc menu config menu_show_tip_when_enhance 1<@Blue>\n",
+ " - Disable it: <@Magenta>psc menu config menu_show_tip_when_enhance 0<@Blue>\n",
" - Used together with <@Magenta>menu_enhance<@Blue>.\n",
" - Fix an issue where multi-byte characters(such as Chinese characters) could cause partial rendering errors in the menu.\n",
" - This is useful with <@Magenta>menu_enhance<@Blue>.\n",
diff --git a/module/CHANGELOG.md b/module/CHANGELOG.md
index e805c31..e23f640 100644
--- a/module/CHANGELOG.md
+++ b/module/CHANGELOG.md
@@ -3,6 +3,12 @@
English
+## 4.3.1 (2024/8/18)
+
+- Add a configuration item `menu_is_loop`, controlling whether the menu is looped, with a default value of `1`.
+ - Disable it: `psc menu config menu_is_loop 0`
+- Optimize the migration logic of old versions.
+
## 4.3.0 (2024/8/15)
- Fix module update issue in `Windows PowerShell`.
@@ -80,13 +86,13 @@
1. `menu_trigger_key`: Default value is `Tab`, which is used to set the trigger key of the completion menu.
- Setting: `psc menu config menu_trigger_key `
2. `menu_enhance`: Default value is `1`, which is used to enable or disable the enhanced completion menu feature.
- - Setting: `psc menu config menu_enhance 1`
+ - Disable it: `psc menu config menu_enhance 0`
- When enabled, `PSCompletions` will intercept all completions and uses the completion menu provided by `PSCompletions` to render completions.
- For example, commands such as `Get-*`, `Set-*` in `PowerShell` will use the completion menu provided by `PSCompletions` to render the completion.
- Note: This setting only takes effect if `menu_enable` is also enabled.
- [About menu enhance](../README.md#about-menu-enhance)
3. `menu_show_tip_when_enhance`: Default value is `1`, which is used to control whether to show command tips for completions that are not added through `psc add`.
- - Setting: `psc menu config menu_show_tip_when_enhance 1`
+ - Disable it: `psc menu config menu_show_tip_when_enhance 0`
- Use together with `menu_enhance`.
- Fix an issue where multi-byte characters(such as Chinese characters) could cause partial rendering errors in the menu.
diff --git a/module/PSCompletions.psd1 b/module/PSCompletions.psd1
index 46cbac8..511e30c 100644
--- a/module/PSCompletions.psd1
+++ b/module/PSCompletions.psd1
@@ -10,7 +10,7 @@
RootModule = 'PSCompletions.psm1'
- ModuleVersion = '4.3.0'
+ ModuleVersion = '4.3.1'
GUID = '00929632-527d-4dab-a5b3-21197faccd05'
diff --git a/module/PSCompletions.psm1 b/module/PSCompletions.psm1
index b545e6e..1cc30f7 100644
--- a/module/PSCompletions.psm1
+++ b/module/PSCompletions.psm1
@@ -4,7 +4,7 @@
# ? 由于此处使用 $PSCompletions.replace_content 会导致其无法使用外部变量,所以重新定义一个函数以供使用
function _replace {
param ($data, $separator = '')
- $data = ($data -join $separator)
+ $data = $data -join $separator
$pattern = '\{\{(.*?(\})*)(?=\}\})\}\}'
$matches = [regex]::Matches($data, $pattern)
foreach ($match in $matches) {
diff --git a/module/core/completion/utils.ps1 b/module/core/completion/utils.ps1
index 18a4911..cc857b0 100644
--- a/module/core/completion/utils.ps1
+++ b/module/core/completion/utils.ps1
@@ -17,15 +17,13 @@
$common_options = @()
$common_options_with_next = @()
- if ($PSCompletions.data.$root.common_options) {
- foreach ($_ in $PSCompletions.data.$root.common_options) {
- foreach ($a in $_.alias) {
- $common_options += $a
- if ($_.next) { $common_options_with_next += $a }
- }
- $common_options += $_.name
- if ($_.next) { $common_options_with_next += $_.name }
+ foreach ($_ in $PSCompletions.data.$root.common_options) {
+ foreach ($a in $_.alias) {
+ $common_options += $a
+ if ($_.next) { $common_options_with_next += $a }
}
+ $common_options += $_.name
+ if ($_.next) { $common_options_with_next += $_.name }
}
$PSCompletions.temp_WriteSpaceTab = @()
$PSCompletions.temp_WriteSpaceTab += $common_options_with_next
@@ -42,19 +40,16 @@
$runspacePool.Open()
$runspaces = @()
- $tasks = @()
- if ($PSCompletions.data.$root.root) {
- $tasks += @{
+ $tasks = @(
+ @{
node = $PSCompletions.data.$root.root
isOption = $false
- }
- }
- if ($PSCompletions.data.$root.options) {
- $tasks += @{
+ },
+ @{
node = $PSCompletions.data.$root.options
isOption = $true
}
- }
+ )
foreach ($task in $tasks) {
$runspace = [powershell]::Create().AddScript({
param($obj, $PSCompletions)
@@ -66,7 +61,7 @@
}
function _replace {
param ($data, $separator = '')
- $data = ($data -join $separator)
+ $data = $data -join $separator
$pattern = '\{\{(.*?(\})*)(?=\}\})\}\}'
$matches = [regex]::Matches($data, $pattern)
foreach ($match in $matches) {
@@ -135,8 +130,8 @@
# 判断别名出现的位置
$index = (($pre + $pad + $_.name) -split ' ').Length - 1
# 用这个位置创建一个数组,将所有在这个位置出现的别名全部写入这个数组
- if (!($_alias_map[$index])) { $_alias_map[$index] = @() }
- $_alias_map[$index] += @{
+ if (!$_alias_map.$index) { $_alias_map.$index = @() }
+ $_alias_map.$index += @{
name = $_.name
alias = $a
}
@@ -172,11 +167,11 @@
$PSCompletions.temp_WriteSpaceTab += $result.temp.WriteSpaceTab
$PSCompletions.temp_WriteSpaceTab_and_SpaceTab += $result.temp.WriteSpaceTab_and_SpaceTab
foreach ($a in $result.alias_map.Keys) {
- if ($alias_map[$a]) {
- $alias_map[$a] += $result.alias_map[$a]
+ if ($alias_map.$a) {
+ $alias_map.$a += $result.alias_map.$a
}
else {
- $alias_map[$a] = $result.alias_map[$a]
+ $alias_map.$a = $result.alias_map.$a
}
}
}
@@ -232,12 +227,10 @@
# 循环命令的长度,针对每一个位置去 $alias_map 找到对应的数组,然后把数组里的值拿出来比对,如果有匹配的,替换掉原来的命令名
# 用位置的好处是,这样遍历是依赖于命令的长度,而命令长度一般不长
for ($i = 0; $i -lt $filter_input_arr.Count; $i++) {
- if ($alias_map[$i]) {
- foreach ($obj in $alias_map[$i]) {
- if ($obj.alias -eq $filter_input_arr[$i]) {
- $alias_input_arr[$i] = $obj.name
- break
- }
+ foreach ($obj in $alias_map.$i) {
+ if ($obj.alias -eq $filter_input_arr[$i]) {
+ $alias_input_arr[$i] = $obj.name
+ break
}
}
}
diff --git a/module/core/init.ps1 b/module/core/init.ps1
index 6ae79b9..4b2f4aa 100644
--- a/module/core/init.ps1
+++ b/module/core/init.ps1
@@ -3,7 +3,7 @@
New-Variable -Name PSCompletions -Value @{} -Option ReadOnly
# 模块版本
-$PSCompletions.version = '4.3.0'
+$PSCompletions.version = '4.3.1'
$PSCompletions.path = @{}
$PSCompletions.path.root = Split-Path $PSScriptRoot -Parent
$PSCompletions.path.completions = Join-Path $PSCompletions.path.root 'completions'
diff --git a/module/core/menu/win.ps1 b/module/core/menu/win.ps1
index 31c90fb..b219106 100644
--- a/module/core/menu/win.ps1
+++ b/module/core/menu/win.ps1
@@ -52,7 +52,7 @@
}
function _replace {
param ($data, $separator = '')
- $data = ($data -join $separator)
+ $data = $data -join $separator
$pattern = '\{\{(.*?(\})*)(?=\}\})\}\}'
$matches = [regex]::Matches($data, $pattern)
foreach ($match in $matches) {
diff --git a/module/core/utils/Core.ps1 b/module/core/utils/Core.ps1
index afb3deb..7d91ffd 100644
--- a/module/core/utils/Core.ps1
+++ b/module/core/utils/Core.ps1
@@ -54,12 +54,10 @@ Add-Member -InputObject $PSCompletions -MemberType ScriptMethod start_job {
$json = get_raw_content $path | ConvertFrom-Json
$path = "$($PSCompletions.path.completions)/$($_)/language/$($json.language[0]).json"
$json = get_raw_content $path | ConvertFrom-Json -AsHashtable
- if ($json.config) {
- foreach ($item in $json.config) {
- if ($PSCompletions.config.comp_config.$_.$($item.name) -in @('', $null)) {
- $PSCompletions.config.comp_config.$_.$($item.name) = $item.value
- $need_update_config = $true
- }
+ foreach ($item in $json.config) {
+ if ($PSCompletions.config.comp_config.$_.$($item.name) -in @('', $null)) {
+ $PSCompletions.config.comp_config.$_.$($item.name) = $item.value
+ $need_update_config = $true
}
}
}
diff --git a/module/core/utils/Desktop.ps1 b/module/core/utils/Desktop.ps1
index 3331173..f3f9fc0 100644
--- a/module/core/utils/Desktop.ps1
+++ b/module/core/utils/Desktop.ps1
@@ -146,12 +146,10 @@ Add-Member -InputObject $PSCompletions -MemberType ScriptMethod start_job {
$json = get_raw_content $path | ConvertFrom-Json
$path = "$($PSCompletions.path.completions)/$($_)/language/$($json.language[0]).json"
$json = get_raw_content $path | convert_from_json_to_hashtable
- if ($json.config) {
- foreach ($item in $json.config) {
- if ($PSCompletions.config.comp_config.$_.$($item.name) -in @('', $null)) {
- $PSCompletions.config.comp_config.$_.$($item.name) = $item.value
- $need_update_config = $true
- }
+ foreach ($item in $json.config) {
+ if ($PSCompletions.config.comp_config.$_.$($item.name) -in @('', $null)) {
+ $PSCompletions.config.comp_config.$_.$($item.name) = $item.value
+ $need_update_config = $true
}
}
}
diff --git a/module/log.json b/module/log.json
index fd5b90d..aa8a87d 100644
--- a/module/log.json
+++ b/module/log.json
@@ -1,4 +1,18 @@
{
+ "4.3.1": {
+ "zh-CN": [
+ "更新(2024/8/18)\n",
+ "- 添加一个配置项 <@Magenta>menu_is_loop<@Blue>, 控制是否循环显示菜单,默认值为 <@Magenta>1<@Blue>\n",
+ " - 禁用它: <@Magenta>psc menu config menu_is_loop 0<@Blue>\n",
+ "- 优化旧版本的迁移逻辑\n"
+ ],
+ "en-US": [
+ "Update(2024/8/18)\n",
+ "- Add a configuration item <@Magenta>menu_is_loop<@Blue>, controlling whether the menu is looped, with a default value of <@Magenta>1<@Blue>.\n",
+ " - Disable it: <@Magenta>psc menu config menu_is_loop 0<@Blue>\n",
+ "- Optimize the migration logic of old versions.\n"
+ ]
+ },
"4.3.0": {
"zh-CN": [
"修复(2024/8/15)\n",
@@ -163,7 +177,7 @@
" 1. <@Magenta>menu_trigger_key<@Blue>: 默认值为 <@Magenta>Tab<@Blue>, 用于设置补全菜单的触发按键\n",
" - 设置: <@Magenta>psc menu config menu_trigger_key <@Blue>\n",
" 2. <@Magenta>menu_enhance<@Blue>: 默认值为 <@Magenta>1<@Blue>, 用于设置是否启用补全菜单增强功能\n",
- " - 设置: <@Magenta>psc menu config menu_enhance 1<@Blue>\n",
+ " - 禁用它: <@Magenta>psc menu config menu_enhance 0<@Blue>\n",
" - 开启后,<@Magenta>PSCompletions<@Blue> 会拦截所有补全,并使用 <@Magenta>PSCompletions<@Blue> 提供的补全菜单渲染补全\n",
" - 比如,<@Magenta>PowerShell<@Blue> 中的 <@Magenta>Get-*<@Blue>,<@Magenta>Set-*<@Blue> 等命令都会使用 <@Magenta>PSCompletions<@Blue> 提供的补全菜单渲染补全\n",
" - 需要注意,此配置项生效的前提是启用了 <@Magenta>menu_enable<@Blue>\n",
@@ -171,7 +185,7 @@
" - Github: https://github.com/abgox/PSCompletions/blob/main/README-CN.md#关于菜单增强\n",
" - Gitee: https://gitee.com/abgox/PSCompletions/blob/main/README-CN.md#关于菜单增强\n",
" 3. <@Magenta>menu_show_tip_when_enhance<@Blue>: 默认值为 <@Magenta>1<@Blue>, 设置不是通过 <@Magenta>psc add<@Blue> 添加的补全,是否显示命令提示信息\n",
- " - 设置: <@Magenta>psc menu config menu_show_tip_when_enhance 1<@Blue>\n",
+ " - 禁用它: <@Magenta>psc menu config menu_show_tip_when_enhance 0<@Blue>\n",
" - 和 <@Magenta>menu_enhance<@Blue> 一起使用\n",
" - 解决了多字节文字可能导致菜单出现部分渲染错误的问题\n",
" - 这配合 <@Magenta>menu_enhance<@Blue> 很有用\n",
@@ -189,7 +203,7 @@
" 1. <@Magenta>menu_trigger_key<@Blue>: Default value is <@Magenta>Tab<@Blue>, which is used to set the trigger key of the completion menu.\n",
" - Setting: <@Magenta>psc menu config menu_trigger_key <@Blue>\n",
" 2. <@Magenta>menu_enhance<@Blue>: Default value is <@Magenta>1<@Blue>, which is used to to enable or disable the enhanced completion menu feature.\n",
- " - Setting: <@Magenta>psc menu config menu_enhance 1<@Blue>\n",
+ " - Disable it: <@Magenta>psc menu config menu_enhance 0<@Blue>\n",
" - When enabled, <@Magenta>PSCompletions<@Blue> will intercept all completions and uses the completion menu provided by <@Magenta>PSCompletions<@Blue> to render completions.\n",
" - For example, commands such as <@Magenta>Get-*<@Blue>, <@Magenta>Set-*<@Blue> in <@Magenta>PowerShell<@Blue> will use the completion menu provided by <@Magenta>PSCompletions<@Blue> to render the completion.\n",
" - Note: This setting only takes effect if <@Magenta>menu_enable<@Blue> is also enabled.\n",
@@ -197,7 +211,7 @@
" - Github: https://github.com/abgox/PSCompletions/blob/main/README.md#about-menu-enhance\n",
" - Gitee: https://gitee.com/abgox/PSCompletions/blob/main/README.md#about-menu-enhance\n",
" 3. <@Magenta>menu_show_tip_when_enhance<@Blue>: Default value is <@Magenta>1<@Blue>, which is used to control whether to show command tips for completions that are not added through <@Magenta>psc add<@Blue>.\n",
- " - Setting: <@Magenta>psc menu config menu_show_tip_when_enhance 1<@Blue>\n",
+ " - Disable it: <@Magenta>psc menu config menu_show_tip_when_enhance 0<@Blue>\n",
" - Used together with <@Magenta>menu_enhance<@Blue>.\n",
" - Fix an issue where multi-byte characters(such as Chinese characters) could cause partial rendering errors in the menu.\n",
" - This is useful with <@Magenta>menu_enhance<@Blue>.\n",
diff --git a/module/version.txt b/module/version.txt
index 8089590..f77856a 100644
--- a/module/version.txt
+++ b/module/version.txt
@@ -1 +1 @@
-4.3.0
+4.3.1