Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 58bd2af

Browse files
committed
Added option to disable command line auto completion
1 parent 38232c6 commit 58bd2af

6 files changed

Lines changed: 58 additions & 3 deletions

File tree

actions.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ func actionFindFile(pf *PanelsFrame) {
854854
vtui.FrameManager.Push(dlg)
855855
}
856856
func actionPanelSettings(pf *PanelsFrame) {
857-
dlg := vtui.NewCenteredDialog(44, 13, Msg("PanelSettings.Title"))
857+
dlg := vtui.NewCenteredDialog(44, 15, Msg("PanelSettings.Title"))
858858
dlg.ShowClose = true
859859

860860
chkHidden := vtui.NewCheckbox(0, 0, Msg("PanelSettings.ShowHidden"), false)
@@ -873,6 +873,10 @@ func actionPanelSettings(pf *PanelsFrame) {
873873
chkCursor.State = 0
874874
if AppConfig.KeepTerminalCursor { chkCursor.State = 1 }
875875

876+
chkCmdAc := vtui.NewCheckbox(0, 0, "Enable command line &auto-completion", false)
877+
chkCmdAc.State = 0
878+
if AppConfig.CommandLineAutoComplete { chkCmdAc.State = 1 }
879+
876880
btnOk := vtui.NewButton(0, 0, Msg("vtui.Ok"))
877881
btnOk.IsDefault = true
878882
btnCancel := vtui.NewButton(0, 0, Msg("vtui.Cancel"))
@@ -881,14 +885,16 @@ func actionPanelSettings(pf *PanelsFrame) {
881885
dlg.AddItem(chkHighlight)
882886
dlg.AddItem(chkPaths)
883887
dlg.AddItem(chkCursor)
888+
dlg.AddItem(chkCmdAc)
884889
dlg.AddItem(btnOk)
885890
dlg.AddItem(btnCancel)
886891

887-
vbox := vtui.NewVBoxLayout(dlg.X1+2, dlg.Y1+2, 44-4, 13-4)
892+
vbox := vtui.NewVBoxLayout(dlg.X1+2, dlg.Y1+2, 44-4, 15-4)
888893
vbox.Add(chkHidden, vtui.Margins{}, vtui.AlignLeft)
889894
vbox.Add(chkHighlight, vtui.Margins{Top: 1}, vtui.AlignLeft)
890895
vbox.Add(chkPaths, vtui.Margins{Top: 1}, vtui.AlignLeft)
891896
vbox.Add(chkCursor, vtui.Margins{Top: 1}, vtui.AlignLeft)
897+
vbox.Add(chkCmdAc, vtui.Margins{Top: 1}, vtui.AlignLeft)
892898

893899
hbox := vtui.NewHBoxLayout(0, 0, 44-4, 1)
894900
hbox.HorizontalAlign = vtui.AlignCenter
@@ -905,6 +911,7 @@ func actionPanelSettings(pf *PanelsFrame) {
905911
AppConfig.HighlightDir = chkHighlight.State == 1
906912
AppConfig.SavePanelPaths = chkPaths.State == 1
907913
AppConfig.KeepTerminalCursor = chkCursor.State == 1
914+
AppConfig.CommandLineAutoComplete = chkCmdAc.State == 1
908915
vtui.ManageCursorStyle = !AppConfig.KeepTerminalCursor
909916
SaveConfig()
910917
dlg.Close()

actions_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,20 @@ func TestActionPanelSettings_Flow(t *testing.T) {
407407
t.Error("Save paths checkbox not found in Panel Settings dialog")
408408
}
409409

410+
// Проверяем наличие чекбокса автодополнения
411+
foundAc := false
412+
for _, itm := range dlg.GetChildren() {
413+
if chk, ok := itm.(*vtui.Checkbox); ok {
414+
if strings.Contains(strings.ToLower(chk.GetText()), "auto-completion") {
415+
foundAc = true
416+
break
417+
}
418+
}
419+
}
420+
if !foundAc {
421+
t.Error("Command line auto-completion checkbox not found in Panel Settings dialog")
422+
}
423+
410424
top.SetExitCode(-1)
411425
vtui.FrameManager.Pop()
412426
}

command_line.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func (cl *CommandLine) ProcessKey(e *vtinput.InputEvent) bool {
9898
}
9999

100100
// AutoComplete logic:
101-
if handled && cl.Edit.HistoryPos == -1 && !cl.IsEmpty() {
101+
if AppConfig.CommandLineAutoComplete && handled && cl.Edit.HistoryPos == -1 && !cl.IsEmpty() {
102102
isChar := e.Char != 0
103103
isDel := e.VirtualKeyCode == vtinput.VK_BACK || e.VirtualKeyCode == vtinput.VK_DELETE
104104
if isChar || isDel {

command_line_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,30 @@ func TestCommandLine_HistoryBoundaries(t *testing.T) {
124124
t.Error("HistoryDown should stay at -1 when already empty")
125125
}
126126
}
127+
128+
func TestCommandLine_AutoCompleteDisabled(t *testing.T) {
129+
vtui.FrameManager.Init(vtui.NewSilentScreenBuf())
130+
SetDefaultF4Palette()
131+
132+
cl := NewCommandLine("> ")
133+
cl.SetPosition(0, 0, 10, 0)
134+
cl.Edit.History = []string{"ls", "long-command"}
135+
136+
// 1. Выключаем глобальную настройку
137+
oldCfg := AppConfig
138+
AppConfig.CommandLineAutoComplete = false
139+
defer func() { AppConfig = oldCfg }()
140+
141+
// 2. Симулируем ввод буквы 'l'
142+
cl.ProcessKey(&vtinput.InputEvent{
143+
Type: vtinput.KeyEventType,
144+
KeyDown: true,
145+
Char: 'l',
146+
})
147+
148+
// 3. Проверяем, что меню автодополнения НЕ появилось в FrameManager
149+
top := vtui.FrameManager.GetTopFrame()
150+
if _, isAc := top.(*vtui.AutoCompleteMenu); isAc {
151+
t.Error("AutoCompleteMenu was shown even though CommandLineAutoComplete is false")
152+
}
153+
}

config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type F4Config struct {
1414
HighlightDir bool
1515
SavePanelPaths bool
1616
KeepTerminalCursor bool
17+
CommandLineAutoComplete bool
1718
EditorAutoComplete bool
1819
EditorAutoCompleteMask string
1920
EditorExpandTabs int
@@ -55,6 +56,7 @@ func LoadConfig() {
5556
AppConfig.HighlightDir = ini.GetString("Panel", "HighlightDir", "0") == "1"
5657
AppConfig.SavePanelPaths = ini.GetString("Panel", "SavePanelPaths", "1") == "1"
5758
AppConfig.KeepTerminalCursor = ini.GetString("Panel", "KeepTerminalCursor", "0") == "1"
59+
AppConfig.CommandLineAutoComplete = ini.GetString("Panel", "CommandLineAutoComplete", "1") == "1"
5860

5961
AppConfig.EditorAutoComplete = ini.GetString("Editor", "AutoComplete", "1") == "1"
6062
AppConfig.EditorAutoCompleteMask = ini.GetString("Editor", "AutoCompleteMask", "*.go;*.c;*.cpp;*.h;*.hpp;*.py;*.js;*.ts;*.rs;*.java;*.sh;*.txt;*.md;*.html;*.css;*.json")
@@ -81,6 +83,7 @@ func SaveConfig() {
8183
sb.WriteString(fmt.Sprintf("HighlightDir = %d\n", map[bool]int{true: 1, false: 0}[AppConfig.HighlightDir]))
8284
sb.WriteString(fmt.Sprintf("SavePanelPaths = %d\n", map[bool]int{true: 1, false: 0}[AppConfig.SavePanelPaths]))
8385
sb.WriteString(fmt.Sprintf("KeepTerminalCursor = %d\n", map[bool]int{true: 1, false: 0}[AppConfig.KeepTerminalCursor]))
86+
sb.WriteString(fmt.Sprintf("CommandLineAutoComplete = %d\n", map[bool]int{true: 1, false: 0}[AppConfig.CommandLineAutoComplete]))
8487

8588
sb.WriteString("\n[Editor]\n")
8689
sb.WriteString(fmt.Sprintf("AutoComplete = %d\n", map[bool]int{true: 1, false: 0}[AppConfig.EditorAutoComplete]))

config_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func TestConfig_SaveAndLoad(t *testing.T) {
2323
AppConfig.HighlightDir = true
2424
AppConfig.SavePanelPaths = false
2525
AppConfig.EditorCrosshair = true
26+
AppConfig.CommandLineAutoComplete = false
2627

2728
// 2. Save
2829
SaveConfig()
@@ -48,4 +49,7 @@ func TestConfig_SaveAndLoad(t *testing.T) {
4849
if !AppConfig.EditorCrosshair {
4950
t.Error("LoadConfig failed to restore EditorCrosshair")
5051
}
52+
if AppConfig.CommandLineAutoComplete {
53+
t.Error("LoadConfig failed to restore CommandLineAutoComplete")
54+
}
5155
}

0 commit comments

Comments
 (0)