diff --git a/runny/model.go b/runny/model.go index e31e837..ab40c44 100644 --- a/runny/model.go +++ b/runny/model.go @@ -66,10 +66,20 @@ func (c *Config) PrintCommands() { slices.Sort(names) var separator = " " - maxLineLength := 80 - if !term.IsTerminal(int(os.Stdout.Fd())) { + var maxLineLength int + + if term.IsTerminal(int(os.Stdout.Fd())) { + if c.verbose { + maxLineLength = 0 + } else { + width, _, err := term.GetSize(int(os.Stdin.Fd())) + if err == nil { + maxLineLength = width + } + } + } else { separator = "\t" - maxLineLength = 40 + maxLineLength = 0 } for _, name := range names { diff --git a/runny/utils.go b/runny/utils.go index 965fee1..744cf75 100644 --- a/runny/utils.go +++ b/runny/utils.go @@ -16,7 +16,7 @@ func commandStringToSingleLine(command string, maxlength int) string { trimmedLines = append(trimmedLines, strings.TrimSpace(line)) } result := strings.Join(trimmedLines, "; ") - if len(result) > maxlength { + if maxlength > 0 && len(result) > maxlength { result = result[:maxlength-1] + "…" } return result diff --git a/runny/utils_test.go b/runny/utils_test.go index 2903c7d..d75219a 100644 --- a/runny/utils_test.go +++ b/runny/utils_test.go @@ -21,6 +21,7 @@ func TestCommandStringToSingleLine(t *testing.T) { {input: Input{command: "foo bar wibble", maxLength: 10}, expected: "foo bar w…"}, {input: Input{command: "foo\nbar", maxLength: 80}, expected: "foo; bar"}, {input: Input{command: " foo \n bar ", maxLength: 80}, expected: "foo; bar"}, + {input: Input{command: "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam convallis. Nunc lacus. Curabitur nunc mauris, commodo vel, eleifend in, ornare sit amet, felis. Nullam mi neque, feugiat et, porttitor vitae, pharetra non, lacus. Fusce imperdiet sem quis dui.", maxLength: 0}, expected: "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam convallis. Nunc lacus. Curabitur nunc mauris, commodo vel, eleifend in, ornare sit amet, felis. Nullam mi neque, feugiat et, porttitor vitae, pharetra non, lacus. Fusce imperdiet sem quis dui."}, } for _, p := range params { output := commandStringToSingleLine(p.input.command, p.input.maxLength)