Skip to content

Commit

Permalink
BUGFIX-60: Move input component into a eparate folder
Browse files Browse the repository at this point in the history
  • Loading branch information
grafviktor committed Apr 16, 2024
1 parent 4f6ac6f commit 9e1bec0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 24 deletions.
9 changes: 5 additions & 4 deletions internal/ui/component/hostedit/hostedit.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/grafviktor/goto/internal/state"
"github.com/grafviktor/goto/internal/storage"
"github.com/grafviktor/goto/internal/ui/component/hostlist"
"github.com/grafviktor/goto/internal/ui/component/input"
"github.com/grafviktor/goto/internal/ui/message"
"github.com/grafviktor/goto/internal/utils"
)
Expand Down Expand Up @@ -100,7 +101,7 @@ type editModel struct {
help help.Model
host model.Host
hostStorage storage.HostStorage
inputs []labeledInput
inputs []input.Input
isNewHost bool
keyMap keyMap
logger iLogger
Expand All @@ -123,7 +124,7 @@ func New(ctx context.Context, storage storage.HostStorage, state *state.Applicat
}

m := editModel{
inputs: make([]labeledInput, 6),
inputs: make([]input.Input, 6),
hostStorage: storage,
host: host,
help: help.New(),
Expand All @@ -138,9 +139,9 @@ func New(ctx context.Context, storage storage.HostStorage, state *state.Applicat
isNewHost: hostNotFoundErr != nil,
}

var t labeledInput
var t input.Input
for i := range m.inputs {
t = *NewLabeledInput()
t = *input.New()
t.Cursor.Style = cursorStyle

switch i {
Expand Down
16 changes: 6 additions & 10 deletions internal/ui/component/hostedit/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,22 @@ package hostedit
import "github.com/charmbracelet/lipgloss"

var (
docStyle = lipgloss.NewStyle().Margin(1, 2)
focusedStyle = lipgloss.NewStyle().
docStyle = lipgloss.NewStyle().Margin(1, 2) //

// the same as focusedStyle in labeledinput

Check failure on line 8 in internal/ui/component/hostedit/style.go

View workflow job for this annotation

GitHub Actions / golangci-lint

Comment should end in a period (godot)
cursorStyle = lipgloss.NewStyle().
BorderForeground(lipgloss.AdaptiveColor{Light: "#F793FF", Dark: "#AD58B4"}).
Foreground(lipgloss.AdaptiveColor{Light: "#EE6FF8", Dark: "#EE6FF8"})
errorStyle = lipgloss.NewStyle().
BorderForeground(lipgloss.AdaptiveColor{Light: "#F793FF", Dark: "#AD58B4"}).
Foreground(lipgloss.AdaptiveColor{Light: "#FF7783", Dark: "#FF7783"})
cursorStyle = focusedStyle.Copy()
focusedInputText = lipgloss.NewStyle().Foreground(lipgloss.Color("#AD58B4"))
noStyle = lipgloss.NewStyle()

titleStyle = lipgloss.NewStyle().
titleStyle = lipgloss.NewStyle(). //
Background(lipgloss.Color("62")).
Foreground(lipgloss.Color("230")).
Padding(0, 1).
// Instead of placing "1" to have a padding at the bottom,
// I use '\n' in the code base. That is to a rendering artifacts
Margin(1, 4, 0)

menuStyle = lipgloss.NewStyle().Margin(3, 4, 0)
menuStyle = lipgloss.NewStyle().Margin(3, 4, 0) //
)

//nolint:dupword
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package hostedit
package input

Check warning on line 1 in internal/ui/component/input/input.go

View workflow job for this annotation

GitHub Actions / golangci-lint

package-comments: should have a package comment (revive)

import (
"fmt"
Expand All @@ -9,27 +9,27 @@ import (
tea "github.com/charmbracelet/bubbletea"
)

// NewLabeledInput - component which consists from input and label.
func NewLabeledInput() *labeledInput {
// New - component which consists from input and label.
func New() *Input {
inputModel := textinput.New()
inputModel.Prompt = ""

return &labeledInput{
return &Input{
Model: inputModel,
FocusedPrompt: "│ ",
}
}

type labeledInput struct {
type Input struct {

Check warning on line 23 in internal/ui/component/input/input.go

View workflow job for this annotation

GitHub Actions / golangci-lint

exported: exported type Input should have comment or be unexported (revive)
textinput.Model
Label string
FocusedPrompt string
Err error
}

func (l *labeledInput) Init() tea.Cmd { return nil }
func (l *Input) Init() tea.Cmd { return nil }

Check warning on line 30 in internal/ui/component/input/input.go

View workflow job for this annotation

GitHub Actions / golangci-lint

exported: exported method Input.Init should have comment or be unexported (revive)

Check warning on line 30 in internal/ui/component/input/input.go

View check run for this annotation

Codecov / codecov/patch

internal/ui/component/input/input.go#L30

Added line #L30 was not covered by tests

func (l *labeledInput) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (l *Input) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

Check warning on line 32 in internal/ui/component/input/input.go

View workflow job for this annotation

GitHub Actions / golangci-lint

exported: exported method Input.Update should have comment or be unexported (revive)
var cmd tea.Cmd

l.Model, cmd = l.Model.Update(msg)
Expand All @@ -41,7 +41,7 @@ func (l *labeledInput) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return l, cmd
}

func (l *labeledInput) View() string {
func (l *Input) View() string {

Check warning on line 44 in internal/ui/component/input/input.go

View workflow job for this annotation

GitHub Actions / golangci-lint

exported: exported method Input.View should have comment or be unexported (revive)
var view string
if l.Focused() {
view = focusedInputText.Render(l.Model.View())
Expand All @@ -52,15 +52,15 @@ func (l *labeledInput) View() string {
return fmt.Sprintf("%s\n%s%s", l.labelView(), l.prompt(), view)
}

func (l *labeledInput) prompt() string {
func (l *Input) prompt() string {
if l.Focused() {
return focusedStyle.Render(l.FocusedPrompt)
}

return strings.Repeat(" ", utf8.RuneCountInString(l.FocusedPrompt))
}

func (l *labeledInput) labelView() string {
func (l *Input) labelView() string {
if l.Err != nil {
return l.prompt() + errorStyle.Render(l.Label)
} else if l.Focused() {
Expand Down
14 changes: 14 additions & 0 deletions internal/ui/component/input/style.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package input

Check failure on line 1 in internal/ui/component/input/style.go

View workflow job for this annotation

GitHub Actions / golangci-lint

ST1000: at least one file in a package should have a package comment (stylecheck)

import "github.com/charmbracelet/lipgloss"

var (
focusedStyle = lipgloss.NewStyle().
BorderForeground(lipgloss.AdaptiveColor{Light: "#F793FF", Dark: "#AD58B4"}).
Foreground(lipgloss.AdaptiveColor{Light: "#EE6FF8", Dark: "#EE6FF8"})
errorStyle = lipgloss.NewStyle().
BorderForeground(lipgloss.AdaptiveColor{Light: "#F793FF", Dark: "#AD58B4"}).
Foreground(lipgloss.AdaptiveColor{Light: "#FF7783", Dark: "#FF7783"})
focusedInputText = lipgloss.NewStyle().Foreground(lipgloss.Color("#AD58B4"))
noStyle = lipgloss.NewStyle()
)

0 comments on commit 9e1bec0

Please sign in to comment.