Mariano Z. 1 hafta önce
işleme
9abc21b2b3
8 değiştirilmiş dosya ile 1064 ekleme ve 0 silme
  1. 35 0
      README.md
  2. 99 0
      config.go
  3. 32 0
      go.mod
  4. 57 0
      go.sum
  5. 249 0
      handlers.go
  6. 123 0
      main.go
  7. 123 0
      sdm.go
  8. 346 0
      ui.go

+ 35 - 0
README.md

@@ -0,0 +1,35 @@
+# SDM TUI
+
+A terminal UI for [StrongDM](https://www.strongdm.com/) on Linux.
+
+StrongDM provides a GUI client for macOS and Windows but offers only a CLI (`sdm`) on Linux. This project wraps that CLI in an interactive TUI so you can browse, filter, connect, and disconnect resources without memorizing commands.
+
+## Features
+
+- Browse and filter available resources
+- Connect with a single keypress — address copied to clipboard
+- Disconnect individual or all resources
+- Inline authentication when session expires
+- Desktop notifications via `notify-send`
+
+## Requirements
+
+- `sdm` CLI installed and in `PATH`
+- Go 1.25+ (for building)
+
+## Usage
+
+```
+go build && ./sdm-tui
+```
+
+## Key Bindings
+
+| Key | Action |
+|-----|--------|
+| `enter` | Connect to selected resource |
+| `d` | Disconnect selected resource |
+| `ctrl+x` | Disconnect all |
+| `r` | Refresh list |
+| `/` | Filter |
+| `q` | Quit |

+ 99 - 0
config.go

@@ -0,0 +1,99 @@
+package main
+
+import (
+	"os"
+	"path/filepath"
+
+	"github.com/charmbracelet/bubbles/textinput"
+	"github.com/pelletier/go-toml/v2"
+)
+
+// Constants for file permissions
+const (
+	configDirPerm  = 0755
+	configFilePerm = 0600
+)
+
+// config holds the application configuration.
+type config struct {
+	Email string `toml:"email"`
+}
+
+// configPath returns the path to the configuration file, following XDG config directory conventions.
+func configPath() (string, error) {
+	xdgConfigHome := os.Getenv("XDG_CONFIG_HOME")
+	var configDir string
+	if xdgConfigHome != "" {
+		configDir = filepath.Join(xdgConfigHome, "sdm-tui")
+	} else {
+		homeDir, err := os.UserHomeDir()
+		if err != nil {
+			return "", err
+		}
+		configDir = filepath.Join(homeDir, ".config", "sdm-tui")
+	}
+	return filepath.Join(configDir, "config.toml"), nil
+}
+
+// saveConfig saves the email to the configuration file.
+func saveConfig(email string) error {
+	configPath, err := configPath()
+	if err != nil {
+		return err
+	}
+
+	if err := os.MkdirAll(filepath.Dir(configPath), configDirPerm); err != nil {
+		return err
+	}
+
+	cfg := config{Email: email}
+	data, err := toml.Marshal(cfg)
+	if err != nil {
+		return err
+	}
+
+	return os.WriteFile(configPath, data, configFilePerm)
+}
+
+// loadConfig loads the email from the configuration file.
+// It also handles migration from the old "email" file format to the new TOML format.
+func loadConfig() string {
+	configPath, err := configPath()
+	if err != nil {
+		return ""
+	}
+
+	data, err := os.ReadFile(configPath)
+	if err != nil {
+		oldEmailPath := filepath.Join(filepath.Dir(configPath), "email")
+		if oldData, err := os.ReadFile(oldEmailPath); err == nil {
+			email := string(oldData)
+			if email != "" {
+				if err := saveConfig(email); err == nil {
+					os.Remove(oldEmailPath)
+				}
+			}
+			return email
+		}
+		return ""
+	}
+
+	var cfg config
+	if err := toml.Unmarshal(data, &cfg); err != nil {
+		return ""
+	}
+
+	return cfg.Email
+}
+
+// loadEmailIntoInput loads a saved email into the text input and returns whether an email was found.
+func loadEmailIntoInput(ti textinput.Model) (textinput.Model, bool) {
+	savedEmail := loadConfig()
+	if savedEmail != "" {
+		ti.SetValue(savedEmail)
+		return ti, true
+	}
+	return ti, false
+}
+
+

+ 32 - 0
go.mod

@@ -0,0 +1,32 @@
+module sdm-tui
+
+go 1.25.4
+
+require (
+	github.com/atotto/clipboard v0.1.4
+	github.com/charmbracelet/bubbles v0.21.0
+	github.com/charmbracelet/bubbletea v1.3.10
+	github.com/charmbracelet/lipgloss v1.1.0
+	github.com/pelletier/go-toml/v2 v2.2.4
+)
+
+require (
+	github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
+	github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
+	github.com/charmbracelet/x/ansi v0.10.1 // indirect
+	github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect
+	github.com/charmbracelet/x/term v0.2.1 // indirect
+	github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
+	github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
+	github.com/mattn/go-isatty v0.0.20 // indirect
+	github.com/mattn/go-localereader v0.0.1 // indirect
+	github.com/mattn/go-runewidth v0.0.16 // indirect
+	github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
+	github.com/muesli/cancelreader v0.2.2 // indirect
+	github.com/muesli/termenv v0.16.0 // indirect
+	github.com/rivo/uniseg v0.4.7 // indirect
+	github.com/sahilm/fuzzy v0.1.1 // indirect
+	github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
+	golang.org/x/sys v0.36.0 // indirect
+	golang.org/x/text v0.3.8 // indirect
+)

+ 57 - 0
go.sum

@@ -0,0 +1,57 @@
+github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
+github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
+github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
+github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
+github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWpi6yML8=
+github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA=
+github.com/charmbracelet/bubbles v0.21.0 h1:9TdC97SdRVg/1aaXNVWfFH3nnLAwOXr8Fn6u6mfQdFs=
+github.com/charmbracelet/bubbles v0.21.0/go.mod h1:HF+v6QUR4HkEpz62dx7ym2xc71/KBHg+zKwJtMw+qtg=
+github.com/charmbracelet/bubbletea v1.3.10 h1:otUDHWMMzQSB0Pkc87rm691KZ3SWa4KUlvF9nRvCICw=
+github.com/charmbracelet/bubbletea v1.3.10/go.mod h1:ORQfo0fk8U+po9VaNvnV95UPWA1BitP1E0N6xJPlHr4=
+github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc h1:4pZI35227imm7yK2bGPcfpFEmuY1gc2YSTShr4iJBfs=
+github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc/go.mod h1:X4/0JoqgTIPSFcRA/P6INZzIuyqdFY5rm8tb41s9okk=
+github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
+github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
+github.com/charmbracelet/x/ansi v0.10.1 h1:rL3Koar5XvX0pHGfovN03f5cxLbCF2YvLeyz7D2jVDQ=
+github.com/charmbracelet/x/ansi v0.10.1/go.mod h1:3RQDQ6lDnROptfpWuUVIUG64bD2g2BgntdxH0Ya5TeE=
+github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd h1:vy0GVL4jeHEwG5YOXDmi86oYw2yuYUGqz6a8sLwg0X8=
+github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=
+github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payRxjMjKgx2PaCWLZ4p3ro9y97+TVLZNaRZgJwSVDQ=
+github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U=
+github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
+github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
+github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
+github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
+github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
+github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
+github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
+github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
+github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
+github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
+github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
+github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
+github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
+github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
+github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
+github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
+github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
+github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
+github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
+github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
+github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
+github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
+github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
+github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
+github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
+github.com/sahilm/fuzzy v0.1.1 h1:ceu5RHF8DGgoi+/dR5PsECjCDH1BE3Fnmpo7aVXOdRA=
+github.com/sahilm/fuzzy v0.1.1/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
+github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
+github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
+golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E=
+golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
+golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
+golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
+golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
+golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=

+ 249 - 0
handlers.go

@@ -0,0 +1,249 @@
+package main
+
+import (
+	"fmt"
+	"os/exec"
+	"sort"
+
+	"github.com/atotto/clipboard"
+	"github.com/charmbracelet/bubbles/list"
+	"github.com/charmbracelet/bubbles/textinput"
+	tea "github.com/charmbracelet/bubbletea"
+)
+
+// handleWindowSize updates the model dimensions and adjusts the list size accordingly.
+func (m model) handleWindowSize(msg tea.WindowSizeMsg) (model, tea.Cmd) {
+	m.width = msg.Width
+	m.height = msg.Height
+	if !m.loading && !m.promptingEmail {
+		m.list.SetWidth(msg.Width)
+		m.list.SetHeight(msg.Height - listHeightOffset)
+	}
+	return m, nil
+}
+
+// handleAuthRequired switches the model to email prompt mode.
+func (m model) handleAuthRequired() (model, tea.Cmd) {
+	m.promptingEmail = true
+	m.loading = false
+	m.emailInput, m.rememberEmail = loadEmailIntoInput(m.emailInput)
+	return m, textinput.Blink
+}
+
+// handleLogin processes the login result and saves the email if requested.
+func (m model) handleLogin(msg loginMsg) (model, tea.Cmd) {
+	m.loggingIn = false
+	if msg.err != nil {
+		m.err = fmt.Sprintf("Login failed: %v", msg.err)
+		return m, nil
+	}
+	if m.rememberEmail {
+		email := m.emailInput.Value()
+		if email != "" {
+			saveConfig(email)
+		}
+	}
+	m.promptingEmail = false
+	m.loading = true
+	return m, fetchStatus
+}
+
+// handleStatus processes the status message and updates the list with connections.
+// Connections are sorted with connected items first, then by name.
+func (m model) handleStatus(msg statusMsg) (model, tea.Cmd) {
+	if msg.err != nil {
+		m.loading = false
+		m.err = fmt.Sprintf("Failed to fetch status: %v", msg.err)
+		return m, nil
+	}
+
+	// Sort connections: connected items first, then by name
+	connections := make([]connection, len(msg.connections))
+	copy(connections, msg.connections)
+	sort.Slice(connections, func(i, j int) bool {
+		if connections[i].Connected != connections[j].Connected {
+			// Connected items come first
+			return connections[i].Connected
+		}
+		// If both have same connection status, sort by name
+		return connections[i].Name < connections[j].Name
+	})
+
+	items := make([]list.Item, len(connections))
+	for i, conn := range connections {
+		items[i] = item{
+			address:   getAddress(conn),
+			name:      conn.Name,
+			connected: conn.Connected,
+			connType:  conn.Type,
+		}
+	}
+
+	m.list = newList(items, m.width, m.height-listHeightOffset)
+	m.loading = false
+
+	return m, nil
+}
+
+// handleConnection initiates a connection to the selected item.
+func (m model) handleConnection() (model, tea.Cmd) {
+	i, ok := m.list.SelectedItem().(item)
+	if !ok {
+		return m, nil
+	}
+	m.loading = true
+	name := i.name
+	address := i.address
+	return m, tea.Batch(
+		func() tea.Msg {
+			return connectSDM(name, address)
+		},
+		m.spinner.Tick,
+	)
+}
+
+// handleConnectResult processes the result of a connect operation.
+func (m model) handleConnectResult(msg connectMsg) (model, tea.Cmd) {
+	m.loading = false
+	if msg.err != nil {
+		m.err = fmt.Sprintf("Error connecting to %s: %v", msg.name, msg.err)
+		return m, nil
+	}
+	clipboard.WriteAll(msg.address)
+	sendNotification("SDM Connected", fmt.Sprintf("Connected to %s", msg.name))
+	return m, tea.Quit
+}
+
+// handleKillConnections disconnects all connections.
+func (m model) handleKillConnections() (model, tea.Cmd) {
+	m.loading = true
+	return m, tea.Batch(
+		func() tea.Msg {
+			cmd := exec.Command("sdm", "disconnect", "--all")
+			output, err := cmd.CombinedOutput()
+			if err != nil {
+				return disconnectMsg{err: fmt.Errorf("disconnecting: %v: %s", err, string(output))}
+			}
+			return disconnectMsg{}
+		},
+		m.spinner.Tick,
+	)
+}
+
+// handleDisconnectSelected disconnects the currently selected connection.
+func (m model) handleDisconnectSelected() (model, tea.Cmd) {
+	i, ok := m.list.SelectedItem().(item)
+	if !ok || !i.connected {
+		return m, nil
+	}
+	m.loading = true
+	name := i.name
+	return m, tea.Batch(
+		func() tea.Msg {
+			return disconnectSDM(name)
+		},
+		m.spinner.Tick,
+	)
+}
+
+// handleDisconnect processes the result of a disconnect operation.
+func (m model) handleDisconnect(msg disconnectMsg) (model, tea.Cmd) {
+	m.loading = false
+	if msg.err != nil {
+		m.err = fmt.Sprintf("Error disconnecting: %v", msg.err)
+		return m, nil
+	}
+	name := "all connections"
+	if msg.name != "" {
+		name = msg.name
+	}
+	sendNotification("SDM Disconnected", fmt.Sprintf("Disconnected from %s", name))
+	m.loading = true
+	return m, tea.Batch(fetchStatus, m.spinner.Tick)
+}
+
+// handleKeyInput processes keyboard input based on the current application state.
+func (m model) handleKeyInput(msg tea.KeyMsg) (model, tea.Cmd) {
+	if m.promptingEmail {
+		switch msg.String() {
+		case "enter":
+			email := m.emailInput.Value()
+			if email != "" && !m.loggingIn {
+				m.loggingIn = true
+				return m, tea.Batch(
+					func() tea.Msg {
+						return loginSDM(email)
+					},
+					m.spinner.Tick,
+				)
+			}
+		case " ":
+			if !m.loggingIn {
+				m.rememberEmail = !m.rememberEmail
+			}
+			return m, nil
+		}
+		if isQuitKey(msg.String()) {
+			return m, tea.Quit
+		}
+		if !m.loggingIn {
+			var cmd tea.Cmd
+			m.emailInput, cmd = m.emailInput.Update(msg)
+			return m, cmd
+		}
+		return m, nil
+	}
+
+	if m.err != "" {
+		switch msg.String() {
+		case "r":
+			m.err = ""
+			m.loading = true
+			m.promptingEmail = false
+			m.loggingIn = false
+			return m, tea.Batch(
+				func() tea.Msg {
+					if err := checkSDMBinary(); err != nil {
+						return statusMsg{err: err}
+					}
+					return fetchStatus()
+				},
+				m.spinner.Tick,
+			)
+		}
+		if isQuitKey(msg.String()) {
+			return m, tea.Quit
+		}
+		return m, nil
+	}
+
+	if m.loading {
+		return m, nil
+	}
+
+	if m.list.FilterState() == list.Filtering {
+		var cmd tea.Cmd
+		m.list, cmd = m.list.Update(msg)
+		return m, cmd
+	}
+
+	switch msg.String() {
+	case tea.KeyEnter.String():
+		return m.handleConnection()
+	case tea.KeyCtrlX.String():
+		return m.handleKillConnections()
+	case "d":
+		return m.handleDisconnectSelected()
+	case "r":
+		m.loading = true
+		return m, tea.Batch(fetchStatus, m.spinner.Tick)
+	}
+
+	if isQuitKey(msg.String()) {
+		return m, tea.Quit
+	}
+
+	var cmd tea.Cmd
+	m.list, cmd = m.list.Update(msg)
+	return m, cmd
+}

+ 123 - 0
main.go

@@ -0,0 +1,123 @@
+// Package main provides a TUI (Terminal User Interface) for managing SDM connections.
+// It allows users to view, filter, and connect to available SDM resources.
+package main
+
+import (
+	"os"
+
+	"github.com/charmbracelet/bubbles/list"
+	"github.com/charmbracelet/bubbles/spinner"
+	"github.com/charmbracelet/bubbles/textinput"
+	tea "github.com/charmbracelet/bubbletea"
+	"github.com/charmbracelet/lipgloss"
+)
+
+// model holds the state of the TUI application.
+type model struct {
+	list           list.Model
+	spinner        spinner.Model
+	loading        bool
+	width          int
+	height         int
+	emailInput     textinput.Model
+	promptingEmail bool
+	rememberEmail  bool
+	loggingIn      bool
+	err            string
+}
+
+// initialModel creates and returns the initial model state.
+func initialModel() model {
+	s := spinner.New()
+	s.Spinner = spinner.Dot
+	s.Style = lipgloss.NewStyle().Foreground(primaryColor)
+
+	ti := textinput.New()
+	ti.Placeholder = "your.email@example.com"
+	ti.Focus()
+	ti.CharLimit = inputCharLimit
+	ti.Width = inputWidth
+
+	ti, rememberEmail := loadEmailIntoInput(ti)
+
+	return model{
+		list:           newList(make([]list.Item, 0), 0, 0),
+		spinner:        s,
+		loading:        true,
+		emailInput:     ti,
+		promptingEmail: false,
+		rememberEmail:  rememberEmail,
+	}
+}
+
+// Init initializes the model and returns the initial batch of commands.
+func (m model) Init() tea.Cmd {
+	return tea.Batch(
+		tea.WindowSize(),
+		m.spinner.Tick,
+		func() tea.Msg {
+			if err := checkSDMBinary(); err != nil {
+				return statusMsg{err: err}
+			}
+			return fetchStatus()
+		},
+	)
+}
+
+// Update processes messages and updates the model state accordingly.
+func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
+	switch msg := msg.(type) {
+	case tea.WindowSizeMsg:
+		return m.handleWindowSize(msg)
+	case authRequiredMsg:
+		return m.handleAuthRequired()
+	case loginMsg:
+		return m.handleLogin(msg)
+	case statusMsg:
+		return m.handleStatus(msg)
+	case connectMsg:
+		return m.handleConnectResult(msg)
+	case disconnectMsg:
+		return m.handleDisconnect(msg)
+	case tea.KeyMsg:
+		return m.handleKeyInput(msg)
+	}
+
+	if m.loading || m.loggingIn {
+		var cmd tea.Cmd
+		m.spinner, cmd = m.spinner.Update(msg)
+		return m, cmd
+	}
+
+	if !m.promptingEmail {
+		var cmd tea.Cmd
+		m.list, cmd = m.list.Update(msg)
+		return m, cmd
+	}
+
+	return m, nil
+}
+
+// View renders the current state of the UI.
+func (m model) View() string {
+	if m.err != "" {
+		return renderError(m)
+	}
+
+	if m.promptingEmail {
+		return renderEmailPrompt(m)
+	}
+
+	if m.loading {
+		return renderLoading(m)
+	}
+
+	return m.list.View()
+}
+
+func main() {
+	p := tea.NewProgram(initialModel())
+	if _, err := p.Run(); err != nil {
+		os.Exit(1)
+	}
+}

