11package runner
22
33import (
4- "bytes"
54 "context"
65 "fmt"
76 "io"
@@ -11,8 +10,8 @@ import (
1110 "strings"
1211 "sync"
1312
14- "github.com/alecthomas/chroma/v2/quick"
15- "github.com/charmbracelet/lipgloss"
13+ // "github.com/alecthomas/chroma/v2/quick"
14+ // "github.com/charmbracelet/lipgloss"
1615 "github.com/muesli/termenv"
1716 "github.com/nxtcoder17/fwatcher/pkg/executor"
1817 "github.com/nxtcoder17/fwatcher/pkg/watcher"
@@ -54,35 +53,35 @@ func isTTY() bool {
5453 return ((stdout .Mode () & os .ModeCharDevice ) == os .ModeCharDevice ) && ((stderr .Mode () & os .ModeCharDevice ) == os .ModeCharDevice )
5554}
5655
57- func printCommand (writer io.Writer , prefix , lang , cmd string ) {
58- if isTTY () {
59- borderColor := "#4388cc"
60- if ! isDarkTheme () {
61- borderColor = "#3d5485"
62- }
63- s := lipgloss .NewStyle ().BorderForeground (lipgloss .Color (borderColor )).PaddingLeft (1 ).PaddingRight (1 ).Border (lipgloss .RoundedBorder (), true , true , true , true )
64- // labelStyle := lipgloss.NewStyle().Foreground(lipgloss.Color(borderColor)).Blink(true)
65-
66- hlCode := new (bytes.Buffer )
67- // choose colorschemes from `https://swapoff.org/chroma/playground/`
68- colorscheme := "catppuccin-macchiato"
69- if ! isDarkTheme () {
70- colorscheme = "monokailight"
71- }
72- _ = colorscheme
73- // quick.Highlight(hlCode, strings.TrimSpace(command.Command), "bash", "terminal16m", colorscheme)
74-
75- cmdStr := strings .TrimSpace (cmd )
76-
77- quick .Highlight (hlCode , cmdStr , lang , "terminal16m" , colorscheme )
78- // cst := styles.Get("gruvbox")
79- // fmt.Println("cst: ", cst.Name, styles.Fallback.Name, styles.Names())
80-
81- // fmt.Printf("%s\n", s.Render(args.taskName+" | "+hlCode.String()))
82- fmt .Fprintf (writer , "%s\n " , s .Render (padString (hlCode .String (), prefix )))
83- }
56+ func hasANSISupport () bool {
57+ term := os .Getenv ("TERM" )
58+ return strings .Contains (term , "xterm" ) || strings .Contains (term , "screen" ) || strings .Contains (term , "vt100" )
8459}
8560
61+ // func printCommand(writer io.Writer, prefix, lang, cmd string) {
62+ // if isTTY() {
63+ // borderColor := "#4388cc"
64+ // if !isDarkTheme() {
65+ // borderColor = "#3d5485"
66+ // }
67+ // s := lipgloss.NewStyle().BorderForeground(lipgloss.Color(borderColor)).PaddingLeft(1).PaddingRight(1).Border(lipgloss.RoundedBorder(), true, true, true, true)
68+ //
69+ // hlCode := new(bytes.Buffer)
70+ // // choose colorschemes from `https://swapoff.org/chroma/playground/`
71+ // colorscheme := "catppuccin-macchiato"
72+ // if !isDarkTheme() {
73+ // colorscheme = "monokailight"
74+ // }
75+ // _ = colorscheme
76+ //
77+ // cmdStr := strings.TrimSpace(cmd)
78+ //
79+ // quick.Highlight(hlCode, cmdStr, lang, "terminal16m", colorscheme)
80+ //
81+ // fmt.Fprintf(writer, "\r%s%s\n", s.Render(padString(hlCode.String(), prefix)), s.UnsetBorderStyle())
82+ // }
83+ // }
84+
8685type CreateCommandGroupArgs struct {
8786 Runfile * types.ParsedRunfile
8887 Task * types.ParsedTask
@@ -141,16 +140,24 @@ func createCommandGroups(ctx Context, args CreateCommandGroupArgs) ([]executor.C
141140 }
142141 }
143142
144- printCommand (args .Stdout .WithPrefix ("" ), strings .Join (args .Trail , "/" ), "bash" , strings .Join (commandsList , "\n " ))
145-
146143 return CreateCommand (ctx , CmdArgs {
147144 Shell : args .Task .Shell ,
148145 Env : fn .ToEnviron (args .Task .Env ),
149146 Cmd : * cmd .Command ,
150147 WorkingDir : args .Task .WorkingDir ,
151148 interactive : args .Task .Interactive ,
152- Stdout : args .Stdout .WithPrefix (strings .Join (args .Trail , "/" )),
153- Stderr : args .Stderr .WithPrefix (strings .Join (args .Trail , "/" )),
149+ Stdout : func () io.Writer {
150+ if args .Task .Interactive {
151+ return os .Stdout
152+ }
153+ return args .Stdout .WithPrefix (args .Task .Name )
154+ }(),
155+ Stderr : func () io.Writer {
156+ if args .Task .Interactive {
157+ return os .Stderr
158+ }
159+ return args .Stderr .WithPrefix (args .Task .Name )
160+ }(),
154161 })
155162 })
156163
0 commit comments