output

package
v1.23.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2024 License: Apache-2.0 Imports: 3 Imported by: 7

Documentation

Overview

Package output provides a series of functions and structures to use to print text to outut devices. Since Device implements the io.Writer interface, it can be used for any Fprint statement.

Example
var device = NewDevice(os.Stdout)

fmt.Fprintln(device, "something")
fmt.Fprintln(device, "something unpaused")

device.Pause()

fmt.Fprintln(device, "something paused")
fmt.Fprintln(device, "something paused 2")
fmt.Fprintln(device, "something paused 3")

fmt.Println("== paused device ==")

device.Resume()
Output:

something
something unpaused
== paused device ==
something paused
something paused 2
something paused 3

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

type Device struct {
	// contains filtered or unexported fields
}

Device masks an io.Writer with an intermediary buffer that receives the writes while the device is paused. Once the device is unpaused the masked io.Writer will receive the buffered writes.

Example
var device = NewDevice(os.Stdout)

device.Write([]byte("something\n"))
device.Write([]byte("something unpaused\n"))

device.Pause()

device.Write([]byte("something paused\n"))
device.Write([]byte("something paused 2\n"))
device.Write([]byte("something paused 3\n"))

fmt.Println("== paused device ==")

device.Resume()
Output:

something
something unpaused
== paused device ==
something paused
something paused 2
something paused 3

func NewDevice

func NewDevice(device io.Writer) *Device

NewDevice instantiates a new Device from an io.Writer

func (*Device) Pause

func (d *Device) Pause()

Pause pauses writes to the masked device and writes to an intermediary buffer.

func (*Device) Resume

func (d *Device) Resume() (n int64, err error)

Resume copies the contents of the intermediary buffer to the device that is being masked.

func (*Device) Write

func (d *Device) Write(p []byte) (n int, err error)

Write writes len(p) bytes from p to the underlying data stream. It returns the number of bytes written from p (0 <= n <= len(p)) and any error encountered that caused the write to stop early. If the device is paused, instead of writing to the actual device it writes to an intermediary buffer that will hold any writes while the device is paused. If the device is paused for too long and causes the

func (*Device) Writer

func (d *Device) Writer() io.Writer

Writer returns the io.Writer that Device is wrapping.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL