Added bento :)
This commit is contained in:
+28
-6
@@ -14,17 +14,20 @@ const (
|
||||
urlInput inputScreenState = iota
|
||||
usernameInput
|
||||
tokenInput
|
||||
connNameInput
|
||||
)
|
||||
|
||||
type InputScreen struct {
|
||||
urlField textinput.Model
|
||||
usernameField textinput.Model
|
||||
tokenField textinput.Model
|
||||
connNameField textinput.Model
|
||||
focusedField inputScreenState
|
||||
err error
|
||||
url string
|
||||
username string
|
||||
token string
|
||||
connName string
|
||||
done bool
|
||||
}
|
||||
|
||||
@@ -40,10 +43,14 @@ func NewInputScreen() *InputScreen {
|
||||
tokenField.Placeholder = "your_access_token"
|
||||
tokenField.EchoMode = textinput.EchoPassword
|
||||
|
||||
connNameField := textinput.New()
|
||||
connNameField.Placeholder = "(optional) Connection name"
|
||||
|
||||
return &InputScreen{
|
||||
urlField: urlField,
|
||||
usernameField: usernameField,
|
||||
tokenField: tokenField,
|
||||
connNameField: connNameField,
|
||||
focusedField: urlInput,
|
||||
}
|
||||
}
|
||||
@@ -72,6 +79,11 @@ func (is *InputScreen) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return is, nil
|
||||
case tokenInput:
|
||||
is.token = is.tokenField.Value()
|
||||
is.focusedField = connNameInput
|
||||
is.connNameField.Focus()
|
||||
return is, nil
|
||||
case connNameInput:
|
||||
is.connName = is.connNameField.Value()
|
||||
is.done = true
|
||||
return is, nil
|
||||
}
|
||||
@@ -83,17 +95,20 @@ func (is *InputScreen) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
is.username = is.usernameField.Value()
|
||||
case tokenInput:
|
||||
is.token = is.tokenField.Value()
|
||||
case connNameInput:
|
||||
is.connName = is.connNameField.Value()
|
||||
}
|
||||
|
||||
if msg.Type == tea.KeyTab {
|
||||
is.focusedField = (is.focusedField + 1) % 3
|
||||
is.focusedField = (is.focusedField + 1) % 4
|
||||
} else {
|
||||
is.focusedField = (is.focusedField - 1 + 3) % 3
|
||||
is.focusedField = (is.focusedField - 1 + 4) % 4
|
||||
}
|
||||
|
||||
is.urlField.Blur()
|
||||
is.usernameField.Blur()
|
||||
is.tokenField.Blur()
|
||||
is.connNameField.Blur()
|
||||
|
||||
switch is.focusedField {
|
||||
case urlInput:
|
||||
@@ -102,6 +117,8 @@ func (is *InputScreen) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
is.usernameField.Focus()
|
||||
case tokenInput:
|
||||
is.tokenField.Focus()
|
||||
case connNameInput:
|
||||
is.connNameField.Focus()
|
||||
}
|
||||
return is, nil
|
||||
}
|
||||
@@ -119,6 +136,8 @@ func (is *InputScreen) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
is.usernameField, cmd = is.usernameField.Update(msg)
|
||||
case tokenInput:
|
||||
is.tokenField, cmd = is.tokenField.Update(msg)
|
||||
case connNameInput:
|
||||
is.connNameField, cmd = is.connNameField.Update(msg)
|
||||
}
|
||||
|
||||
return is, cmd
|
||||
@@ -132,7 +151,7 @@ func (is *InputScreen) View() string {
|
||||
Bold(true).
|
||||
Render("Gitea Wrapped") + "\n\n"
|
||||
|
||||
s += "Enter your Gitea credentials to get started:\n\n"
|
||||
s += "Enter your Gitea credentials:\n\n"
|
||||
|
||||
s += "Gitea URL\n"
|
||||
s += is.urlField.View() + "\n\n"
|
||||
@@ -143,6 +162,9 @@ func (is *InputScreen) View() string {
|
||||
s += "Access Token\n"
|
||||
s += is.tokenField.View() + "\n\n"
|
||||
|
||||
s += "Connection Name (optional - to save for later)\n"
|
||||
s += is.connNameField.View() + "\n\n"
|
||||
|
||||
if is.err != nil {
|
||||
s += lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("1")).
|
||||
@@ -151,7 +173,7 @@ func (is *InputScreen) View() string {
|
||||
|
||||
s += lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("8")).
|
||||
Render("(press Tab to navigate, Enter to continue, Ctrl+C to quit)") + "\n"
|
||||
Render("(Tab to navigate, Enter to continue, Ctrl+C to quit)") + "\n"
|
||||
|
||||
return s
|
||||
}
|
||||
@@ -160,8 +182,8 @@ func (is *InputScreen) IsDone() bool {
|
||||
return is.done
|
||||
}
|
||||
|
||||
func (is *InputScreen) GetCredentials() (string, string, string) {
|
||||
return is.url, is.username, is.token
|
||||
func (is *InputScreen) GetCredentials() (url, username, token, connName string) {
|
||||
return is.url, is.username, is.token, is.connName
|
||||
}
|
||||
|
||||
type errMsg error
|
||||
|
||||
Reference in New Issue
Block a user