~ghost08/tcell-term

833545ebc21927cdcc85bc9cf1ecaf62a87c50f6 — Tim Culverhouse 1 year, 2 months ago 27ddd69
option: add option to set poll rate

Add option to set poll rate of EventWidgetContent events

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
1 files changed, 17 insertions(+), 1 deletions(-)

M terminal.go
M terminal.go => terminal.go +17 -1
@@ 22,6 22,7 @@ type Terminal struct {
	curVis   bool

	view views.View
	interval int

	close bool



@@ 31,6 32,7 @@ type Terminal struct {
func New(opts ...Option) *Terminal {
	t := &Terminal{
		term: termutil.New(),
		interval: 8,
	}
	t.term.SetWindowManipulator(&windowManipulator{})
	for _, opt := range opts {


@@ 47,6 49,20 @@ func WithWindowManipulator(wm termutil.WindowManipulator) Option {
	}
}

// WithPollInterval sets the minimum time, in ms, between
// views.EventWidgetContent events, which signal the screen has updates which
// can be drawn.
//
// Default: 8 ms
func WithPollInterval(interval int) Option {
	return func(t *Terminal) {
		if interval < 1 {
			interval = 1
		}
		t.interval = interval
	}
}

func (t *Terminal) Run(cmd *exec.Cmd) error {
	return t.run(cmd, &syscall.SysProcAttr{})
}


@@ 57,7 73,7 @@ func (t *Terminal) RunWithAttrs(cmd *exec.Cmd, attr *syscall.SysProcAttr) error 

func (t *Terminal) run(cmd *exec.Cmd, attr *syscall.SysProcAttr) error {
	w, h := t.view.Size()
	tmr := time.NewTicker(16 * time.Millisecond)
	tmr := time.NewTicker(time.Duration(t.interval) * time.Millisecond)
	go func() {
		for {
			select {