From 7bff34f4089cd6f7edc40470d212aafa116262df Mon Sep 17 00:00:00 2001 From: Alisson Santos Date: Mon, 2 Nov 2020 10:56:23 +0100 Subject: [PATCH 1/2] Use terminal width for the status line --- pkg/cmd/repo/garden/garden.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/cmd/repo/garden/garden.go b/pkg/cmd/repo/garden/garden.go index 8ab347594..d3b65e1c4 100644 --- a/pkg/cmd/repo/garden/garden.go +++ b/pkg/cmd/repo/garden/garden.go @@ -303,7 +303,7 @@ func gardenRun(opts *GardenOptions) error { } // status line stuff - sl := statusLine(garden, player) + sl := statusLine(garden, player, opts.IO) fmt.Fprint(out, "\033[;H") // move to top left for y := 0; y < player.Geo.Height-1; y++ { @@ -450,14 +450,18 @@ func drawGarden(out io.Writer, garden [][]*Cell, player *Player) { fmt.Fprintln(out, utils.Bold(sl)) } -func statusLine(garden [][]*Cell, player *Player) string { - statusLine := garden[player.Y][player.X].StatusLine + " " +func statusLine(garden [][]*Cell, player *Player, io *iostreams.IOStreams) string { + statusLine := garden[player.Y][player.X].StatusLine + if player.ShoeMoistureContent > 1 { statusLine += "\nYour shoes squish with water from the stream." } else if player.ShoeMoistureContent == 1 { statusLine += "\nYour shoes seem to have dried out." - } else { - statusLine += "\n " + } + + if len(statusLine) < io.TerminalWidth() { + paddingSize := io.TerminalWidth() - len(statusLine) + statusLine += strings.Repeat(" ", paddingSize) } return statusLine From 699a6c68fe6a6d67d6a321789bff626b168cf5c0 Mon Sep 17 00:00:00 2001 From: Alisson Santos Date: Mon, 2 Nov 2020 13:21:46 +0100 Subject: [PATCH 2/2] Use slice and make both status lines the size of the terminal width. --- pkg/cmd/repo/garden/garden.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pkg/cmd/repo/garden/garden.go b/pkg/cmd/repo/garden/garden.go index d3b65e1c4..8ae1d0a9c 100644 --- a/pkg/cmd/repo/garden/garden.go +++ b/pkg/cmd/repo/garden/garden.go @@ -451,20 +451,25 @@ func drawGarden(out io.Writer, garden [][]*Cell, player *Player) { } func statusLine(garden [][]*Cell, player *Player, io *iostreams.IOStreams) string { - statusLine := garden[player.Y][player.X].StatusLine + width := io.TerminalWidth() + statusLines := []string{garden[player.Y][player.X].StatusLine} if player.ShoeMoistureContent > 1 { - statusLine += "\nYour shoes squish with water from the stream." + statusLines = append(statusLines, "Your shoes squish with water from the stream.") } else if player.ShoeMoistureContent == 1 { - statusLine += "\nYour shoes seem to have dried out." + statusLines = append(statusLines, "Your shoes seem to have dried out.") + } else { + statusLines = append(statusLines, "") } - if len(statusLine) < io.TerminalWidth() { - paddingSize := io.TerminalWidth() - len(statusLine) - statusLine += strings.Repeat(" ", paddingSize) + for i, line := range statusLines { + if len(line) < width { + paddingSize := width - len(line) + statusLines[i] = line + strings.Repeat(" ", paddingSize) + } } - return statusLine + return strings.Join(statusLines, "\n") } func shaToColorFunc(sha string) func(string) string {