Documentation
¶
Index ¶
- Constants
- Variables
- func EraseNLines(n int) string
- func RenderOnce(ctx context.Context, renderer Renderer, opts ...RenderOption) error
- func RunRenderLoop(ctx context.Context, renderer Renderer, opts ...RenderLoopOption) func() error
- type OutputFormat
- type RenderLoopOption
- type RenderLoopOptions
- type RenderOption
- type RenderOptions
- type Renderer
Constants ¶
const ( // The CursorUp ANSI escape code is not supported on all terminals. CursorUp = "\x1b[A" // Move cursor up one line // The EraseLine ANSI escape code is not supported on all terminals. EraseLine = "\x1b[K" // Erase the current line )
const ( // StaticRenderMode corresponds to a one-time call to RenderOnce. StaticRenderMode = "static" // LiveRenderMode corresponds to RunRenderLoop. LiveRenderMode = "live" )
Variables ¶
var DefaultRefreshRate = 100 * time.Millisecond
Functions ¶
func EraseNLines ¶
EraseNLines erases n lines from the terminal. It uses ANSI escape codes to move the CursorUp and EraseLine. ANSI escape codes are not supported on all terminals, so this function may not work as expected in all environments.
func RenderOnce ¶
func RenderOnce(ctx context.Context, renderer Renderer, opts ...RenderOption) error
RenderOnce calls the Renderer.Render function once. If no writer is provided, it defaults to os.Stdout.
RenderOnce is a convenience function around Renderer.Render providing a similar interface as RunRenderLoop, but without the live rendering loop.
func RunRenderLoop ¶
func RunRenderLoop(ctx context.Context, renderer Renderer, opts ...RenderLoopOption) func() error
RunRenderLoop starts the rendering loop. It returns a function that can be used to wait for the rendering loop to return. The rendering loop will run until the context is cancelled or an error occurs. If no writer is provided, it defaults to os.Stdout. If no refresh rate is provided, it defaults to DefaultRefreshRate. TODO(fabianburth): Implement render loop in a TUI. Currently, the feature is experimental, as the ASCI control sequences used to reset the output only work as long as the output fits into the terminal window (you may scroll very far out though ;) ). https://github.com/open-component-model/ocm-project/issues/608
Types ¶
type OutputFormat ¶
type OutputFormat int
const ( OutputFormatJSON OutputFormat = iota OutputFormatYAML OutputFormatNDJSON OutputFormatTree OutputFormatTable )
func (OutputFormat) String ¶
func (o OutputFormat) String() string
type RenderLoopOption ¶
type RenderLoopOption func(*RenderLoopOptions)
RenderLoopOption is a function that modifies the RenderLoopOptions. RenderLoopOption can be passed to RunRenderLoop to customize the rendering behavior.
func WithRefreshRate ¶
func WithRefreshRate(refreshRate time.Duration) RenderLoopOption
WithRefreshRate returns a RenderLoopOption that sets the refresh rate for the rendering loop. The refresh rate determines how often the render loop will refresh the output.
func WithRenderOptions ¶
func WithRenderOptions(opts ...RenderOption) RenderLoopOption
WithRenderOptions returns a RenderLoopOption that sets the RenderOptions on the RenderLoopOptions.
type RenderLoopOptions ¶
type RenderLoopOptions struct {
// RefreshRate is the rate at which the renderer should refresh the output.
RefreshRate time.Duration
RenderOptions
}
RenderLoopOptions defines the options for the RunRenderLoop.
type RenderOption ¶
type RenderOption func(*RenderOptions)
RenderOption is a function that modifies the RenderOptions. RenderOption can be passed to RenderOnce to customize the rendering behavior.
func WithWriter ¶
func WithWriter(writer io.Writer) RenderOption
WithWriter returns a RenderOption that sets the writer for the renderer.
type RenderOptions ¶
type RenderOptions struct {
// Writer is the writer to which the renderer should write the output.
// Typically, this is os.Stdout.
Writer io.Writer
}
RenderOptions defines the options for RenderOnce.
Directories
¶
| Path | Synopsis |
|---|---|
|
tree
Package tree provides functionality to render tree structures
|
Package tree provides functionality to render tree structures |
|
Package progress provides a generic progress tracking system for long-running operations.
|
Package progress provides a generic progress tracking system for long-running operations. |
|
bar
Package bar provides a terminal progress bar visualizer.
|
Package bar provides a terminal progress bar visualizer. |