Skip to content

Commit

Permalink
refactor: conform to standards, remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
PhearZero committed Oct 21, 2024
1 parent 0c8edce commit 661e0b9
Show file tree
Hide file tree
Showing 16 changed files with 86 additions and 109 deletions.
12 changes: 12 additions & 0 deletions ui/controls/style.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package controls

import "github.com/charmbracelet/lipgloss"

var controlStyle = func() lipgloss.Style {
b := lipgloss.RoundedBorder()
b.Left = "┤"
b.Right = "├"
return lipgloss.NewStyle().
BorderStyle(lipgloss.RoundedBorder()).
BorderStyle(b)
}()
11 changes: 0 additions & 11 deletions ui/controls/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,6 @@ import (
"strings"
)

var roundedBorder = func() lipgloss.Style {
return lipgloss.NewStyle().
BorderStyle(lipgloss.RoundedBorder())
}()
var controlStyle = func() lipgloss.Style {
b := lipgloss.RoundedBorder()
b.Left = "┤"
b.Right = "├"
return roundedBorder.BorderStyle(b)
}()

// View renders the model's content if it is visible, aligning it horizontally and ensuring it fits within the specified width.
func (m Model) View() string {
if !m.IsVisible {
Expand Down
13 changes: 13 additions & 0 deletions ui/pages/accounts/cmds.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package accounts

import (
"github.com/algorandfoundation/hack-tui/internal"
tea "github.com/charmbracelet/bubbletea"
)

// EmitAccountSelected waits for and retrieves a new set of table rows from a given channel.
func EmitAccountSelected(account internal.Account) tea.Cmd {
return func() tea.Msg {
return account
}
}
6 changes: 0 additions & 6 deletions ui/pages/accounts/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ import (
"github.com/charmbracelet/lipgloss"
)

// EmitAccountSelected waits for and retrieves a new set of table rows from a given channel.
func EmitAccountSelected(account internal.Account) tea.Cmd {
return func() tea.Msg {
return account
}
}
func (m ViewModel) Init() tea.Cmd {
return nil
}
Expand Down
2 changes: 0 additions & 2 deletions ui/pages/accounts/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"strconv"
)

var green = lipgloss.NewStyle().Foreground(lipgloss.Color("10"))

type ViewModel struct {
Width int
Height int
Expand Down
5 changes: 5 additions & 0 deletions ui/pages/accounts/style.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package accounts

import "github.com/charmbracelet/lipgloss"

var green = lipgloss.NewStyle().Foreground(lipgloss.Color("10"))
9 changes: 0 additions & 9 deletions ui/pages/accounts/utils.go

This file was deleted.

26 changes: 12 additions & 14 deletions ui/pages/generate/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,16 @@ package generate

import (
"context"
"fmt"
"github.com/algorandfoundation/hack-tui/api"
"github.com/algorandfoundation/hack-tui/internal"
"github.com/algorandfoundation/hack-tui/ui/pages/accounts"
"github.com/charmbracelet/bubbles/cursor"
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/log"
"strconv"
)

var (
focusedStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("205"))
blurredStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("240"))
cursorStyle = focusedStyle
noStyle = lipgloss.NewStyle()
helpStyle = blurredStyle
cursorModeHelpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("244"))

focusedButton = focusedStyle.Render("[ Submit ]")
blurredButton = fmt.Sprintf("[ %s ]", blurredStyle.Render("Submit"))
)

func (m ViewModel) Init() tea.Cmd {
return textinput.Blink
}
Expand Down Expand Up @@ -107,3 +93,15 @@ func (m ViewModel) HandleMessage(msg tea.Msg) (ViewModel, tea.Cmd) {
cmd := m.updateInputs(msg)
return m, cmd
}

func (m ViewModel) updateInputs(msg tea.Msg) tea.Cmd {
cmds := make([]tea.Cmd, len(m.Inputs))

// Only text inputs with Focus() set will respond, so it's safe to simply
// update all of them here without any further logic.
for i := range m.Inputs {
m.Inputs[i], cmds[i] = m.Inputs[i].Update(msg)
}

return tea.Batch(cmds...)
}
13 changes: 0 additions & 13 deletions ui/pages/generate/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/algorandfoundation/hack-tui/api"
"github.com/charmbracelet/bubbles/cursor"
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
)

type ViewModel struct {
Expand All @@ -15,18 +14,6 @@ type ViewModel struct {
cursorMode cursor.Mode
}

func (m *ViewModel) updateInputs(msg tea.Msg) tea.Cmd {
cmds := make([]tea.Cmd, len(m.Inputs))

// Only text inputs with Focus() set will respond, so it's safe to simply
// update all of them here without any further logic.
for i := range m.Inputs {
m.Inputs[i], cmds[i] = m.Inputs[i].Update(msg)
}

return tea.Batch(cmds...)
}

func New(address string, client *api.ClientWithResponses) ViewModel {
m := ViewModel{
Address: address,
Expand Down
18 changes: 18 additions & 0 deletions ui/pages/generate/style.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package generate

import (
"fmt"
"github.com/charmbracelet/lipgloss"
)

var (
focusedStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("205"))
blurredStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("240"))
cursorStyle = focusedStyle
noStyle = lipgloss.NewStyle()
helpStyle = blurredStyle
cursorModeHelpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("244"))

focusedButton = focusedStyle.Render("[ Submit ]")
blurredButton = fmt.Sprintf("[ %s ]", blurredStyle.Render("Submit"))
)
21 changes: 21 additions & 0 deletions ui/pages/keys/cmds.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package keys

import (
"github.com/algorandfoundation/hack-tui/api"
tea "github.com/charmbracelet/bubbletea"
)

type DeleteKey *api.ParticipationKey

func EmitDeleteKey(key *api.ParticipationKey) tea.Cmd {
return func() tea.Msg {
return DeleteKey(key)
}
}

// EmitKeySelected waits for and retrieves a new set of table rows from a given channel.
func EmitKeySelected(key *api.ParticipationKey) tea.Cmd {
return func() tea.Msg {
return key
}
}
15 changes: 0 additions & 15 deletions ui/pages/keys/controller.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
package keys

import (
"github.com/algorandfoundation/hack-tui/api"
"github.com/algorandfoundation/hack-tui/internal"
"github.com/algorandfoundation/hack-tui/ui/pages"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)

// EmitKeySelected waits for and retrieves a new set of table rows from a given channel.
func EmitKeySelected(key *api.ParticipationKey) tea.Cmd {
return func() tea.Msg {
return key
}
}

type DeleteKey *api.ParticipationKey

func EmitDeleteKey(key *api.ParticipationKey) tea.Cmd {
return func() tea.Msg {
return DeleteKey(key)
}
}
func (m ViewModel) Init() tea.Cmd {
return nil
}
Expand Down
2 changes: 0 additions & 2 deletions ui/pages/keys/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"sort"
)

var green = lipgloss.NewStyle().Foreground(lipgloss.Color("10"))

type ViewModel struct {
Address string
Data *[]api.ParticipationKey
Expand Down
5 changes: 5 additions & 0 deletions ui/pages/keys/style.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package keys

import "github.com/charmbracelet/lipgloss"

var green = lipgloss.NewStyle().Foreground(lipgloss.Color("10"))
9 changes: 0 additions & 9 deletions ui/pages/keys/utils.go

This file was deleted.

28 changes: 0 additions & 28 deletions ui/utils.go

This file was deleted.

0 comments on commit 661e0b9

Please sign in to comment.