works now
This commit is contained in:
@@ -20,7 +20,9 @@ type QuestionnaireModel struct {
|
||||
|
||||
func NewQuestionnaireModel(questions Questions, keys []string) *QuestionnaireModel {
|
||||
form := huh.NewForm(questions...).
|
||||
WithTheme(style.HuhCenterTheme()).WithLayout(huh.LayoutGrid(1, 1))
|
||||
WithTheme(style.HuhCenterTheme()).
|
||||
WithLayout(huh.LayoutGrid(1, 1)).
|
||||
WithWidth(80)
|
||||
|
||||
return &QuestionnaireModel{
|
||||
Questions: questions,
|
||||
@@ -37,7 +39,9 @@ func (q *QuestionnaireModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
case tea.WindowSizeMsg:
|
||||
q.SetSize(msg.Width, msg.Height)
|
||||
case tea.KeyMsg:
|
||||
// Update form width to match window
|
||||
q.form.WithWidth(msg.Width)
|
||||
case tea.KeyPressMsg:
|
||||
switch msg.String() {
|
||||
case "q", "ctrl+c":
|
||||
q.userQuit = true
|
||||
@@ -57,14 +61,18 @@ func (q *QuestionnaireModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return q, cmd
|
||||
}
|
||||
|
||||
func (q *QuestionnaireModel) View() string {
|
||||
func (q *QuestionnaireModel) View() tea.View {
|
||||
form := lipgloss.NewStyle().
|
||||
Width(q.width).Align(lipgloss.Center).
|
||||
Render(q.form.View())
|
||||
|
||||
return lipgloss.Place(
|
||||
content := lipgloss.Place(
|
||||
q.width, q.height, lipgloss.Center, lipgloss.Center, form,
|
||||
)
|
||||
|
||||
v := tea.NewView(content)
|
||||
v.AltScreen = true
|
||||
return v
|
||||
}
|
||||
|
||||
func (q *QuestionnaireModel) SetSize(width, height int) {
|
||||
|
||||
@@ -157,7 +157,7 @@ func (r *RunLifecycle) Finish(ctx context.Context, runErr error) error {
|
||||
}
|
||||
|
||||
func runIntro(details models.TaskDetails) error {
|
||||
model, err := tea.NewProgram(NewTaskModel(details), tea.WithAltScreen()).Run()
|
||||
model, err := tea.NewProgram(NewTaskModel(details)).Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -179,7 +179,7 @@ func runQuestionnaire(t Tasker, iType InterfaceType, collector *taskRunCollector
|
||||
keys = provider.QuestionnaireKeys(iType)
|
||||
}
|
||||
|
||||
model, err := tea.NewProgram(NewQuestionnaireModel(questions, keys), tea.WithAltScreen()).Run()
|
||||
model, err := tea.NewProgram(NewQuestionnaireModel(questions, keys)).Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func (m TaskModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
case tea.WindowSizeMsg:
|
||||
m.SetSize(msg.Width, msg.Height)
|
||||
case tea.KeyMsg:
|
||||
case tea.KeyPressMsg:
|
||||
switch {
|
||||
case key.Matches(msg, m.keys.Quit):
|
||||
m.userQuit = true
|
||||
@@ -73,10 +73,13 @@ func (m TaskModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m TaskModel) View() string {
|
||||
func (m TaskModel) View() tea.View {
|
||||
if m.width < 55 || m.height < 16 {
|
||||
return lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center,
|
||||
content := lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center,
|
||||
style.TextStyle.Render("Terminal too small."))
|
||||
v := tea.NewView(content)
|
||||
v.AltScreen = true
|
||||
return v
|
||||
}
|
||||
|
||||
boxWidth := min(m.width-10, 120)
|
||||
@@ -111,7 +114,9 @@ func (m TaskModel) View() string {
|
||||
|
||||
final := lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center, b.String())
|
||||
|
||||
return final
|
||||
v := tea.NewView(final)
|
||||
v.AltScreen = true
|
||||
return v
|
||||
}
|
||||
|
||||
func (m *TaskModel) SetSize(width, height int) {
|
||||
|
||||
Reference in New Issue
Block a user