Documentation ¶
Index ¶
- type ScreenBuf
- func (s *ScreenBuf) Clear() error
- func (s *ScreenBuf) Flush() error
- func (s *ScreenBuf) FlushLineWrap() error
- func (s *ScreenBuf) Reset()
- func (s *ScreenBuf) Write(b []byte) (int, error)
- func (s *ScreenBuf) WriteLineWrap(b []byte, outputLen int) (int, error)
- func (s *ScreenBuf) WriteString(str string) (int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ScreenBuf ¶
type ScreenBuf struct {
// contains filtered or unexported fields
}
ScreenBuf is a convenient way to write to terminal screens. It creates, clears and, moves up or down lines as needed to write the output to the terminal using ANSI escape codes.
func (*ScreenBuf) Flush ¶
Flush writes any buffered data to the underlying io.Writer, ensuring that any pending data is displayed.
func (*ScreenBuf) FlushLineWrap ¶ added in v0.0.3
func (*ScreenBuf) Reset ¶
func (s *ScreenBuf) Reset()
Reset truncates the underlining buffer and marks all its previous lines to be cleared during the next Write.
func (*ScreenBuf) Write ¶
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.
func (*ScreenBuf) WriteLineWrap ¶ added in v0.0.3
idea: the original code uses cursor to point current terminal line cursor,
however the cursor is not accurate after "Moveup" or "Movedown". Here, since the linewrap will cause the actual line count > s.height, we need someway to recalc the height to make sure the output height is correct Then, by using s.Clear() func, which automatically clears all the lines and move cursor to the original position, we could simply output our content then in FlushLineWrap().