Documentation ¶
Overview ¶
The term package provides a way to capture stdout and stderr and display the output in a browser. The package also provides a way to display charts in the browser. If you want to display charts, you can use the DataFrame type from the df package. Or you can leverage the Chart interface to display any chart in the go-echarts library.
The Escape* functions are used to wrap the content in HTML tags so that it can be displayed in a browser.
Index ¶
- Constants
- func BindPort(port int) func(t *Term)
- func Block(e BlockElement, ops ...BlockOption)
- func BlockSize(e BlockElement, width, height int, ops ...BlockOption)
- func Close()
- func Detach() func(t *Term)
- func EscapeIframe(pageHtml string, klass string) string
- func Format(format OutputFormat) func(t *Term)
- func HTML(page bool) iter.Seq[string]
- func NewThreadSafeWriter(w io.Writer) *threadSafeWriter
- func Open(options ...TermOption)
- func PrintBlock(html string, ops ...BlockOption)
- func PrintBlockSize(html string, width, height int, ops ...BlockOption)
- func PrintHtml(html string)
- type BlockElement
- type BlockOption
- type BlockWithOption
- type Buffer
- type Image
- type OutputFormat
- type Term
- type TermOption
Constants ¶
const ( // HtmlTag is a special tag used to wrap HTML content in the buffer. // None html content will be wrapped in <pre> tag. HtmlTag = "==========76ADCBF0-980B-4C05-951F-63340F35E9C==========" MaxBuffersize = 1024 * 1024 * 1024 // 1GB )
const BlockStyle = `` /* 718-byte string literal not displayed */
Block div for html content such as charts and plots. For x-axis, it will take up the full width of the parent element, center it's content if it's smaller than the parent element, and overflow on the x-axis if it's larger. For y-axis, it will either use a fixed height or dynamically adjust to the content. Input: (x, y) Block: (width: 100%, height: auto|y) Child: (width: 100%|x, height: 100%)
const BodyStyle = `` /* 221-byte string literal not displayed */
const IframeStyle = `` /* 230-byte string literal not displayed */
const ScrollScript = `` /* 1286-byte string literal not displayed */
const TextStyle = `` /* 1003-byte string literal not displayed */
Variables ¶
This section is empty.
Functions ¶
func BindPort ¶
BindPort will start a web server to serve the terminal output on the specified port.
func Block ¶
func Block(e BlockElement, ops ...BlockOption)
func BlockSize ¶
func BlockSize(e BlockElement, width, height int, ops ...BlockOption)
func Close ¶
func Close()
Close closes the terminal. This function should be called at the end of the program.
func EscapeIframe ¶
EscapeIframe wraps the given HTML content in an iframe tag and escapes it for srcdoc attribute. If the pageHtml starts with "http", it will be used as the source url of the iframe.
func Format ¶
func Format(format OutputFormat) func(t *Term)
Format sets the format of the terminal output. The default is FormatRaw.
func HTML ¶
HTML returns a sequence of strings for the HTML content. If page is true, the HTML content is a full page. Otherwise, it is a fragment. One should only call this function when the format option is set to Custom.
func NewThreadSafeWriter ¶
func Open ¶
func Open(options ...TermOption)
Open opens the terminal. This function should be called at the beginning of the program.
func PrintBlock ¶
func PrintBlock(html string, ops ...BlockOption)
func PrintBlockSize ¶
func PrintBlockSize(html string, width, height int, ops ...BlockOption)
PrintBlockSize supports HTML Page, Iframe, and other HTML elements.
Types ¶
type BlockElement ¶
type BlockElement interface {
HTML() string // Returns the HTML content of the block
}
BlockElement represents a horizontally centered or scrollable block of HTML content. There are two types of block elements: one can have auto size (such as an img), and the other can not (such as an iframe). For elements which can not have auto size, the box element should have a 100% width and auto overflow-x. So that it can take the responsibility for horizontal scrolling from the row element.
func ImageData ¶
func ImageData(mime string, data []byte) BlockElement
type BlockOption ¶
type BlockOption func(*blockConfig)
func BackgroundOption ¶
func BackgroundOption(c color.Color) BlockOption
func ColorOption ¶
func ColorOption(c color.Color) BlockOption
func OpacityOption ¶
func OpacityOption(x float64) BlockOption
func SizeOption ¶
func SizeOption(width, height int) BlockOption
type BlockWithOption ¶
type BlockWithOption interface { BlockElement Options() []BlockOption }
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is a simple in-memory buffer that can be used as an io.Reader or io.Writer. It's like bytes.Buffer, but it reads and writes to a channel instead of a byte slice. So the read and write operations can block until data is available. One of the NewBuffer* functions should be used to create a new buffer. The Close method should be called to notify readers that no more data will be written.
func NewBufferChan ¶
func NewBufferSize ¶
func NewBufferString ¶
type OutputFormat ¶
type OutputFormat int
const ( HTMLWindow OutputFormat = iota // Open in browser HTMLPage // Print HTML page HTMLContent // Print HTML content Raw // Print raw text, useful for debugging Custom // Print nothing, user is expected to call the HTML function )
type Term ¶
type Term struct {
// contains filtered or unexported fields
}
Term captures stdout and stderr and provides methods to display the output in a browser.
func NewTerm ¶
func NewTerm() *Term
NewTerm creates a new Term and copies stdout and stderr to a internal buffer. The output can be displayed in a browser when you use the Open method with the default HTMLWindow format. See the Format options for other ways to display the output.
func (*Term) Close ¶
func (t *Term) Close()
Close stops capturing stdout and stderr and restores the original stdout and stderr.
func (*Term) HTML ¶
HTML returns a sequence of strings that represent the terminal output in HTML format. If fullPage is true, the output will be wrapped in a full HTML page with styles. Otherwise, the output will be some HTML content that can be embedded in a page.
func (*Term) Open ¶
func (t *Term) Open(options ...TermOption)
type TermOption ¶
type TermOption func(*Term)