MCPcopy
hub / github.com/SurgeDM/Surge / Update

Method Update

internal/tui/update.go:61–292  ·  view source on GitHub ↗

Update handles messages and updates the model

(msg tea.Msg)

Source from the content-addressed store, hash-verified

59
60// Update handles messages and updates the model
61func (m RootModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
62 // Dynamically reload keymap.json on the fly if it is updated on disk
63 if time.Since(m.lastConfigCheckTime) > 1*time.Second {
64 m.lastConfigCheckTime = time.Now()
65 if info, err := os.Stat(config.GetKeyMapConfigPath()); err == nil {
66 if info.ModTime().After(m.lastKeyMapModTime) {
67 preLoadModTime := info.ModTime()
68 if newKeys, err := config.LoadKeyMap(); err == nil && newKeys != nil {
69 m.keys = newKeys
70 if postInfo, postErr := os.Stat(config.GetKeyMapConfigPath()); postErr == nil {
71 m.lastKeyMapModTime = postInfo.ModTime()
72 } else {
73 m.lastKeyMapModTime = preLoadModTime
74 }
75 utils.Debug("TUI: dynamically reloaded keymap.json from disk")
76 }
77 }
78 }
79 }
80
81 if m.Settings == nil {
82 m.Settings = config.DefaultSettings()
83 }
84
85 if m.keys == nil {
86 m.keys = config.DefaultKeyMap()
87 }
88
89 if m.shuttingDown {
90 switch msg := msg.(type) {
91 case shutdownCompleteMsg:
92 if msg.err != nil {
93 utils.Debug("TUI shutdown error: %v", msg.err)
94 }
95 return m, tea.Quit
96 case tea.WindowSizeMsg:
97 m.width = msg.Width
98 m.height = msg.Height
99 return m, nil
100 default:
101 return m, nil
102 }
103 }
104
105 switch msg := msg.(type) {
106
107 case tea.WindowSizeMsg:
108 m.width = msg.Width
109 m.height = msg.Height
110
111 if m.state == SettingsState {
112 m.normalizeSettingsSelection()
113 if m.SettingsIsEditing {
114 m.updateSettingsInputWidthForViewport()
115 }
116 }
117
118 if m.state == CategoryManagerState {