Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f0b987ec authored by Colin Cross's avatar Colin Cross
Browse files

status table: don't write newlines in non-scrolling terminals

Multiple terminals have had issues with writing newlines into the
non-scrolling region, just set the cursor to the beginning of the
next line instead.

Test: m nothing in JediTerm
Change-Id: I2e434f4cc263ca13b82889a79d6a8bb48d084cb3
parent bf8f57e2
Loading
Loading
Loading
Loading
+21 −29
Original line number Diff line number Diff line
@@ -334,17 +334,19 @@ func (s *smartStatusOutput) actionTable() {
	scrollingHeight := s.termHeight - s.tableHeight

	// Update the scrolling region in case the height of the terminal changed

	fmt.Fprint(s.writer, ansi.setScrollingMargins(1, scrollingHeight))
	// Move the cursor to the first line of the non-scrolling region
	fmt.Fprint(s.writer, ansi.setCursor(scrollingHeight+1, 1))

	// Write as many status lines as fit in the table
	var tableLine int
	var runningAction actionTableEntry
	for tableLine, runningAction = range s.runningActions {
	for tableLine := 0; tableLine < s.tableHeight; tableLine++ {
		if tableLine >= s.tableHeight {
			break
		}
		// Move the cursor to the correct line of the non-scrolling region
		fmt.Fprint(s.writer, ansi.setCursor(scrollingHeight+1+tableLine, 1))

		if tableLine < len(s.runningActions) {
			runningAction := s.runningActions[tableLine]

			seconds := int(time.Since(runningAction.startTime).Round(time.Second).Seconds())

@@ -363,19 +365,9 @@ func (s *smartStatusOutput) actionTable() {
			durationStr := fmt.Sprintf("   %2d:%02d ", seconds/60, seconds%60)
			desc = elide(desc, s.termWidth-len(durationStr))
			durationStr = color + durationStr + ansi.regular()

		fmt.Fprint(s.writer, durationStr, desc, ansi.clearToEndOfLine())
		if tableLine < s.tableHeight-1 {
			fmt.Fprint(s.writer, "\n")
			fmt.Fprint(s.writer, durationStr, desc)
		}
	}

	// Clear any remaining lines in the table
	for ; tableLine < s.tableHeight; tableLine++ {
		fmt.Fprint(s.writer, ansi.clearToEndOfLine())
		if tableLine < s.tableHeight-1 {
			fmt.Fprint(s.writer, "\n")
		}
	}

	// Move the cursor back to the last line of the scrolling region