Skip to content

Commit

Permalink
Added the logic to get the input from the textinput when connect key …
Browse files Browse the repository at this point in the history
…is pressed
  • Loading branch information
MayukhSobo committed May 15, 2024
1 parent dfbb44c commit 8cfc830
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
8 changes: 8 additions & 0 deletions db/database.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package db

type Database interface {
Connect()
Ping()
Execute()
Close()
}
7 changes: 7 additions & 0 deletions internal/app/home/home.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package home

import (
"math/rand"
"os"
"spectacle/db"
"spectacle/logger"

tea "github.com/charmbracelet/bubbletea"
Expand All @@ -11,6 +13,11 @@ func (m HomeScreenModel) Init() tea.Cmd {
return nil
}

func ping(endpoint string, db *db.Database) (AlertType, error) {
values := []AlertType{GOOD_CONNECTION, NO_CONNECTION}
return values[rand.Intn(2)], nil
}

func Start() {
m := NewHomeScreenModel("What is the ETCD endpoint?")
p := tea.NewProgram(m, tea.WithAltScreen())
Expand Down
13 changes: 12 additions & 1 deletion internal/app/home/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (m HomeScreenModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.KeyMsg:
switch {
case key.Matches(msg, m.Keys.Command):
logger.Log.Debugf("Command key is pressed!")
logger.Log.Debugf("Command Mode!")
m.Help.IsActive = !m.Help.IsActive
}
if m.Help.IsActive {
Expand All @@ -31,6 +31,17 @@ func (m HomeScreenModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
cmd = tea.ClearScreen
case key.Matches(msg, m.Keys.Connect):
m.Tooltip.Active = !m.Tooltip.Active
// Try to get the address from the input
address := m.Input.model.Value()
alert, err := ping(address, nil)
if err != nil {
logger.Log.Errorf("Encountered error: %+v", err)
break
}
m.Tooltip.Alert = alert
// Connect to the endpoint
// If success, m.Tooltip.Alert = GOOD_CONNECTION
// else m.Tooltip.Alert = NO_CONNECTION
cmd = tea.ClearScreen
case key.Matches(msg, m.Keys.Clear):
m.Input.model.SetValue("")
Expand Down

0 comments on commit 8cfc830

Please sign in to comment.