mirror of
https://github.com/IllusionMan1212/gorc.git
synced 2026-10-24 02:12:33 +00:00
feat: disable connect button when host, port and nickname are empty
This commit is contained in:
+30
-14
@@ -28,27 +28,32 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type State struct {
|
type State struct {
|
||||||
FocusIndex int
|
FocusIndex int
|
||||||
Inputs []textinput.Model
|
Inputs []textinput.Model
|
||||||
TLS bool
|
TLS bool
|
||||||
DialogStyle lipgloss.Style
|
CanConnect bool
|
||||||
WelcomeMsgStyle lipgloss.Style
|
ConnectButtonBlurredStyle string
|
||||||
Style lipgloss.Style
|
ConnectButtonFocusedStyle string
|
||||||
|
DialogStyle lipgloss.Style
|
||||||
|
WelcomeMsgStyle lipgloss.Style
|
||||||
|
Style lipgloss.Style
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLogin() State {
|
func NewLogin() State {
|
||||||
state := State{
|
state := State{
|
||||||
Inputs: make([]textinput.Model, 5),
|
Inputs: make([]textinput.Model, 5),
|
||||||
DialogStyle: DialogStyle.Copy(),
|
ConnectButtonBlurredStyle: BlurredDisabledButton,
|
||||||
WelcomeMsgStyle: WelcomeMsgStyle.Copy(),
|
ConnectButtonFocusedStyle: FocusedDisabledButton,
|
||||||
Style: ui.MainStyle.Copy(),
|
DialogStyle: DialogStyle.Copy(),
|
||||||
|
WelcomeMsgStyle: WelcomeMsgStyle.Copy(),
|
||||||
|
Style: ui.MainStyle.Copy(),
|
||||||
}
|
}
|
||||||
|
|
||||||
var t textinput.Model
|
var t textinput.Model
|
||||||
for i := range state.Inputs {
|
for i := range state.Inputs {
|
||||||
t = textinput.New()
|
t = textinput.New()
|
||||||
t.CursorStyle = CursorStyle
|
t.CursorStyle = CursorStyle
|
||||||
t.Prompt = "| "
|
t.Prompt = ""
|
||||||
|
|
||||||
switch i {
|
switch i {
|
||||||
case 0:
|
case 0:
|
||||||
@@ -85,7 +90,8 @@ func (s State) Update(msg tea.Msg) (State, tea.Cmd) {
|
|||||||
switch key {
|
switch key {
|
||||||
case " ", "enter":
|
case " ", "enter":
|
||||||
// run the Connect cmd when pressing "enter" while focused on the connect button
|
// run the Connect cmd when pressing "enter" while focused on the connect button
|
||||||
if key == "enter" && s.FocusIndex == len(s.Inputs)+1 {
|
// if the CanConnect flag is set
|
||||||
|
if key == "enter" && s.FocusIndex == len(s.Inputs)+1 && s.CanConnect {
|
||||||
return s, cmds.Connect
|
return s, cmds.Connect
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,6 +143,16 @@ func (s *State) updateInputs(msg tea.Msg) tea.Cmd {
|
|||||||
s.Inputs[i], cmds[i] = s.Inputs[i].Update(msg)
|
s.Inputs[i], cmds[i] = s.Inputs[i].Update(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.Inputs[0].Value() != "" && s.Inputs[1].Value() != "" && s.Inputs[3].Value() != "" {
|
||||||
|
s.ConnectButtonBlurredStyle = BlurredButton
|
||||||
|
s.ConnectButtonFocusedStyle = FocusedButton
|
||||||
|
s.CanConnect = true
|
||||||
|
} else {
|
||||||
|
s.ConnectButtonBlurredStyle = BlurredDisabledButton
|
||||||
|
s.ConnectButtonFocusedStyle = FocusedDisabledButton
|
||||||
|
s.CanConnect = false
|
||||||
|
}
|
||||||
|
|
||||||
return tea.Batch(cmds...)
|
return tea.Batch(cmds...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,9 +191,9 @@ func (s State) View() string {
|
|||||||
|
|
||||||
fmt.Fprintf(&sb, "\n%s\n", *checkbox)
|
fmt.Fprintf(&sb, "\n%s\n", *checkbox)
|
||||||
|
|
||||||
button := &BlurredButton
|
button := &s.ConnectButtonBlurredStyle
|
||||||
if s.FocusIndex == len(s.Inputs)+1 {
|
if s.FocusIndex == len(s.Inputs)+1 {
|
||||||
button = &FocusedButton
|
button = &s.ConnectButtonFocusedStyle
|
||||||
}
|
}
|
||||||
fmt.Fprintf(&sb, "\n%s\n", *button)
|
fmt.Fprintf(&sb, "\n%s\n", *button)
|
||||||
|
|
||||||
|
|||||||
+20
-4
@@ -36,6 +36,22 @@ const WelcomeMsg = `
|
|||||||
`
|
`
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
BlurredDisabledButton = lipgloss.NewStyle().
|
||||||
|
Border(lipgloss.NormalBorder()).
|
||||||
|
BorderForeground(ui.DisabledColor).
|
||||||
|
Foreground(ui.DisabledColor).
|
||||||
|
MarginTop(1).
|
||||||
|
Padding(0, 2).
|
||||||
|
Align(lipgloss.Center).
|
||||||
|
Render("Connect")
|
||||||
|
FocusedDisabledButton = lipgloss.NewStyle().
|
||||||
|
Border(lipgloss.NormalBorder()).
|
||||||
|
BorderForeground(ui.DisabledColorFocus).
|
||||||
|
Foreground(ui.DisabledColorFocus).
|
||||||
|
MarginTop(1).
|
||||||
|
Padding(0, 2).
|
||||||
|
Align(lipgloss.Center).
|
||||||
|
Render("Connect")
|
||||||
FocusedButton = lipgloss.NewStyle().
|
FocusedButton = lipgloss.NewStyle().
|
||||||
Border(lipgloss.NormalBorder()).
|
Border(lipgloss.NormalBorder()).
|
||||||
BorderForeground(ui.AccentColor).
|
BorderForeground(ui.AccentColor).
|
||||||
@@ -57,22 +73,22 @@ var (
|
|||||||
FocusedCheckbox = lipgloss.NewStyle().
|
FocusedCheckbox = lipgloss.NewStyle().
|
||||||
Foreground(ui.AccentColor).
|
Foreground(ui.AccentColor).
|
||||||
MarginTop(1).
|
MarginTop(1).
|
||||||
Render("✕ Enable TLS")
|
Render("TLS Enabled [✕]")
|
||||||
|
|
||||||
BlurredCheckbox = lipgloss.NewStyle().
|
BlurredCheckbox = lipgloss.NewStyle().
|
||||||
Foreground(ui.PrimaryColor).
|
Foreground(ui.PrimaryColor).
|
||||||
MarginTop(1).
|
MarginTop(1).
|
||||||
Render("✕ Enable TLS")
|
Render("TLS Enabled [✕]")
|
||||||
|
|
||||||
FocusedCheckboxChecked = lipgloss.NewStyle().
|
FocusedCheckboxChecked = lipgloss.NewStyle().
|
||||||
Foreground(ui.AccentColor).
|
Foreground(ui.AccentColor).
|
||||||
MarginTop(1).
|
MarginTop(1).
|
||||||
Render("🗸 Enable TLS")
|
Render("TLS Enabled [🗸]")
|
||||||
|
|
||||||
BlurredCheckboxChecked = lipgloss.NewStyle().
|
BlurredCheckboxChecked = lipgloss.NewStyle().
|
||||||
Foreground(ui.PrimaryColor).
|
Foreground(ui.PrimaryColor).
|
||||||
MarginTop(1).
|
MarginTop(1).
|
||||||
Render("🗸 Enable TLS")
|
Render("TLS Enabled [🗸]")
|
||||||
|
|
||||||
DialogStyle = lipgloss.NewStyle().
|
DialogStyle = lipgloss.NewStyle().
|
||||||
Align(lipgloss.Center)
|
Align(lipgloss.Center)
|
||||||
|
|||||||
@@ -225,10 +225,10 @@ func (s *State) SetSize(width, height int) {
|
|||||||
s.InputBox.SetSize(width)
|
s.InputBox.SetSize(width)
|
||||||
s.SidePanel.SetSize(width, height, s.InputBox.Style.GetVerticalFrameSize())
|
s.SidePanel.SetSize(width, height, s.InputBox.Style.GetVerticalFrameSize())
|
||||||
|
|
||||||
// We floor here because width is an int and some fractions are lost
|
// We floor because width is an int and some fractions are lost when casting
|
||||||
// and also because we ceil the sidepanel's width
|
// and also because we ceil the sidepanel's width
|
||||||
// -3 for the tab bar height
|
// -3 for the tab bar height
|
||||||
newWidth := int(math.Floor(float64(width)*8.0/10.0) - float64(s.Viewport.Style.GetHorizontalFrameSize()))
|
newWidth := int(math.Floor(float64(width)*8/10) - float64(s.Viewport.Style.GetHorizontalFrameSize()))
|
||||||
newHeight := height - s.InputBox.Style.GetVerticalFrameSize() - s.Viewport.Style.GetVerticalFrameSize() - 3
|
newHeight := height - s.InputBox.Style.GetVerticalFrameSize() - s.Viewport.Style.GetVerticalFrameSize() - 3
|
||||||
|
|
||||||
s.Viewport.Width = newWidth
|
s.Viewport.Width = newWidth
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ func (s *SidePanelState) UpdateNicks() {
|
|||||||
func (s *SidePanelState) SetSize(width, height, inputboxHeight int) {
|
func (s *SidePanelState) SetSize(width, height, inputboxHeight int) {
|
||||||
// We ceil here because width is an int and some fractions are lost
|
// We ceil here because width is an int and some fractions are lost
|
||||||
// -1 is for some extra invisible margin or padding between the sidepanel and the inputbox
|
// -1 is for some extra invisible margin or padding between the sidepanel and the inputbox
|
||||||
newWidth := int(math.Ceil(math.Ceil((float64(width) * 2.0 / 10.0)) - float64(s.Viewport.Style.GetHorizontalFrameSize())))
|
newWidth := int(math.Ceil(math.Ceil((float64(width) * 2 / 10)) - float64(s.Viewport.Style.GetHorizontalFrameSize())))
|
||||||
newHeight := height - inputboxHeight - s.Viewport.Style.GetVerticalFrameSize() - 1
|
newHeight := height - inputboxHeight - s.Viewport.Style.GetVerticalFrameSize() - 1
|
||||||
|
|
||||||
s.Viewport.Style = s.Viewport.Style.Width(newWidth)
|
s.Viewport.Style = s.Viewport.Style.Width(newWidth)
|
||||||
|
|||||||
@@ -95,11 +95,11 @@ var (
|
|||||||
leftArrowDim = tab.Copy().
|
leftArrowDim = tab.Copy().
|
||||||
Border(leftArrowBorder, true).
|
Border(leftArrowBorder, true).
|
||||||
BorderForeground(ui.PrimaryColor).
|
BorderForeground(ui.PrimaryColor).
|
||||||
Foreground(ui.ArrowsDimColor)
|
Foreground(ui.DisabledColor)
|
||||||
rightArrowDim = tab.Copy().
|
rightArrowDim = tab.Copy().
|
||||||
Border(rightArrowBorder, true).
|
Border(rightArrowBorder, true).
|
||||||
BorderForeground(ui.PrimaryColor).
|
BorderForeground(ui.PrimaryColor).
|
||||||
Foreground(ui.ArrowsDimColor)
|
Foreground(ui.DisabledColor)
|
||||||
|
|
||||||
leftArrowLit = tab.Copy().
|
leftArrowLit = tab.Copy().
|
||||||
Border(leftArrowBorder, true).
|
Border(leftArrowBorder, true).
|
||||||
|
|||||||
+6
-1
@@ -33,8 +33,13 @@ var (
|
|||||||
Light: "#151515",
|
Light: "#151515",
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrowsDimColor = lipgloss.AdaptiveColor{
|
DisabledColor = lipgloss.AdaptiveColor{
|
||||||
Dark: "#444",
|
Dark: "#444",
|
||||||
Light: "#AAA",
|
Light: "#AAA",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DisabledColorFocus = lipgloss.AdaptiveColor{
|
||||||
|
Dark: "#666",
|
||||||
|
Light: "#CCC",
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user