From 7cb02d77aee2f195163193b3a87d6cde2f98106d Mon Sep 17 00:00:00 2001 From: kota kanbe Date: Thu, 26 May 2016 09:00:52 +0900 Subject: [PATCH] Fix freezing forever when no args specified in TUI mode --- commands/tui.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/commands/tui.go b/commands/tui.go index e8b9a112..fe30c063 100644 --- a/commands/tui.go +++ b/commands/tui.go @@ -80,14 +80,17 @@ func (p *TuiCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) s } historyID = f.Args()[0] } else { - bytes, err := ioutil.ReadAll(os.Stdin) - if err != nil { - log.Errorf("Failed to read stdin: %s", err) - return subcommands.ExitFailure - } - fields := strings.Fields(string(bytes)) - if 0 < len(fields) { - historyID = fields[0] + stat, _ := os.Stdin.Stat() + if (stat.Mode() & os.ModeCharDevice) == 0 { + bytes, err := ioutil.ReadAll(os.Stdin) + if err != nil { + log.Errorf("Failed to read stdin: %s", err) + return subcommands.ExitFailure + } + fields := strings.Fields(string(bytes)) + if 0 < len(fields) { + historyID = fields[0] + } } } return report.RunTui(historyID)