This commit is contained in:
Christian Rocha 2020-06-08 12:43:24 -04:00
parent 3647042096
commit 55a8d1853e
No known key found for this signature in database
GPG Key ID: D6CC7A16E5878018
2 changed files with 19 additions and 2 deletions

View File

@ -47,7 +47,9 @@ type TerminalSizeMsg interface {
Error() error Error() error
} }
// GetTerminalSize is used to get // GetTerminalSize is a command used to retrieve the terminal dimensions. Pass
// a function used to construct your message, which would implement the
// TerminalSizeMsg interaface.
func GetTerminalSize(newMsgFunc func(int, int, error) TerminalSizeMsg) Cmd { func GetTerminalSize(newMsgFunc func(int, int, error) TerminalSizeMsg) Cmd {
w, h, err := terminal.GetSize(int(os.Stdout.Fd())) w, h, err := terminal.GetSize(int(os.Stdout.Fd()))
return func() Msg { return func() Msg {

View File

@ -68,6 +68,22 @@ func (r *renderer) flush() {
return return
} }
// We haven an opportunity here to limit the rendering to the terminal width
// and height to the width of the terminal, but this would mean a few things:
//
// 1) We'd need to maintain the terminal dimensions internally and listen
// for window size changes.
//
// 2) We'd need to measure the width of lines, accounting for double-byte
// widths. We'd use something like go-runewidth
// (http://github.com/mattn/go-runewidth).
//
// 3) We'd need to measure the width of lines excluding ANSI escape
// sequences and break lines in the right places accordingly.
//
// Because of the way this would complicate the renderer, this may not be
// the place to do that.
r.mtx.Lock() r.mtx.Lock()
defer r.mtx.Unlock() defer r.mtx.Unlock()
@ -82,7 +98,6 @@ func (r *renderer) flush() {
r.linesRendered++ r.linesRendered++
out.Write([]byte("\r\n")) out.Write([]byte("\r\n"))
} else { } else {
// TODO: don't write past the terminal width
_, _ = out.Write([]byte{b}) _, _ = out.Write([]byte{b})
} }
} }