mirror of
https://github.com/IllusionMan1212/gorc.git
synced 2026-10-24 02:12:33 +00:00
fix(login): manually set the width for the textinput fields
This commit is contained in:
+17
-14
@@ -17,7 +17,6 @@
|
|||||||
package login
|
package login
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/charmbracelet/bubbles/textinput"
|
"github.com/charmbracelet/bubbles/textinput"
|
||||||
@@ -60,22 +59,27 @@ func NewLogin() State {
|
|||||||
t.Placeholder = "Host"
|
t.Placeholder = "Host"
|
||||||
t.Focus()
|
t.Focus()
|
||||||
t.CharLimit = 40
|
t.CharLimit = 40
|
||||||
|
t.Width = len(t.Placeholder)
|
||||||
t.TextStyle = FocusedStyle
|
t.TextStyle = FocusedStyle
|
||||||
t.Validate = NoSpacesValidation
|
t.Validate = NoSpacesValidation
|
||||||
case 1:
|
case 1:
|
||||||
t.Placeholder = "Port"
|
t.Placeholder = "Port"
|
||||||
t.CharLimit = 5
|
t.CharLimit = 5
|
||||||
|
t.Width = len(t.Placeholder)
|
||||||
t.Validate = ValidatePort
|
t.Validate = ValidatePort
|
||||||
case 2:
|
case 2:
|
||||||
t.Placeholder = "Channel"
|
t.Placeholder = "Channel"
|
||||||
t.CharLimit = 32
|
t.CharLimit = 32
|
||||||
|
t.Width = len(t.Placeholder)
|
||||||
case 3:
|
case 3:
|
||||||
t.Placeholder = "Nickname"
|
t.Placeholder = "Nickname"
|
||||||
t.CharLimit = 32
|
t.CharLimit = 32
|
||||||
|
t.Width = len(t.Placeholder)
|
||||||
t.Validate = NoSpacesValidation
|
t.Validate = NoSpacesValidation
|
||||||
case 4:
|
case 4:
|
||||||
t.Placeholder = "Password"
|
t.Placeholder = "Password"
|
||||||
t.CharLimit = 64
|
t.CharLimit = 64
|
||||||
|
t.Width = len(t.Placeholder)
|
||||||
t.EchoMode = textinput.EchoPassword
|
t.EchoMode = textinput.EchoPassword
|
||||||
t.EchoCharacter = '•'
|
t.EchoCharacter = '•'
|
||||||
}
|
}
|
||||||
@@ -144,6 +148,7 @@ func (s *State) updateInputs(msg tea.Msg) tea.Cmd {
|
|||||||
|
|
||||||
for i := range s.Inputs {
|
for i := range s.Inputs {
|
||||||
s.Inputs[i], cmds[i] = s.Inputs[i].Update(msg)
|
s.Inputs[i], cmds[i] = s.Inputs[i].Update(msg)
|
||||||
|
s.Inputs[i].Width = max(len(s.Inputs[i].Placeholder), len(s.Inputs[i].Value()))
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.Inputs[0].Value() != "" && s.Inputs[1].Value() != "" && s.Inputs[3].Value() != "" {
|
if s.Inputs[0].Value() != "" && s.Inputs[1].Value() != "" && s.Inputs[3].Value() != "" {
|
||||||
@@ -169,36 +174,34 @@ func (s *State) SetSize(width, height int) {
|
|||||||
|
|
||||||
func (s State) View() string {
|
func (s State) View() string {
|
||||||
var sb strings.Builder
|
var sb strings.Builder
|
||||||
|
for i, input := range s.Inputs {
|
||||||
for i := range s.Inputs {
|
sb.WriteString(input.View())
|
||||||
sb.WriteString(s.Inputs[i].View())
|
if i < len(s.Inputs) {
|
||||||
if i < len(s.Inputs)-1 {
|
|
||||||
sb.WriteRune('\n')
|
sb.WriteRune('\n')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
checkbox := &BlurredCheckbox
|
checkbox := BlurredCheckbox
|
||||||
// if the checkbox is focused
|
// if the checkbox is focused
|
||||||
if s.FocusIndex == len(s.Inputs) {
|
if s.FocusIndex == len(s.Inputs) {
|
||||||
checkbox = &FocusedCheckbox
|
checkbox = FocusedCheckbox
|
||||||
// if tls is enabled
|
// if tls is enabled
|
||||||
if s.TLS {
|
if s.TLS {
|
||||||
checkbox = &FocusedCheckboxChecked
|
checkbox = FocusedCheckboxChecked
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the checkbox is not focused and tls is enabled
|
// if the checkbox is not focused and tls is enabled
|
||||||
if s.FocusIndex != len(s.Inputs) && s.TLS {
|
if s.FocusIndex != len(s.Inputs) && s.TLS {
|
||||||
checkbox = &BlurredCheckboxChecked
|
checkbox = BlurredCheckboxChecked
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(&sb, "\n%s\n", *checkbox)
|
button := s.ConnectButtonBlurredStyle
|
||||||
|
|
||||||
button := &s.ConnectButtonBlurredStyle
|
|
||||||
if s.FocusIndex == len(s.Inputs)+1 {
|
if s.FocusIndex == len(s.Inputs)+1 {
|
||||||
button = &s.ConnectButtonFocusedStyle
|
button = s.ConnectButtonFocusedStyle
|
||||||
}
|
}
|
||||||
fmt.Fprintf(&sb, "\n%s\n", *button)
|
|
||||||
|
sb.WriteString(lipgloss.JoinVertical(lipgloss.Center, checkbox, button))
|
||||||
|
|
||||||
screen := lipgloss.JoinVertical(lipgloss.Center, s.WelcomeMsgStyle.Render(WelcomeMsg), s.DialogStyle.Render(sb.String()))
|
screen := lipgloss.JoinVertical(lipgloss.Center, s.WelcomeMsgStyle.Render(WelcomeMsg), s.DialogStyle.Render(sb.String()))
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -90,10 +90,10 @@ var (
|
|||||||
Render("TLS Enabled [✔]")
|
Render("TLS Enabled [✔]")
|
||||||
|
|
||||||
DialogStyle = lipgloss.NewStyle().
|
DialogStyle = lipgloss.NewStyle().
|
||||||
Align(lipgloss.Center)
|
AlignHorizontal(lipgloss.Center)
|
||||||
|
|
||||||
WelcomeMsgStyle = lipgloss.NewStyle().
|
WelcomeMsgStyle = lipgloss.NewStyle().
|
||||||
Align(lipgloss.Center).
|
AlignHorizontal(lipgloss.Center).
|
||||||
Foreground(ui.PrimaryColor)
|
Foreground(ui.PrimaryColor)
|
||||||
|
|
||||||
CursorStyle = lipgloss.NewStyle().
|
CursorStyle = lipgloss.NewStyle().
|
||||||
|
|||||||
Reference in New Issue
Block a user