forked from Mirrors/bubbletea
Comments
This commit is contained in:
parent
3647042096
commit
55a8d1853e
|
@ -47,7 +47,9 @@ type TerminalSizeMsg interface {
|
|||
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 {
|
||||
w, h, err := terminal.GetSize(int(os.Stdout.Fd()))
|
||||
return func() Msg {
|
||||
|
|
17
renderer.go
17
renderer.go
|
@ -68,6 +68,22 @@ func (r *renderer) flush() {
|
|||
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()
|
||||
defer r.mtx.Unlock()
|
||||
|
||||
|
@ -82,7 +98,6 @@ func (r *renderer) flush() {
|
|||
r.linesRendered++
|
||||
out.Write([]byte("\r\n"))
|
||||
} else {
|
||||
// TODO: don't write past the terminal width
|
||||
_, _ = out.Write([]byte{b})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue