Skip to content

Commit

Permalink
display: better wording; fix fake issue #227 (#228)
Browse files Browse the repository at this point in the history
Signed-off-by: Liu Cong <[email protected]>
  • Loading branch information
innerr authored Sep 20, 2022
1 parent 9039595 commit 2a78e19
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 18 deletions.
8 changes: 4 additions & 4 deletions pkg/builtin/bg_tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func WaitForBgTaskFinish(
return WaitForAllBgTasksFinish(argv, cc, env, flow, currCmdIdx)
}

errs := WaitBgTasks(cc, env, tid)
errs := WaitBgTasks(cc, env, tid, true)
for _, err := range errs {
display.PrintError(cc, env, err)
}
Expand All @@ -45,14 +45,14 @@ func WaitForAllBgTasksFinish(
panic(core.NewCmdError(flow.Cmds[currCmdIdx],
"must be in main thread to wait for other threads to finish"))
}
errs := WaitBgTasks(cc, env, "")
errs := WaitBgTasks(cc, env, "", true)
for _, err := range errs {
display.PrintError(cc, env, err)
}
return currCmdIdx, true
}

func WaitBgTasks(cc *core.Cli, env *core.Env, matchTid string) (errs []error) {
func WaitBgTasks(cc *core.Cli, env *core.Env, matchTid string, manual bool) (errs []error) {
preTid := utils.GoRoutineIdStr()
for {
tid, task, ok := cc.BgTasks.GetEarliestTask()
Expand All @@ -64,7 +64,7 @@ func WaitBgTasks(cc *core.Cli, env *core.Env, matchTid string) (errs []error) {
}
info := task.GetStat()

display.PrintSwitchingThreadDisplay(preTid, info, env, cc.Screen)
display.PrintSwitchingThreadDisplay(preTid, info, env, cc.Screen, manual)

cc.BgTasks.BringBgTaskToFront(tid, cc.CmdIO.CmdStdout)
err := task.WaitForFinish()
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/core/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func SaveEnvToFile(env *Env, path string, sep string, skipDefault bool) {
"sys.breakpoint",
"sys.execute-wait-sec",
"sys.event.",
"sys.paths.",
}
saveEnvToFile(env, path, sep, filtered, skipDefault)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/cli/display/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func PrintCmdStack(
} else {
if i == currCmdIdx {
if sysArgv.IsDelay() && !inBg {
line += ColorCmdCurr(">> "+name+" (schedule in ", env) + sysArgv.GetDelayStr() + ColorCmdCurr(")", env)
line += ColorCmdCurr(">> "+name+" (schedule to bg in ", env) + sysArgv.GetDelayStr() + ColorCmdCurr(")", env)
lineExtraLen += ColorExtraLen(env, "cmd-curr", "cmd-curr")
} else {
line += ColorCmdCurr(">> "+name, env)
Expand All @@ -231,15 +231,15 @@ func PrintCmdStack(
}
} else if i < currCmdIdx {
if sysArgv.IsDelay() && !inBg {
line += " " + ColorCmdDelay(name+" (scheduled in ", env) + sysArgv.GetDelayStr() + ColorCmdDelay(")", env)
line += " " + ColorCmdDelay(name+" (scheduled to bg in ", env) + sysArgv.GetDelayStr() + ColorCmdDelay(")", env)
lineExtraLen += ColorExtraLen(env, "cmd-delay", "cmd-delay")
} else {
line += " " + ColorCmdDone(name, env)
lineExtraLen += ColorExtraLen(env, "cmd-done")
}
} else {
if sysArgv.IsDelay() && !inBg {
line += " " + name + " (schedule in " + sysArgv.GetDelayStr() + ")"
line += " " + name + " (schedule to bg in " + sysArgv.GetDelayStr() + ")"
} else {
line += " " + name
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/display/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ func dumpCmdDisplayName(
//if sysArgv.GetDelayDuration().Nanoseconds() == 0 {
// name += ColorCmdDelay(" (background)", env)
//} else {
name += ColorCmdDelay(" (schedule in ", env) + sysArgv.GetDelayStr() + ColorCmdDelay(")", env)
name += ColorCmdDelay(" (schedule to bg in ", env) + sysArgv.GetDelayStr() + ColorCmdDelay(")", env)
//}
}

Expand Down
14 changes: 10 additions & 4 deletions pkg/cli/display/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,20 @@ func RenderCmdResult(l CmdResultLines, env *core.Env, screen core.Screen, width
}
}

func PrintSwitchingThreadDisplay(preTid string, info core.BgTaskInfo, env *core.Env, screen core.Screen) {
func PrintSwitchingThreadDisplay(preTid string, info core.BgTaskInfo, env *core.Env, screen core.Screen, manual bool) {
var title string
var extraLen int

if preTid == utils.GoRoutineIdStrMain {
title = ColorThread("thread ", env) + preTid +
ColorThread(" ended, switch display to thread ", env) + info.Tid +
ColorThread(", command ", env) + ColorCmdDelay("["+info.Cmd+"]", env)
if manual {
title = ColorThread("in thread ", env) + preTid +
ColorThread(" do manual wait, switch display to thread ", env) + info.Tid +
ColorThread(", command ", env) + ColorCmdDelay("["+info.Cmd+"]", env)
} else {
title = ColorThread("thread ", env) + preTid +
ColorThread(" ended, switch display to thread ", env) + info.Tid +
ColorThread(", command ", env) + ColorCmdDelay("["+info.Cmd+"]", env)
}
extraLen = ColorExtraLen(env, "thread", "thread", "thread", "cmd-delay")
} else {
title = ColorThread("switch display to thread ", env) + info.Tid +
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/execute/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (self *Executor) Run(cc *core.Cli, env *core.Env, bootstrap string, input .

var errs []error
if env.GetBool("sys.bg.wait") {
errs = builtin.WaitBgTasks(cc, env, "")
errs = builtin.WaitBgTasks(cc, env, "", false)
for _, err := range errs {
display.PrintError(cc, env, err)
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/cli/parser/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ type Parser struct {
// UPDATE: rewite this with goyacc
//
// A very simple implement of command line parsing, lack of char escaping
// * The command line argv list have extra tokenizing info
// - An example: a quoted string with space inside
// - TODO: how to store this info(to flow file?) and still keep it human-editable ?
// * The dynamite info(registered modules and env KVs) could use for disambiguation
// - Inconvenient to use a LEX/YACC lib to parse
// - The command line argv list have extra tokenizing info
// - An example: a quoted string with space inside
// - TODO: how to store this info(to flow file?) and still keep it human-editable ?
// - The dynamite info(registered modules and env KVs) could use for disambiguation
// - Inconvenient to use a LEX/YACC lib to parse
func (self *Parser) Parse(
cmds *core.CmdTree,
envAbbrs *core.EnvAbbrs,
Expand Down

0 comments on commit 2a78e19

Please sign in to comment.