mirror of
https://github.com/anotherhadi/usbguard-tui.git
synced 2026-10-05 18:28:24 +02:00
@@ -0,0 +1,55 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
tea "charm.land/bubbletea/v2"
|
||||
"github.com/anotherhadi/ilovetui/app"
|
||||
"github.com/anotherhadi/ilovetui/modal"
|
||||
"github.com/anotherhadi/ilovetui/notification"
|
||||
"github.com/anotherhadi/usbguard-tui/ui"
|
||||
)
|
||||
|
||||
type appModel struct {
|
||||
core ui.Model
|
||||
modals modal.Model
|
||||
notif notification.Model
|
||||
}
|
||||
|
||||
func newApp() appModel {
|
||||
return appModel{
|
||||
core: ui.New(),
|
||||
modals: modal.New(),
|
||||
notif: notification.New(),
|
||||
}
|
||||
}
|
||||
|
||||
func (a appModel) Init() tea.Cmd {
|
||||
return tea.Batch(a.core.Init(), a.modals.Init(), a.notif.Init())
|
||||
}
|
||||
|
||||
func (a appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
if _, ok := msg.(app.QuitMsg); ok {
|
||||
return a, tea.Quit
|
||||
}
|
||||
|
||||
a.core.ModalOpen = a.modals.Open()
|
||||
var coreCmd tea.Cmd
|
||||
a.core, coreCmd = a.core.Update(msg)
|
||||
|
||||
var modalCmd, notifCmd tea.Cmd
|
||||
a.modals, modalCmd = a.modals.Update(msg)
|
||||
a.notif, notifCmd = a.notif.Update(msg)
|
||||
|
||||
return a, tea.Batch(coreCmd, modalCmd, notifCmd)
|
||||
}
|
||||
|
||||
func (a appModel) View() tea.View {
|
||||
bg := a.core.View()
|
||||
bg = a.modals.Render(bg)
|
||||
bg = a.notif.Render(bg)
|
||||
return tea.View{
|
||||
Content: bg,
|
||||
AltScreen: true,
|
||||
WindowTitle: "USBGuard TUI",
|
||||
MouseMode: tea.MouseModeCellMotion,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
tea "charm.land/bubbletea/v2"
|
||||
"github.com/anotherhadi/usbguard-tui/internal/guard"
|
||||
)
|
||||
|
||||
var version = "dev"
|
||||
|
||||
func main() {
|
||||
if len(os.Args) > 1 && (os.Args[1] == "--version" || os.Args[1] == "-version" || os.Args[1] == "-v") {
|
||||
fmt.Println("usbguard-tui", version)
|
||||
return
|
||||
}
|
||||
|
||||
if err := guard.Check(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if _, err := guard.ListDevices(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
p := tea.NewProgram(newApp())
|
||||
if _, err := p.Run(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user