mirror of
https://github.com/jixishi/SerialTerminalForWindowsTerminal.git
synced 2026-06-15 16:42:46 +00:00
fix: TUI 'g' key input, EndStr panel editing, and mode validation
- Remove 'g' and 'shift+g' from viewport handler (conflicted with text input; home/end keys already provide same functionality) - Add rawValue field to modeItem to preserve EndStr control chars during TUI panel editing (fixes %q round-trip corruption) - Add validation for empty charset names and timefmt fields Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -439,8 +439,14 @@ func (d *CommandDispatcher) handleModeCommand(args []string) error {
|
|||||||
|
|
||||||
switch field {
|
switch field {
|
||||||
case "in":
|
case "in":
|
||||||
|
if value == "" {
|
||||||
|
return fmt.Errorf("input charset must not be empty")
|
||||||
|
}
|
||||||
d.app.cfg.InputCode = value
|
d.app.cfg.InputCode = value
|
||||||
case "out":
|
case "out":
|
||||||
|
if value == "" {
|
||||||
|
return fmt.Errorf("output charset must not be empty")
|
||||||
|
}
|
||||||
d.app.cfg.OutputCode = value
|
d.app.cfg.OutputCode = value
|
||||||
case "end":
|
case "end":
|
||||||
d.app.cfg.EndStr = value
|
d.app.cfg.EndStr = value
|
||||||
@@ -457,6 +463,9 @@ func (d *CommandDispatcher) handleModeCommand(args []string) error {
|
|||||||
}
|
}
|
||||||
d.app.cfg.TimesTamp = enabled
|
d.app.cfg.TimesTamp = enabled
|
||||||
case "timefmt":
|
case "timefmt":
|
||||||
|
if value == "" && d.app.cfg.TimesTamp {
|
||||||
|
return fmt.Errorf("timestamp format must not be empty")
|
||||||
|
}
|
||||||
d.app.cfg.TimesFmt = value
|
d.app.cfg.TimesFmt = value
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unknown mode field: %s", field)
|
return fmt.Errorf("unknown mode field: %s", field)
|
||||||
|
|||||||
@@ -101,11 +101,11 @@ func (m *uiModel) handleViewportKey(msg tea.KeyMsg) bool {
|
|||||||
m.viewport, cmd = m.viewport.Update(msg)
|
m.viewport, cmd = m.viewport.Update(msg)
|
||||||
_ = cmd
|
_ = cmd
|
||||||
return true
|
return true
|
||||||
case "home", "g":
|
case "home":
|
||||||
m.viewport.GotoTop()
|
m.viewport.GotoTop()
|
||||||
m.followTail = false
|
m.followTail = false
|
||||||
return true
|
return true
|
||||||
case "end", "shift+g":
|
case "end":
|
||||||
m.viewport.GotoBottom()
|
m.viewport.GotoBottom()
|
||||||
m.followTail = true
|
m.followTail = true
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -16,9 +16,10 @@ import (
|
|||||||
type doneMsg struct{}
|
type doneMsg struct{}
|
||||||
|
|
||||||
type modeItem struct {
|
type modeItem struct {
|
||||||
key string
|
key string
|
||||||
label string
|
label string
|
||||||
value string
|
value string
|
||||||
|
rawValue string
|
||||||
}
|
}
|
||||||
|
|
||||||
type panelLine struct {
|
type panelLine struct {
|
||||||
|
|||||||
@@ -71,7 +71,14 @@ func (m *uiModel) refreshPanel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *uiModel) buildModeItems() []modeItem {
|
func (m *uiModel) buildModeItems() []modeItem {
|
||||||
return []modeItem{{"in", "Input Charset", m.app.cfg.InputCode}, {"out", "Output Charset", m.app.cfg.OutputCode}, {"end", "Line End", fmt.Sprintf("%q", m.app.cfg.EndStr)}, {"frame", "Hex Frame Size", fmt.Sprintf("%d", m.app.cfg.FrameSize)}, {"timestamp", "Timestamp", fmt.Sprintf("%v", m.app.cfg.TimesTamp)}, {"timefmt", "Timestamp Format", m.app.cfg.TimesFmt}}
|
return []modeItem{
|
||||||
|
{"in", "Input Charset", m.app.cfg.InputCode, m.app.cfg.InputCode},
|
||||||
|
{"out", "Output Charset", m.app.cfg.OutputCode, m.app.cfg.OutputCode},
|
||||||
|
{"end", "Line End", fmt.Sprintf("%q", m.app.cfg.EndStr), m.app.cfg.EndStr},
|
||||||
|
{"frame", "Hex Frame Size", fmt.Sprintf("%d", m.app.cfg.FrameSize), fmt.Sprintf("%d", m.app.cfg.FrameSize)},
|
||||||
|
{"timestamp", "Timestamp", fmt.Sprintf("%v", m.app.cfg.TimesTamp), fmt.Sprintf("%v", m.app.cfg.TimesTamp)},
|
||||||
|
{"timefmt", "Timestamp Format", m.app.cfg.TimesFmt, m.app.cfg.TimesFmt},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *uiModel) handleForwardPanelKey(key string) bool {
|
func (m *uiModel) handleForwardPanelKey(key string) bool {
|
||||||
@@ -222,7 +229,7 @@ func (m *uiModel) handleModePanelKey(key string) bool {
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
case "enter", "e":
|
case "enter", "e":
|
||||||
initial := strings.Trim(sel.value, "\"")
|
initial := sel.rawValue
|
||||||
m.startPrompt("Edit Mode: "+sel.label, "new value", initial, func(v string) {
|
m.startPrompt("Edit Mode: "+sel.label, "new value", initial, func(v string) {
|
||||||
m.app.handleLine(fmt.Sprintf(".mode set %s %s", sel.key, v))
|
m.app.handleLine(fmt.Sprintf(".mode set %s %s", sel.key, v))
|
||||||
m.refreshPanel()
|
m.refreshPanel()
|
||||||
|
|||||||
Reference in New Issue
Block a user