Files
runtime/apps/cli/views/common/prompt.go
zeekay ea80dc3638 feat: Add new Dockerfiles and improve containerization
- Add main Dockerfile for production builds
- Add Dockerfile.runtime for secure code execution
- Add Dockerfile.runtime.fixed with improved configuration
- Include .dockerignore for build optimization
- Add integration documentation and publishing guides
- Update API and CLI components for better runtime support
- Enhance sandbox and container management features
2025-08-16 23:03:39 -05:00

97 lines
1.8 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Copyright 2025 Hanzo Industries Inc.
// SPDX-License-Identifier: AGPL-3.0
package common
import (
"fmt"
"strings"
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
type promptModel struct {
textInput textinput.Model
err error
done bool
title string
desc string
}
func (m promptModel) Init() tea.Cmd {
return textinput.Blink
}
func (m promptModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.Type {
case tea.KeyEnter:
m.done = true
return m, tea.Quit
case tea.KeyCtrlC:
m.done = true
m.err = fmt.Errorf("user cancelled")
return m, tea.Quit
}
}
m.textInput, cmd = m.textInput.Update(msg)
return m, cmd
}
func (m promptModel) View() string {
if m.done {
return ""
}
titleStyle := lipgloss.NewStyle().
Bold(true).
MarginLeft(2).
MarginTop(1)
descStyle := lipgloss.NewStyle().
Foreground(lipgloss.Color("241")).
MarginLeft(2)
return fmt.Sprintf("\n%s\n%s\n\n %s\n\n",
titleStyle.Render(m.title),
descStyle.Render(m.desc),
m.textInput.View())
}
func PromptForInput(prompt, title, desc string) (string, error) {
ti := textinput.New()
ti.Focus()
ti.CharLimit = 156
ti.Width = 80
ti.Prompt = "› "
m := promptModel{
textInput: ti,
title: title,
desc: desc,
}
p := tea.NewProgram(m, tea.WithAltScreen())
model, err := p.Run()
if err != nil {
return "", fmt.Errorf("error running prompt: %w", err)
}
finalModel, ok := model.(promptModel)
if !ok {
return "", fmt.Errorf("could not read model state")
}
if finalModel.err != nil {
return "", finalModel.err
}
return strings.TrimSpace(finalModel.textInput.Value()), nil
}