MCPcopy
hub / github.com/mathaou/termdbms / Update

Method Update

viewer/viewer.go:67–136  ·  view source on GitHub ↗

Update is where all commands and whatnot get processed

(message tea.Msg)

Source from the content-addressed store, hash-verified

65
66// Update is where all commands and whatnot get processed
67func (m TuiModel) Update(message tea.Msg) (tea.Model, tea.Cmd) {
68 var (
69 command tea.Cmd
70 commands []tea.Cmd
71 )
72
73 if !m.UI.FormatModeEnabled {
74 m.Viewport, _ = m.Viewport.Update(message)
75 }
76
77 switch msg := message.(type) {
78 case list.FilterMatchesMessage:
79 m.ClipboardList, command = m.ClipboardList.Update(msg)
80 break
81 case tea.MouseMsg:
82 HandleMouseEvents(&m, &msg)
83 m.SetViewSlices()
84 break
85 case tea.WindowSizeMsg:
86 event := HandleWindowSizeEvents(&m, &msg)
87 if event != nil {
88 commands = append(commands, event)
89 }
90 break
91 case tea.KeyMsg:
92 str := msg.String()
93 if m.UI.ShowClipboard {
94 HandleClipboardEvents(&m, str, &command, msg)
95 break
96 }
97
98 // when fullscreen selection viewing is in session, don't allow UI manipulation other than quit or exit
99 s := msg.String()
100 invalidRenderCommand := m.UI.RenderSelection &&
101 s != "esc" &&
102 s != "ctrl+c" &&
103 s != "q" &&
104 s != "p" &&
105 s != "m" &&
106 s != "n"
107 if invalidRenderCommand {
108 break
109 }
110
111 if s == "ctrl+c" || (s == "q" && (!m.UI.EditModeEnabled && !m.UI.FormatModeEnabled)) {
112 return m, tea.Quit
113 }
114
115 event := HandleKeyboardEvents(&m, &msg)
116 if event != nil {
117 commands = append(commands, event)
118 }
119 if !m.UI.EditModeEnabled && m.Ready {
120 m.SetViewSlices()
121 if m.UI.FormatModeEnabled {
122 MoveCursorWithinBounds(&m)
123 }
124 }

Callers

nothing calls this directly

Calls 8

SetViewSlicesMethod · 0.95
HandleMouseEventsFunction · 0.85
HandleWindowSizeEventsFunction · 0.85
HandleClipboardEventsFunction · 0.85
HandleKeyboardEventsFunction · 0.85
MoveCursorWithinBoundsFunction · 0.85
UpdateMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected