indentedwriter

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2022 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package indentedWriter implements an io.Writer that prefaces each output line with a defined number of spaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IndentedWriter

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

An io.Writer that prefixes each line with a defined number of spaces.

Note that IndentedWriter does not implement a Close() method, because there is no way to know how many other IndentedWriters may be simultaneously using the same output interface.

IndentedWriter is not safe for concurrency.

func IndentedWriterOn

func IndentedWriterOn(out io.Writer) *IndentedWriter

Return a fresh IndentedWriter on the given Writer interface.

func (*IndentedWriter) Indent

func (iw *IndentedWriter) Indent(n int) *IndentedWriter

Given an IndentedWriter, return a fresh IndentedWriter on the same Weiter interface whose start-of-line indentation is increased by n.

func (*IndentedWriter) NoIndent

func (iw *IndentedWriter) NoIndent() *IndentedWriter

Given an IndentedWriter, return a fresh IndentedWriter on the same Weiter interface whose start-of-line indentation is zero.

When emitting indented output, this is useful for writing pragmas such as line number directives.

func (*IndentedWriter) Print

func (iw *IndentedWriter) Print(a ...any) (n int, err error)

Method for Print, allowing IndentedWriter to subsume fmt

func (*IndentedWriter) Printf

func (iw *IndentedWriter) Printf(format string, a ...any) (n int, err error)

Method for Printf, allowing IndentedWriter to subsume fmt

func (*IndentedWriter) Println

func (iw *IndentedWriter) Println(a ...any) (n int, err error)

Method for Println, allowing IndentedWriter to subsume fmt

func (*IndentedWriter) Write

func (iw *IndentedWriter) Write(b []byte) (n int, err error)

Write bytes to the IndentedWriter receiver.

This satisfies the io.Writer interface, which lets us pass IdentedWriter to many of the functions in the various Go io libraries.

type Printable

type Printable interface {
	Print(a ...any) (n int, err error)
	Println(a ...any) (n int, err error)
	Printf(format string, a ...any) (n int, err error)
}

Jump to

Keyboard shortcuts

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