From c2ab77dacbf175705f5a80fae1461d3d7b180165 Mon Sep 17 00:00:00 2001 From: Maxwell Huang-Hobbs Date: Mon, 28 Feb 2022 17:43:10 -0500 Subject: [PATCH] add Printf/Println to tea.go --- tea.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tea.go b/tea.go index fcbf822af4..ff587469d7 100644 --- a/tea.go +++ b/tea.go @@ -709,3 +709,30 @@ func (p *Program) RestoreTerminal() error { return nil } + +// Printf prints above the Program. This output is unmanaged by the program and +// will persist across renders by the Program. +// +// Unlike fmt.Printf (but similar to log.Printf) the message will be print on +// its own line. +// +// If the altscreen is active no output will be printed. +func (p *Program) Println(args ...interface{}) { + p.msgs <- printLineMessage{ + messageBody: fmt.Sprint(args...), + } +} + +// Printf prints above the Program. It takes a format template followed by +// values similar to fmt.Printf. This output is unmanaged by the program and +// will persist across renders by the Program. +// +// Unlike fmt.Printf (but similar to log.Printf) the message will be print on +// its own line. +// +// If the altscreen is active no output will be printed. +func (p *Program) Printf(template string, args ...interface{}) { + p.msgs <- printLineMessage{ + messageBody: fmt.Sprintf(template, args...), + } +}