screenbuf/screenbuf.go
func (s *ScreenBuf) Write(b []byte) (int, error) {
	if bytes.ContainsAny(b, "\r\n") {
		return 0, fmt.Errorf("%q should not contain either \\r or \\n", b)
	}

	if s.reset {
		if err := s.Clear(); err != nil {
			return 0, err
		}
	}

	switch {
	case s.cursor == s.height:
		n, err := s.buf.Write(clearLine)
		if err != nil {
			return n, err
		}
		line := append(b, []byte("\n")...)
		n, err = s.buf.Write(line)
		if err != nil {
			return n, err
		}
		s.height++
		s.cursor++
		return n, nil
	case s.cursor < s.height:
		n, err := s.buf.Write(clearLine)
		if err != nil {
			return n, err
		}
		n, err = s.buf.Write(b)
		if err != nil {
			return n, err
		}
		n, err = s.buf.Write(moveDown)
		if err != nil {
			return n, err
		}
		s.cursor++
		return n, nil
	default:
		return 0, fmt.Errorf("Invalid write cursor position (%d) exceeded line height: %d", s.cursor, s.height)
	}
}
func (s *ScreenBuf) Write(b []byte) (int, error) {
	if bytes.ContainsAny(b, "\r\n") {
		return 0, fmt.Errorf("%q should not contain either \\r or \\n", b)
	}

	if s.reset {
		if err := s.Clear(); err != nil {
			return 0, err
		}
	}

	switch {
	case s.cursor == s.height:
		n, err := s.buf.Write(clearLine)
		if err != nil {
			return n, err
		}
		line := append(b, []byte("\n")...)
		n, err = s.buf.Write(line)
		if err != nil {
			return n, err
		}
		s.height++
		s.cursor++
		return n, nil
	case s.cursor < s.height:
		n, err := s.buf.Write(clearLine)
		if err != nil {
			return n, err
		}
		n, err = s.buf.Write(b)
		if err != nil {
			return n, err
		}
		n, err = s.buf.Write(moveDown)
		if err != nil {
			return n, err
		}
		s.cursor++
		return n, nil
	default:
		return 0, fmt.Errorf("Invalid write cursor position (%d) exceeded line height: %d", s.cursor, s.height)
	}
}
func ( s * ScreenBuf ) Write ( b [ ] byte ) ( int , error ) { if bytes . ContainsAny ( b , " \r \n " ) { return 0 , fmt . Errorf ( " \\ \\ " , b ) } if s . reset { if err := s . Clear ( ) ; err != nil { return 0 , err } } switch { case s . cursor == s . height : n , err := s . buf . Write ( clearLine ) if err != nil { return n , err } line := append ( b , [ ] byte ( " \n " ) ... ) n , err = s . buf . Write ( line ) if err != nil { return n , err } s . height ++ s . cursor ++ return n , nil case s . cursor < s . height : n , err := s . buf . Write ( clearLine ) if err != nil { return n , err } n , err = s . buf . Write ( b ) if err != nil { return n , err } n , err = s . buf . Write ( moveDown ) if err != nil { return n , err } s . cursor ++ return n , nil default : return 0 , fmt . Errorf ( " " , s . cursor , s . height ) } }
// Write writes a single line to the underlining buffer. If the ScreenBuf was
// previously reset, all previous lines are cleared and the output starts from
// the top. Lines with \r or \n will cause an error since they can interfere with the
// terminal ability to move between lines.
Write writes a single line to the underlining buffer . If the ScreenBuf was previously reset all previous lines are cleared and the output starts from the top . Lines with \ r or \ n will cause an error since they can interfere with the terminal ability to move between lines .