1package policy
2
3import (
4 "github.com/The-Robin-Hood/ufWall/internal/keys"
5 "github.com/The-Robin-Hood/ufWall/internal/ufw"
6
7 "github.com/charmbracelet/bubbles/key"
8 tea "github.com/charmbracelet/bubbletea"
9)
10
11func (m Model) Update(msg tea.Msg, policy ufw.Policy) (Model, tea.Cmd) {
12 switch msg := msg.(type) {
13 case tea.KeyMsg:
14 switch {
15 case key.Matches(msg, keys.Bindings.CursorUp):
16 if m.cursorLine > 0 {
17 m.cursorLine--
18 }
19 case key.Matches(msg, keys.Bindings.CursorDown):
20 if m.cursorLine < m.totalOpts {
21 m.cursorLine++
22 }
23 case key.Matches(msg, keys.Bindings.Execute):
24 switch m.cursorLine {
25 case 0:
26 ufw.DefaultIncoming(!(policy.DefaultIncoming == "ALLOW"))
27 case 1:
28 ufw.DefaultOutgoing(!(policy.DefaultOutgoing == "ALLOW"))
29 case 2:
30 ufw.DefaultRouted(!(policy.DefaultRouted == "ALLOW"))
31 }
32 return m, keys.Refresh()
33 }
34 }
35 return m, nil
36}