+ 123 - 0
sdm.go

@@ -0,0 +1,123 @@
+package main
+
+import (
+	"encoding/json"
+	"fmt"
+	"os/exec"
+
+	tea "github.com/charmbracelet/bubbletea"
+)
+
+// Constants for SDM command exit codes
+const (
+	exitCodeAuthRequired = 9
+)
+
+// connection represents a SDM connection from the status command.
+type connection struct {
+	Name      string  `json:"name"`
+	Type      string  `json:"type"`
+	Address   string  `json:"address"`
+	Connected bool    `json:"connected"`
+	WebURL    *string `json:"web_url"`
+}
+
+// statusMsg is sent when the status fetch operation completes.
+type statusMsg struct {
+	connections []connection
+	err         error
+}
+
+// authRequiredMsg is sent when authentication is required.
+type authRequiredMsg struct{}
+
+// loginMsg is sent when the login operation completes.
+type loginMsg struct {
+	err error
+}
+
+// connectMsg is sent when a connect operation completes.
+type connectMsg struct {
+	name    string
+	address string
+	err     error
+}
+
+// disconnectMsg is sent when a disconnect operation completes.
+type disconnectMsg struct {
+	name string
+	err  error
+}
+
+// checkSDMBinary verifies that the sdm binary is available in PATH.
+func checkSDMBinary() error {
+	_, err := exec.LookPath("sdm")
+	if err != nil {
+		return fmt.Errorf("sdm binary not found in PATH. Please install sdm and try again")
+	}
+	return nil
+}
+
+// fetchStatus executes the SDM status command and returns the result as a message.
+// If authentication is required (exit code 9), it returns authRequiredMsg.
+func fetchStatus() tea.Msg {
+	cmd := exec.Command("sdm", "status", "-j")
+	output, err := cmd.CombinedOutput()
+	if err != nil {
+		if exitError, ok := err.(*exec.ExitError); ok && exitError.ExitCode() == exitCodeAuthRequired {
+			return authRequiredMsg{}
+		}
+		return statusMsg{err: fmt.Errorf("%v: %s", err, string(output))}
+	}
+
+	var connections []connection
+	if err := json.Unmarshal(output, &connections); err != nil {
+		return statusMsg{err: err}
+	}
+
+	return statusMsg{connections: connections}
+}
+
+// loginSDM executes the SDM login command with the provided email.
+func loginSDM(email string) tea.Msg {
+	cmd := exec.Command("sdm", "login", "--email", email)
+	output, err := cmd.CombinedOutput()
+	if err != nil {
+		return loginMsg{err: fmt.Errorf("%v: %s", err, string(output))}
+	}
+	return loginMsg{}
+}
+
+// connectSDM executes the SDM connect command and waits for it to complete.
+func connectSDM(name, address string) tea.Msg {
+	cmd := exec.Command("sdm", "connect", name)
+	output, err := cmd.CombinedOutput()
+	if err != nil {
+		return connectMsg{name: name, address: address, err: fmt.Errorf("%v: %s", err, string(output))}
+	}
+	return connectMsg{name: name, address: address}
+}
+
+// disconnectSDM executes the SDM disconnect command for a specific connection.
+func disconnectSDM(name string) tea.Msg {
+	cmd := exec.Command("sdm", "disconnect", name)
+	output, err := cmd.CombinedOutput()
+	if err != nil {
+		return disconnectMsg{name: name, err: fmt.Errorf("%v: %s", err, string(output))}
+	}
+	return disconnectMsg{name: name}
+}
+
+// getAddress returns the appropriate address for a connection, preferring WebURL over Address.
+func getAddress(conn connection) string {
+	if conn.WebURL != nil {
+		return *conn.WebURL
+	}
+	return conn.Address
+}
+
+// sendNotification sends a desktop notification using notify-send.
+func sendNotification(title, message string) {
+	cmd := exec.Command("notify-send", title, message)
+	cmd.Run() // Ignore errors - notification is non-critical
+}

