Batman! (this commit has no parents)

This commit is contained in:
2025-05-13 09:49:02 -04:00
parent 9dbd7ecab8
commit 23629a40a8
3 changed files with 75 additions and 17 deletions

View File

@@ -3,6 +3,7 @@ package interactive
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
cbhelp "github.com/charmbracelet/bubbles/help"
"github.com/charmbracelet/bubbles/key"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/huh"
@@ -21,6 +22,7 @@ type Model struct {
err error
focusField huh.Field
inParamsFields bool
help cbhelp.Model
}
type UrlParam interface {
@@ -61,6 +63,8 @@ func InitialModel(c *cli.Context) Model {
m.generator = g
m.help = cbhelp.New()
return m
}
@@ -74,6 +78,7 @@ func (m Model) initialFields() []huh.Field {
params.NewResize(),
params.NewMinWidth(),
params.NewMinHeight(),
params.NewQuality(),
params.NewZoom(),
params.NewEnlarge(),
}

View File

@@ -0,0 +1,41 @@
package params
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/charmbracelet/huh"
)
type Quality struct {
value *string
field *huh.Input
}
func NewQuality() *Quality {
z := &Quality{
value: aws.String(""),
field: huh.NewInput().
Key("q").
Description("Quality of the image 0-100").
Title("Quality"),
}
z.field.Value(z.value)
return z
}
func (z *Quality) Value() string {
return *z.value
}
func (z *Quality) Display() string {
return "quality"
}
func (z *Quality) Key() string {
return "q"
}
func (z *Quality) Input() []huh.Field {
return []huh.Field{z.field}
}

View File

@@ -2,35 +2,45 @@ package interactive
import (
"fmt"
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/lipgloss"
)
func (m Model) View() string {
output := lipgloss.NewStyle().
Foreground(lipgloss.Color("5")).
Background(lipgloss.Color("0")).
Bold(true).
Underline(true).
Render("Welcome to the img-proxy URL Generator!") + "\n\n"
fieldStyle := lipgloss.NewStyle().PaddingBottom(1)
if m.err != nil {
return output + "Error: " + m.err.Error() + "\n" + "Press Ctrl+C to exit.\n"
return lipgloss.
NewStyle().
Bold(true).
Foreground(lipgloss.Color("red")).
Background(lipgloss.Color("black")).
Render("Error: " + m.err.Error() + "\n" + "Press Ctrl+C to exit.")
}
output := lipgloss.NewStyle().
Foreground(lipgloss.Color("5")).
PaddingBottom(1).
Bold(true).
Underline(true).
Render("Welcome to the img-proxy URL Generator!") + "\n"
for _, field := range m.Fields {
output += field.View() + "\n\n"
output += fieldStyle.Render("\n" + field.View())
}
for _, field := range *m.selectedParams {
for _, f := range field.Input() {
output += f.View() + "\n\n"
output += fieldStyle.Render("\n" + f.View())
}
}
if *m.url == "" {
return output + help()
return output + "\n" + m.renderHelp()
}
// Generate the URL
params := make([]string, 0)
for _, field := range *m.selectedParams {
if field.Value() != "" {
@@ -45,15 +55,17 @@ func (m Model) View() string {
Foreground(lipgloss.Color("#0000ff")).
Render(url))
output += help()
output += m.renderHelp()
return output
}
func help() string {
return lipgloss.
NewStyle().
Inline(true).
Foreground(lipgloss.Color("#123456")).
Render("Ctrl+C | Esc: exit * Tab: Next Field * Sft+Tab: Prev Field * Space: Select\n")
func (m Model) renderHelp() string {
return m.help.ShortHelpView([]key.Binding{
key.NewBinding(key.WithKeys("ctrl+c", "esc"), key.WithHelp("esc", "quit")),
key.NewBinding(key.WithKeys("up"), key.WithHelp("↑", "cursor up")),
key.NewBinding(key.WithKeys("down"), key.WithHelp("↓", "cursor down")),
key.NewBinding(key.WithKeys(" "), key.WithHelp("space", "select")),
key.NewBinding(key.WithKeys("tab"), key.WithHelp("tab", "next field")),
})
}