Skip to content

Commit d2f2a52

Browse files
authored
fix: disable markdown viewer when rendering as non-interactive (#285)
1 parent d2d457c commit d2f2a52

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

cmd/internal/helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func TUIEnabled(ctx *context.Context, cmd *cobra.Command) bool {
6161
format := flags.ValueFor[string](cmd, *flags.OutputFormatFlag, false)
6262
formatDisabled = format == "yaml" || format == "yml" || format == "json"
6363
}
64-
envDisabled, _ := strconv.ParseBool(os.Getenv("DISABLE_FLOW_INTERACTIVE"))
64+
envDisabled, _ := strconv.ParseBool(os.Getenv(flowIO.DisableInteractiveEnvKey))
6565
return !formatDisabled && !envDisabled && ctx.Config.ShowTUI()
6666
}
6767

internal/io/io.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package io
22

33
import "os"
44

5+
const DisableInteractiveEnvKey = "DISABLE_FLOW_INTERACTIVE"
6+
57
var (
68
Stdout = os.Stdout
7-
Stderr = os.Stderr
89
Stdin = os.Stdin
910
)

internal/runner/render/render.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"gopkg.in/yaml.v3"
1616

1717
"github.com/flowexec/flow/internal/context"
18+
"github.com/flowexec/flow/internal/io"
1819
"github.com/flowexec/flow/internal/logger"
1920
"github.com/flowexec/flow/internal/runner"
2021
"github.com/flowexec/flow/internal/runner/engine"
@@ -107,7 +108,13 @@ func (r *renderRunner) Exec(
107108
}
108109

109110
logger.Log().Infof("Rendering content from file %s", contentFile)
110-
filename := filepath.Base(contentFile)
111+
112+
if os.Getenv(io.DisableInteractiveEnvKey) != "" {
113+
logger.Log().Print("### Rendered Content Start ###")
114+
logger.Log().Print(buff.String())
115+
logger.Log().Print("### Rendered Content End ###")
116+
return nil
117+
}
111118

112119
if err := ctx.TUIContainer.Start(); err != nil {
113120
return errors.Wrapf(err, "unable to open viewer")
@@ -116,6 +123,7 @@ func (r *renderRunner) Exec(
116123
ctx.TUIContainer.WaitForExit()
117124
}()
118125

126+
filename := filepath.Base(contentFile)
119127
ctx.TUIContainer.SetState("file", filename)
120128
return ctx.TUIContainer.SetView(views.NewMarkdownView(ctx.TUIContainer.RenderState(), buff.String()))
121129
}

internal/utils/env/env.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/flowexec/flow/internal/context"
1111
"github.com/flowexec/flow/internal/filesystem"
12+
"github.com/flowexec/flow/internal/io"
1213
"github.com/flowexec/flow/internal/utils"
1314
"github.com/flowexec/flow/types/executable"
1415
)
@@ -206,9 +207,9 @@ func DefaultEnv(ctx *context.Context, executable *executable.Executable) map[str
206207
envMap["FLOW_WORKSPACE_PATH"] = executable.WorkspacePath()
207208
envMap["FLOW_CONFIG_PATH"] = filesystem.ConfigDirPath()
208209
envMap["FLOW_CACHE_PATH"] = filesystem.CachedDataDirPath()
209-
envMap["DISABLE_FLOW_INTERACTIVE"] = "true"
210-
if interactive := os.Getenv("DISABLE_FLOW_INTERACTIVE"); interactive != "" {
211-
envMap["DISABLE_FLOW_INTERACTIVE"] = interactive
210+
envMap[io.DisableInteractiveEnvKey] = "true"
211+
if interactive := os.Getenv(io.DisableInteractiveEnvKey); interactive != "" {
212+
envMap[io.DisableInteractiveEnvKey] = interactive
212213
}
213214
return envMap
214215
}

internal/utils/env/env_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"go.uber.org/mock/gomock"
1212

1313
"github.com/flowexec/flow/internal/context"
14+
"github.com/flowexec/flow/internal/io"
1415
"github.com/flowexec/flow/internal/logger"
1516
"github.com/flowexec/flow/internal/utils/env"
1617
"github.com/flowexec/flow/types/config"
@@ -300,7 +301,7 @@ var _ = Describe("Env", func() {
300301
Expect(envMap["FLOW_CURRENT_WORKSPACE"]).To(Equal(wsName))
301302
Expect(envMap["FLOW_CURRENT_NAMESPACE"]).To(Equal(nsName))
302303
Expect(envMap["FLOW_EXECUTABLE_NAME"]).To(Equal(execName))
303-
Expect(envMap["DISABLE_FLOW_INTERACTIVE"]).To(Equal("true"))
304+
Expect(envMap[io.DisableInteractiveEnvKey]).To(Equal("true"))
304305
// TODO: Add more assertions for other keys in the environment map
305306
})
306307
})

0 commit comments

Comments
 (0)