55 "os/exec"
66 "runtime"
77 "strings"
8- "time"
98
109 tea "charm.land/bubbletea/v2"
1110 "charm.land/lipgloss/v2"
@@ -25,33 +24,21 @@ type SettingsState struct {
2524}
2625
2726type Settings struct {
28- state SettingsState
29- theme theme.Theme
30- notice string
27+ state SettingsState
28+ theme theme.Theme
3129}
3230
33- type SettingsClearNoticeMsg struct {}
34-
3531func NewSettings (state SettingsState , t theme.Theme ) Settings {
3632 return Settings {state : state , theme : t }
3733}
3834
3935func (s Settings ) Init () tea.Cmd { return nil }
4036
4137func (s Settings ) Update (msg tea.Msg ) (Screen , tea.Cmd ) {
42- switch msg := msg .(type ) {
43- case tea.KeyPressMsg :
38+ if msg , ok := msg .(tea.KeyPressMsg ); ok {
4439 if msg .String () == "c" && s .state .DeviceID != "" {
45- err := copyToClipboard (s .state .DeviceID )
46- if err != nil {
47- s .notice = "copy failed: " + err .Error ()
48- } else {
49- s .notice = "copied!"
50- }
51- return s , tea .Tick (2 * time .Second , func (time.Time ) tea.Msg { return SettingsClearNoticeMsg {} })
40+ _ = copyToClipboard (s .state .DeviceID )
5241 }
53- case SettingsClearNoticeMsg :
54- s .notice = ""
5542 }
5643 return s , nil
5744}
@@ -91,9 +78,6 @@ func (s Settings) View(width, height int) string {
9178 if s .state .DeviceID != "" {
9279 lines = append (lines , row ("Device ID" , s .state .DeviceID ))
9380 }
94- if s .notice != "" {
95- lines = append (lines , "" , s .theme .Success .Render (" " + s .notice ))
96- }
9781
9882 return lipgloss .NewStyle ().Width (width ).Height (height ).Render (strings .Join (lines , "\n " ))
9983}
0 commit comments