forked from Mirrors/bubbletea
Adjust exports of new msgs + add msg to replace ignored lines
This commit is contained in:
parent
4d68ed07ef
commit
a492302609
53
renderer.go
53
renderer.go
|
@ -16,46 +16,65 @@ const (
|
||||||
|
|
||||||
// RendererIgnoreLinesMsg tells the renderer to skip rendering for the given
|
// RendererIgnoreLinesMsg tells the renderer to skip rendering for the given
|
||||||
// range of lines.
|
// range of lines.
|
||||||
type IgnoreLinesMsg struct {
|
type ignoreLinesMsg struct {
|
||||||
|
From int
|
||||||
|
To int
|
||||||
|
}
|
||||||
|
|
||||||
|
// IgnoreLines produces command that sets a range of lines to be ignored
|
||||||
|
// by the renderer. The general use case here is that those lines would be
|
||||||
|
// rendered separately for performance reasons.
|
||||||
|
func IgnoreLines(from int, to int) Cmd {
|
||||||
|
return func() Msg {
|
||||||
|
return ignoreLinesMsg{From: from, To: to}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type resetIgnoreLinesMsg struct {
|
||||||
from int
|
from int
|
||||||
to int
|
to int
|
||||||
}
|
}
|
||||||
|
|
||||||
// IgnoreLines is a command that sets a range of lines to be ignored
|
// ResetIngoredLines produces a command that clears any lines set to be ignored
|
||||||
// by the renderer. The general use case here is that those lines would be
|
// and the sets new ones by the renderer. This is probably a more common use
|
||||||
// rendered separately for performance reasons.
|
// case than the IgnoreLines command.
|
||||||
func IgnoreLines(from int, to int) IgnoreLinesMsg {
|
func ResetIgnoredLines(from int, to int) Cmd {
|
||||||
return IgnoreLinesMsg{from: from, to: to}
|
return func() Msg {
|
||||||
|
return resetIgnoreLinesMsg{from: from, to: to}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearIgnoredLinesMsg has the renderer allows the renderer to commence rendering
|
// ClearIgnoredLinesMsg has the renderer allows the renderer to commence rendering
|
||||||
// any lines previously set to be ignored.
|
// any lines previously set to be ignored.
|
||||||
type ClearIgnoredLinesMsg struct{}
|
type clearIgnoredLinesMsg struct{}
|
||||||
|
|
||||||
// RendererIgnoreLines is a command that sets a range of lines to be ignored
|
// RendererIgnoreLines is a command that sets a range of lines to be
|
||||||
// by the renderer.
|
// ignored by the renderer.
|
||||||
func ClearIgnoredLines(from int, to int) ClearIgnoredLinesMsg {
|
func ClearIgnoredLines() Msg {
|
||||||
return ClearIgnoredLinesMsg{}
|
return clearIgnoredLinesMsg{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScrollDownMsg is experiemental. There are no guarantees about it persisting
|
// ScrollDownMsg is experiemental. There are no guarantees about it persisting
|
||||||
// in a future API. It's exposed for high performance scrolling.
|
// in a future API. It's exposed for high performance scrolling.
|
||||||
type ScrollUpMsg struct {
|
type ScrollUpMsg struct {
|
||||||
newLines []string
|
NewLines []string
|
||||||
topBoundary int
|
TopBoundary int
|
||||||
bottomBoundary int
|
BottomBoundary int
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScrollDownMsg is experiemental. There are no guarantees about it persisting
|
// ScrollDownMsg is experiemental. There are no guarantees about it persisting
|
||||||
// in a future API. It's exposed for high performance scrolling.
|
// in a future API. It's exposed for high performance scrolling.
|
||||||
type ScrollDownMsg struct {
|
type ScrollDownMsg struct {
|
||||||
newLines []string
|
NewLines []string
|
||||||
topBoundary int
|
TopBoundary int
|
||||||
bottomBoundary int
|
BottomBoundary int
|
||||||
}
|
}
|
||||||
|
|
||||||
// renderer is a timer-based renderer, updating the view at a given framerate
|
// renderer is a timer-based renderer, updating the view at a given framerate
|
||||||
// to avoid overloading the terminal emulator.
|
// to avoid overloading the terminal emulator.
|
||||||
|
//
|
||||||
|
// In cases where very high performance is needed the renderer can be told
|
||||||
|
// to exclude ranges of lines, allowing them to be written to directly.
|
||||||
type renderer struct {
|
type renderer struct {
|
||||||
out io.Writer
|
out io.Writer
|
||||||
buf bytes.Buffer
|
buf bytes.Buffer
|
||||||
|
|
22
tea.go
22
tea.go
|
@ -62,8 +62,8 @@ type batchMsg []Cmd
|
||||||
// WindowSizeMsg is used to report on the terminal size. It's fired once initially
|
// WindowSizeMsg is used to report on the terminal size. It's fired once initially
|
||||||
// and then on every terminal resize.
|
// and then on every terminal resize.
|
||||||
type WindowSizeMsg struct {
|
type WindowSizeMsg struct {
|
||||||
width int
|
Width int
|
||||||
height int
|
Height int
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewProgram creates a new Program.
|
// NewProgram creates a new Program.
|
||||||
|
@ -174,19 +174,27 @@ func (p *Program) Start() error {
|
||||||
// Report resizes to the renderer. Only necessary for special,
|
// Report resizes to the renderer. Only necessary for special,
|
||||||
// performance-based rendering.
|
// performance-based rendering.
|
||||||
if size, ok := msg.(WindowSizeMsg); ok {
|
if size, ok := msg.(WindowSizeMsg); ok {
|
||||||
mrRenderer.width = size.width
|
mrRenderer.width = size.Width
|
||||||
mrRenderer.height = size.height
|
mrRenderer.height = size.Height
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle messages telling the main rendering routine to ignore
|
// Handle messages telling the main rendering routine to ignore
|
||||||
// ranges of lines. Useful for performance-based rendering.
|
// ranges of lines. Useful for performance-based rendering.
|
||||||
if ignore, ok := msg.(IgnoreLinesMsg); ok {
|
if lineRange, ok := msg.(ignoreLinesMsg); ok {
|
||||||
mrRenderer.setIgnoredLines(ignore.from, ignore.to)
|
mrRenderer.setIgnoredLines(lineRange.from, lineRange.to)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle messages telling the main rendering routine to clear
|
||||||
|
// ranges of lines previously ignored and set a new range of
|
||||||
|
// ignored lines. For use in high-performance rendering.
|
||||||
|
if lineRange, ok := msg.(resetIgnoreLinesMsg); ok {
|
||||||
|
mrRenderer.clearIgnoredLines()
|
||||||
|
mrRenderer.setIgnoredLines(lineRange.from, lineRange.to)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle messages telling the main rendering to stop ignoring
|
// Handle messages telling the main rendering to stop ignoring
|
||||||
// lines. Useful when disabling any performance-based rendering.
|
// lines. Useful when disabling any performance-based rendering.
|
||||||
if _, ok := msg.(IgnoreLinesMsg); ok {
|
if _, ok := msg.(clearIgnoredLinesMsg); ok {
|
||||||
mrRenderer.clearIgnoredLines()
|
mrRenderer.clearIgnoredLines()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue