opentofu/internal/command/console_interactive.go
Christian Mesh 0abfd52e3e Terrible hacks to get some sort of wasm working
cp "$(go env GOROOT)/lib/wasm/wasm_exec.js" .
GOOS=js GOARCH=wasm go build -ldflags="-X 'main.experimentsAllowed=yes'" -o main.wasm ./cmd/tofu/

Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2026-04-30 14:57:01 -04:00

76 lines
1.8 KiB
Go

// Copyright (c) The OpenTofu Authors
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) 2023 HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package command
import (
"github.com/opentofu/opentofu/internal/command/views"
"github.com/opentofu/opentofu/internal/repl"
)
func (c *ConsoleCommand) modeInteractive(session *repl.Session, view views.Console) int {
// Configure input
/*l, err := readline.NewEx(&readline.Config{
Prompt: "> ",
InterruptPrompt: "^C",
EOFPrompt: "exit",
HistorySearchFold: true,
Stdin: os.Stdin,
Stdout: os.Stdout,
Stderr: os.Stderr,
})
if err != nil {
view.Diagnostics(tfdiags.Diagnostics{}.Append(tfdiags.Sourceless(
tfdiags.Error,
"Plugins loading error",
fmt.Sprintf("Error initializing console: %s", err),
)))
return 1
}
defer l.Close()
var consoleState consoleBracketState
for {
// Read a line
line, err := l.Readline()
if errors.Is(err, readline.ErrInterrupt) {
if len(line) == 0 {
break
} else {
continue
}
} else if errors.Is(err, io.EOF) {
break
}
line = strings.TrimSpace(line)
// we update the state with the new line, so if we have open
// brackets we know not to execute the command just yet
fullCommand, openState := consoleState.UpdateState(line)
if openState > 0 {
// here there are open brackets somewhere, so we don't execute it
// as we are in a bracket we update the prompt. we use one . per layer pf brackets
l.SetPrompt(fmt.Sprintf("%s ", strings.Repeat(".", openState)))
} else {
out, exit, diags := session.Handle(fullCommand)
if diags.HasErrors() {
view.Diagnostics(diags)
}
if exit {
break
}
// clear the state and buffer as we have executed a command
// we also reset the prompt
l.SetPrompt("> ")
view.Output(out)
}
}*/
return 0
}