chore: gofmt
This commit is contained in:
parent
17ceeb3666
commit
1193989c56
82
main.go
82
main.go
|
@ -1,25 +1,26 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
"github.com/charmbracelet/bubbles/help"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/bubbles/key"
|
||||||
"github.com/charmbracelet/bubbles/key"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/bubbles/help"
|
"github.com/charmbracelet/lipgloss"
|
||||||
|
|
||||||
"github.com/prometheus-community/pro-bing"
|
"github.com/prometheus-community/pro-bing"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
checkMark = lipgloss.NewStyle().Foreground(lipgloss.Color("42")).SetString("✓")
|
checkMark = lipgloss.NewStyle().Foreground(lipgloss.Color("42")).SetString("✓")
|
||||||
docStyle = lipgloss.NewStyle().Margin(1, 2)
|
docStyle = lipgloss.NewStyle().Margin(1, 2)
|
||||||
)
|
)
|
||||||
|
|
||||||
type keyMap struct {
|
type keyMap struct {
|
||||||
Quit key.Binding
|
Quit key.Binding
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k keyMap) ShortHelp() []key.Binding {
|
func (k keyMap) ShortHelp() []key.Binding {
|
||||||
return []key.Binding{k.Quit}
|
return []key.Binding{k.Quit}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +29,7 @@ func (k keyMap) FullHelp() [][]key.Binding {
|
||||||
{k.Quit},
|
{k.Quit},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var keys = keyMap{
|
var keys = keyMap{
|
||||||
Quit: key.NewBinding(
|
Quit: key.NewBinding(
|
||||||
key.WithKeys("q", "esc", "ctrl+c"),
|
key.WithKeys("q", "esc", "ctrl+c"),
|
||||||
|
@ -36,53 +38,53 @@ var keys = keyMap{
|
||||||
}
|
}
|
||||||
|
|
||||||
type model struct {
|
type model struct {
|
||||||
keys keyMap
|
keys keyMap
|
||||||
help help.Model
|
help help.Model
|
||||||
addresses []string
|
addresses []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func initialModel() model {
|
func initialModel() model {
|
||||||
return model{
|
return model{
|
||||||
keys: keys,
|
keys: keys,
|
||||||
help: help.New(),
|
help: help.New(),
|
||||||
addresses: []string{"100.64.0.1", "100.64.0.2"},
|
addresses: []string{"100.64.0.1", "100.64.0.2"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m model) Init() tea.Cmd {
|
func (m model) Init() tea.Cmd {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case tea.KeyMsg:
|
case tea.KeyMsg:
|
||||||
switch {
|
switch {
|
||||||
case key.Matches(msg, m.keys.Quit):
|
case key.Matches(msg, m.keys.Quit):
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m model) View() string {
|
func (m model) View() string {
|
||||||
s := "Pinging hosts...\n\n"
|
s := "Pinging hosts...\n\n"
|
||||||
for _, address := range m.addresses {
|
for _, address := range m.addresses {
|
||||||
_, err := probing.NewPinger(fmt.Sprintf("%s", address))
|
_, err := probing.NewPinger(fmt.Sprintf("%s", address))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
} else {
|
} else {
|
||||||
s += fmt.Sprintf("%s %s\n", checkMark, address)
|
s += fmt.Sprintf("%s %s\n", checkMark, address)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
helpView := m.help.View(m.keys)
|
helpView := m.help.View(m.keys)
|
||||||
return docStyle.Render(s + "\n" + helpView)
|
return docStyle.Render(s + "\n" + helpView)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
p := tea.NewProgram(initialModel())
|
p := tea.NewProgram(initialModel())
|
||||||
if _, err := p.Run(); err != nil {
|
if _, err := p.Run(); err != nil {
|
||||||
fmt.Printf("Error: %v", err)
|
fmt.Printf("Error: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue