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

Commit fac6fd09 authored by Colin Cross's avatar Colin Cross Committed by Gerrit Code Review
Browse files

Merge changes I0b78ceeb,Ic57e1efd

* changes:
  Add environment variable to force keeping ANSI codes
  Disable table mode in smart status if window size is not available
parents f05bea08 3c0fe0ed
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -218,10 +218,16 @@ func distDir(outDir string) string {
	}
}

func forceAnsiOutput() bool {
	value := os.Getenv("SOONG_UI_ANSI_OUTPUT")
	return value == "1" || value == "y" || value == "yes" || value == "on" || value == "true"
}

func main() {
	stdio := terminal.StdioImpl{}

	output := terminal.NewStatusOutput(stdio.Stdout(), "", false, false)
	output := terminal.NewStatusOutput(stdio.Stdout(), "", false, false,
		forceAnsiOutput())
	log := logger.New(output)
	defer log.Cleanup()

+2 −1
Original line number Diff line number Diff line
@@ -164,7 +164,8 @@ func main() {

	// Create a terminal output that mimics Ninja's.
	output := terminal.NewStatusOutput(c.stdio().Stdout(), os.Getenv("NINJA_STATUS"), c.simpleOutput,
		build.OsEnvironment().IsEnvTrue("ANDROID_QUIET_BUILD"))
		build.OsEnvironment().IsEnvTrue("ANDROID_QUIET_BUILD"),
		build.OsEnvironment().IsEnvTrue("SOONG_UI_ANSI_OUTPUT"))

	// Attach a new logger instance to the terminal output.
	log := logger.New(output)
+1 −1
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ type TestResults struct {

// Run runs a single build command.  It emulates the "m" command line by calling into Soong UI directly.
func (t *Test) Run(logsDir string) {
	output := terminal.NewStatusOutput(os.Stdout, "", false, false)
	output := terminal.NewStatusOutput(os.Stdout, "", false, false, false)

	log := logger.New(output)
	defer log.Cleanup()
+6 −2
Original line number Diff line number Diff line
@@ -24,15 +24,17 @@ import (
type simpleStatusOutput struct {
	writer    io.Writer
	formatter formatter
	keepANSI  bool
}

// NewSimpleStatusOutput returns a StatusOutput that represents the
// current build status similarly to Ninja's built-in terminal
// output.
func NewSimpleStatusOutput(w io.Writer, formatter formatter) status.StatusOutput {
func NewSimpleStatusOutput(w io.Writer, formatter formatter, keepANSI bool) status.StatusOutput {
	return &simpleStatusOutput{
		writer:    w,
		formatter: formatter,
		keepANSI:  keepANSI,
	}
}

@@ -54,7 +56,9 @@ func (s *simpleStatusOutput) FinishAction(result status.ActionResult, counts sta
	progress := s.formatter.progress(counts) + str

	output := s.formatter.result(result)
	if !s.keepANSI {
		output = string(stripAnsiEscapes([]byte(output)))
	}

	if output != "" {
		fmt.Fprint(s.writer, progress, "\n", output)
+33 −24
Original line number Diff line number Diff line
@@ -77,7 +77,12 @@ func NewSmartStatusOutput(w io.Writer, formatter formatter) status.StatusOutput
		s.requestedTableHeight = h
	}

	s.updateTermSize()
	if w, h, ok := termSize(s.writer); ok {
		s.termWidth, s.termHeight = w, h
		s.computeTableHeight()
	} else {
		s.tableMode = false
	}

	if s.tableMode {
		// Add empty lines at the bottom of the screen to scroll back the existing history
@@ -296,14 +301,8 @@ func (s *smartStatusOutput) stopSigwinch() {
	close(s.sigwinch)
}

func (s *smartStatusOutput) updateTermSize() {
	if w, h, ok := termSize(s.writer); ok {
		firstUpdate := s.termHeight == 0 && s.termWidth == 0
		oldScrollingHeight := s.termHeight - s.tableHeight

		s.termWidth, s.termHeight = w, h

		if s.tableMode {
// computeTableHeight recomputes s.tableHeight based on s.termHeight and s.requestedTableHeight.
func (s *smartStatusOutput) computeTableHeight() {
	tableHeight := s.requestedTableHeight
	if tableHeight == 0 {
		tableHeight = s.termHeight / 4
@@ -317,10 +316,21 @@ func (s *smartStatusOutput) updateTermSize() {
		tableHeight = s.termHeight - 1
	}
	s.tableHeight = tableHeight
}

// updateTermSize recomputes the table height after a SIGWINCH and pans any existing text if
// necessary.
func (s *smartStatusOutput) updateTermSize() {
	if w, h, ok := termSize(s.writer); ok {
		oldScrollingHeight := s.termHeight - s.tableHeight

		s.termWidth, s.termHeight = w, h

		if s.tableMode {
			s.computeTableHeight()

			scrollingHeight := s.termHeight - s.tableHeight

			if !firstUpdate {
			// If the scrolling region has changed, attempt to pan the existing text so that it is
			// not overwritten by the table.
			if scrollingHeight < oldScrollingHeight {
@@ -333,7 +343,6 @@ func (s *smartStatusOutput) updateTermSize() {
		}
	}
}
}

func (s *smartStatusOutput) actionTable() {
	scrollingHeight := s.termHeight - s.tableHeight
Loading