+ 346 - 0
ui.go

@@ -0,0 +1,346 @@
+package main
+
+import (
+	"fmt"
+	"io"
+
+	"github.com/charmbracelet/bubbles/key"
+	"github.com/charmbracelet/bubbles/list"
+	"github.com/charmbracelet/lipgloss"
+)
+
+// Constants for UI dimensions
+const (
+	minEmailWidth    = 50
+	maxEmailWidth    = 70
+	minLoadingWidth  = 40
+	maxLoadingWidth  = 60
+	inputCharLimit   = 256
+	inputWidth       = 50
+	listHeightOffset = 2
+)
+
+// Color scheme
+var (
+	primaryColor   = lipgloss.Color("205")
+	secondaryColor = lipgloss.Color("240")
+	successColor   = lipgloss.Color("42")
+	subtleColor    = lipgloss.Color("241")
+	borderColor    = lipgloss.Color("236")
+	errorColor     = lipgloss.Color("196")
+)
+
+// UI style definitions grouped by purpose
+var (
+	// Text styles
+	titleStyle = lipgloss.NewStyle().
+			Bold(true).
+			Foreground(primaryColor).
+			MarginBottom(1)
+
+	labelStyle = lipgloss.NewStyle().
+			Foreground(secondaryColor).
+			MarginRight(1)
+
+	helpTextStyle = lipgloss.NewStyle().
+			Foreground(subtleColor).
+			Italic(true).
+			MarginTop(1)
+
+	loadingStyle = lipgloss.NewStyle().
+			Foreground(primaryColor).
+			Margin(1, 0)
+
+	errorStyle = lipgloss.NewStyle().
+			Foreground(errorColor).
+			Bold(true)
+
+	// Container styles
+
+	containerStyle = lipgloss.NewStyle().
+			Border(lipgloss.RoundedBorder()).
+			BorderForeground(borderColor).
+			Background(lipgloss.NoColor{}).
+			Padding(1, 2).
+			Margin(1, 0)
+
+	// Checkbox styles
+	checkboxStyle = lipgloss.NewStyle().
+			Foreground(primaryColor).
+			MarginRight(1)
+
+	checkboxCheckedStyle = lipgloss.NewStyle().
+				Foreground(successColor).
+				MarginRight(1)
+
+	// Status styles
+	statusConnectedStyle = lipgloss.NewStyle().
+				Foreground(successColor).
+				Bold(true)
+
+	statusDisconnectedStyle = lipgloss.NewStyle().
+				Foreground(subtleColor)
+)
+
+// listKeyMap defines custom key bindings for the list view.
+type listKeyMap struct {
+	connect    key.Binding
+	disconnect key.Binding
+	disconnAll key.Binding
+	refresh    key.Binding
+}
+
+var customKeys = listKeyMap{
+	connect: key.NewBinding(
+		key.WithKeys("enter"),
+		key.WithHelp("enter", "connect"),
+	),
+	disconnect: key.NewBinding(
+		key.WithKeys("d"),
+		key.WithHelp("d", "disconnect"),
+	),
+	disconnAll: key.NewBinding(
+		key.WithKeys("ctrl+x"),
+		key.WithHelp("ctrl+x", "disconnect all"),
+	),
+	refresh: key.NewBinding(
+		key.WithKeys("r"),
+		key.WithHelp("r", "refresh"),
+	),
+}
+
+// item represents a connection item in the list view.
+type item struct {
+	name      string
+	address   string
+	connected bool
+	connType  string
+}
+
+// Title returns the display title for the item, with a bullet indicator if connected.
+func (i item) Title() string {
+	if i.connected {
+		return "● " + i.name
+	}
+	return i.name
+}
+
+// Description returns the formatted description showing the address and connection status.
+func (i item) Description() string {
+	addressStyle := statusDisconnectedStyle
+	prefix := ""
+	if i.connType != "" {
+		prefix = "[" + i.connType + "] "
+	}
+	if i.connected {
+		addressStyle = statusConnectedStyle
+		return addressStyle.Render(prefix+i.address) + " " + statusConnectedStyle.Render("• Connected")
+	}
+	return addressStyle.Render(prefix + i.address)
+}
+
+// FilterValue returns the value used for filtering items in the list.
+func (i item) FilterValue() string { return i.name }
+
+// customDelegate provides custom rendering for list items with connection status styling.
+type customDelegate struct {
+	list.DefaultDelegate
+}
+
+// Render renders a list item with custom styling based on selection and connection status.
+func (d customDelegate) Render(w io.Writer, m list.Model, index int, listItem list.Item) {
+	itm, ok := listItem.(item)
+	if !ok {
+		d.DefaultDelegate.Render(w, m, index, listItem)
+		return
+	}
+
+	isSelected := index == m.Index()
+	titleStyle := d.getTitleStyle(isSelected, itm.connected)
+	title := titleStyle.Render(itm.Title())
+
+	descStyle := d.Styles.NormalDesc
+	if isSelected {
+		descStyle = d.Styles.SelectedDesc
+	}
+	desc := descStyle.Render(itm.Description())
+
+	fmt.Fprint(w, lipgloss.JoinVertical(lipgloss.Left, title, desc))
+}
+
+// getTitleStyle returns the appropriate title style based on selection and connection status.
+func (d customDelegate) getTitleStyle(isSelected, isConnected bool) lipgloss.Style {
+	baseStyle := lipgloss.NewStyle().
+		Background(lipgloss.NoColor{}).
+		Padding(0, 0, 0, 1)
+
+	if isSelected {
+		selectedStyle := d.Styles.SelectedTitle.
+			Border(lipgloss.NormalBorder(), false, false, false, true).
+			BorderForeground(primaryColor).
+			Bold(true).
+			Background(lipgloss.NoColor{}).
+			Padding(0, 0, 0, 1)
+
+		if isConnected {
+			return selectedStyle.Foreground(successColor)
+		}
+		return selectedStyle.Foreground(primaryColor)
+	}
+
+	// Normal (unselected) item
+	if isConnected {
+		return baseStyle.
+			Foreground(successColor).
+			Bold(true)
+	}
+	return baseStyle.Foreground(lipgloss.Color("252"))
+}
+
+// newList creates and configures a new list model with custom styling.
+func newList(items []list.Item, width, height int) list.Model {
+	delegate := customDelegate{DefaultDelegate: list.NewDefaultDelegate()}
+	delegate.Styles.SelectedTitle = delegate.Styles.SelectedTitle.
+		Border(lipgloss.NormalBorder(), false, false, false, true).
+		BorderForeground(primaryColor).
+		Foreground(primaryColor).
+		Bold(true).
+		Background(lipgloss.NoColor{}).
+		Padding(0, 0, 0, 1)
+	delegate.Styles.SelectedDesc = delegate.Styles.SelectedDesc.
+		Border(lipgloss.NormalBorder(), false, false, false, true).
+		BorderForeground(primaryColor).
+		Foreground(secondaryColor).
+		Background(lipgloss.NoColor{}).
+		Padding(0, 0, 0, 1)
+	delegate.Styles.NormalDesc = delegate.Styles.NormalDesc.
+		Foreground(subtleColor).
+		Background(lipgloss.NoColor{}).
+		Padding(0, 0, 0, 1)
+
+	l := list.New(items, delegate, width, height)
+	l.Title = ""
+	l.SetShowStatusBar(false)
+	l.SetShowPagination(false)
+	l.SetFilteringEnabled(true)
+	l.SetShowHelp(true)
+	l.AdditionalShortHelpKeys = func() []key.Binding {
+		return []key.Binding{
+			customKeys.connect,
+			customKeys.disconnect,
+			customKeys.disconnAll,
+			customKeys.refresh,
+		}
+	}
+	l.Styles.StatusBar = lipgloss.NewStyle().
+		Foreground(subtleColor).
+		Background(lipgloss.NoColor{}).
+		MarginTop(1)
+	l.Styles.Title = lipgloss.NewStyle().
+		Background(lipgloss.NoColor{})
+	l.Styles.FilterPrompt = lipgloss.NewStyle().
+		Background(lipgloss.NoColor{})
+	l.Styles.FilterCursor = lipgloss.NewStyle().
+		Background(lipgloss.NoColor{})
+	return l
+}
+
+// isQuitKey checks if the given key string represents a quit command.
+func isQuitKey(key string) bool {
+	return key == "q" || key == "ctrl+c" || key == "esc"
+}
+
+// renderEmailPrompt renders the email authentication prompt view.
+func renderEmailPrompt(m model) string {
+	if m.loggingIn {
+		title := titleStyle.Render("Authenticating...")
+		spinnerText := loadingStyle.Render(m.spinner.View() + " Opening browser for authentication...")
+		content := lipgloss.JoinVertical(lipgloss.Center,
+			"",
+			title,
+			"",
+			spinnerText,
+			"",
+		)
+
+		width := clampWidth(m.width, minLoadingWidth, maxLoadingWidth)
+		return lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center,
+			containerStyle.Width(width).Align(lipgloss.Center).Render(content))
+	}
+
+	checkbox := checkboxStyle.Render("[ ]")
+	if m.rememberEmail {
+		checkbox = checkboxCheckedStyle.Render("[x]")
+	}
+
+	title := titleStyle.Render("Authentication Required")
+	message := labelStyle.Render("You are not authenticated. Please login.")
+	emailLabel := labelStyle.Render("Email:")
+	emailInput := m.emailInput.View()
+	rememberText := checkbox + labelStyle.Render("Remember email (press Space to toggle)")
+	helpText := helpTextStyle.Render("Press Enter to login, Esc to quit")
+
+	content := lipgloss.JoinVertical(lipgloss.Left,
+		title,
+		"",
+		message,
+		"",
+		emailLabel+emailInput,
+		"",
+		rememberText,
+		"",
+		helpText,
+	)
+
+	width := clampWidth(m.width, minEmailWidth, maxEmailWidth)
+	return lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center,
+		containerStyle.Width(width).Render(content))
+}
+
+// renderLoading renders the loading spinner view.
+func renderLoading(m model) string {
+	title := titleStyle.Render("Loading Connections")
+	spinnerText := loadingStyle.Render(m.spinner.View() + " Loading connections...")
+	content := lipgloss.JoinVertical(lipgloss.Center,
+		"",
+		title,
+		"",
+		spinnerText,
+		"",
+	)
+
+	width := clampWidth(m.width, minLoadingWidth, maxLoadingWidth)
+	return lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center,
+		containerStyle.Width(width).Align(lipgloss.Center).Render(content))
+}
+
+// renderError renders the error view with retry and quit options.
+func renderError(m model) string {
+	title := titleStyle.Render("Error")
+	errText := errorStyle.Render(m.err)
+	helpText := helpTextStyle.Render("Press r to retry, q/Esc to quit")
+	content := lipgloss.JoinVertical(lipgloss.Center,
+		"",
+		title,
+		"",
+		errText,
+		"",
+		helpText,
+		"",
+	)
+
+	width := clampWidth(m.width, minLoadingWidth, maxLoadingWidth)
+	return lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center,
+		containerStyle.Width(width).Align(lipgloss.Center).Render(content))
+}
+
+// clampWidth constrains the width value between min and max.
+func clampWidth(width, min, max int) int {
+	if width > max {
+		return max
+	}
+	if width < min {
+		return min
+	}
+	return width
+}