screenbuf

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2024 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

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 New

func New(w io.Writer) *ScreenBuf

New creates and initializes a new ScreenBuf.

func (*ScreenBuf) Clear

func (s *ScreenBuf) Clear() error

Clear clears all previous lines and the output starts from the top.

func (*ScreenBuf) Flush

func (s *ScreenBuf) Flush() error

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 (s *ScreenBuf) FlushLineWrap() error

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

func (s *ScreenBuf) Write(b []byte) (int, error)

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

func (s *ScreenBuf) WriteLineWrap(b []byte, outputLen int) (int, error)

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().

func (*ScreenBuf) WriteString

func (s *ScreenBuf) WriteString(str string) (int, error)

WriteString is a convenient function to write a new line passing a string. Check ScreenBuf.Write() for a detailed explanation of the function behaviour.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL