Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#53:fix the bug /dev/ptmx is not available in docker #55

Merged
merged 1 commit into from
Jan 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions cmd/shared/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package shared
import (
"bufio"
"fmt"
"github.com/fatih/color" //nolint
"os"
"os/exec"
"regexp"
Expand All @@ -12,12 +13,18 @@ import (

func StreamCmdOutput(cmd *exec.Cmd, file string) error {
// Start the command with a pty
ptmx, err := pty.Start(cmd)
if err != nil {
fmt.Println("Error starting command:", err)
return err
var scanner *bufio.Scanner
if ptmx, err := pty.Start(cmd); err == nil {
scanner = bufio.NewScanner(ptmx)
defer ptmx.Close()
} else {
color.Yellow("device not support tty will fall back plain model")
if rd, err := cmd.StdoutPipe(); err == nil {
scanner = bufio.NewScanner(rd)
} else {
return err
}
}
defer ptmx.Close()

// Create a file to save the output
log, err := os.Create(file)
Expand All @@ -31,7 +38,6 @@ func StreamCmdOutput(cmd *exec.Cmd, file string) error {
colorRegex := regexp.MustCompile(`\x1b\[[0-9;]*m`)
// Goroutine to remove color escape sequences, print the colored output, and write the modified output to the file
go func() {
scanner := bufio.NewScanner(ptmx)
for scanner.Scan() {
line := scanner.Text()

Expand Down