Skip to content

Commit

Permalink
Pass stdout option
Browse files Browse the repository at this point in the history
  • Loading branch information
TomWright committed Oct 29, 2024
1 parent de29bd2 commit f6f2be3
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions internal/cli/interactive.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,14 @@ func (c *InteractiveCmd) Run(ctx *Globals) error {

m := initialModel(c, c.Query, stdInBytes)

p := tea.NewProgram(m)
p := tea.NewProgram(m, tea.WithOutput(ctx.Stdout))

_, err = p.Run()
return err
if err != nil {
return err
}

return nil
}

func initialModel(it *InteractiveCmd, defaultCommand string, stdInBytes []byte) interactiveTeaModel {
Expand Down Expand Up @@ -124,6 +128,9 @@ func (m interactiveTeaModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.previousCommand = m.currentCommand

m.currentCommand = m.commandInput.Value()
if m.firstUpdate {
cmds = append(cmds, tea.EnterAltScreen)
}
if m.firstUpdate || m.currentCommand != m.previousCommand {
m.firstUpdate = false
// If the command has changed, we need to execute it
Expand Down Expand Up @@ -160,12 +167,7 @@ func (m interactiveTeaModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.Type {
case tea.KeyEsc:
return m, tea.Quit
//if m.commandInput.Focused() {
// m.commandInput.Blur()
//}
case tea.KeyCtrlC:
case tea.KeyEsc, tea.KeyCtrlC:
return m, tea.Quit
default:
if !m.commandInput.Focused() {
Expand All @@ -180,7 +182,7 @@ func (m interactiveTeaModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
resultHeaderHeight := lipgloss.Height(m.resultHeaderView())
verticalMarginHeight := headerHeight + 2 + commandInputHeight + resultHeaderHeight

viewportHeight := msg.Height - verticalMarginHeight
viewportHeight := msg.Height - verticalMarginHeight - 2
viewportWidth := (msg.Width / 2) - 4

if !m.outputReady {
Expand Down

0 comments on commit f6f2be3

Please sign in to comment.