aios

package module
v0.1.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: MIT Imports: 19 Imported by: 0

README

aios

Abstract IO Streams(fork from github.com/cli/cli)

How to use

// in production
import "github.com/alswl/aios"

ios := aios.System()

// in testing
import "github.com/alswl/aios"

ios, stdin, stdout, stderr := aios.Test()

Documentation

Overview

Package term provides information about the terminal that the current process is connected to (if any), for example measuring the dimensions of the terminal and inspecting whether it's safe to output color.

Index

Constants

View Source
const DefaultWidth = 80

Variables

This section is empty.

Functions

func IsColorDisabled

func IsColorDisabled() bool

IsColorDisabled returns true if environment variables NO_COLOR or CLICOLOR prohibit usage of color codes in terminal output.

func IsColorForced

func IsColorForced() bool

IsColorForced returns true if environment variable CLICOLOR_FORCE is set to force colored terminal output.

func IsTerminal

func IsTerminal(f *os.File) bool

IsTerminal reports whether a file descriptor is connected to a terminal.

Types

type ColorScheme

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

func NewColorScheme

func NewColorScheme(enabled, is256enabled bool, trueColor bool) *ColorScheme

func (*ColorScheme) Blue

func (c *ColorScheme) Blue(t string) string

func (*ColorScheme) Bluef

func (c *ColorScheme) Bluef(t string, args ...interface{}) string

func (*ColorScheme) Bold

func (c *ColorScheme) Bold(t string) string

func (*ColorScheme) Boldf

func (c *ColorScheme) Boldf(t string, args ...interface{}) string

func (*ColorScheme) ColorFromRGB

func (c *ColorScheme) ColorFromRGB(hex string) func(string) string

ColorFromRGB returns a function suitable for TablePrinter.AddField that calls HexToRGB, coloring text if supported by the terminal.

func (*ColorScheme) ColorFromString

func (c *ColorScheme) ColorFromString(s string) func(string) string

func (*ColorScheme) Cyan

func (c *ColorScheme) Cyan(t string) string

func (*ColorScheme) CyanBold

func (c *ColorScheme) CyanBold(t string) string

func (*ColorScheme) Cyanf

func (c *ColorScheme) Cyanf(t string, args ...interface{}) string

func (*ColorScheme) FailureIcon

func (c *ColorScheme) FailureIcon() string

func (*ColorScheme) FailureIconWithColor

func (c *ColorScheme) FailureIconWithColor(colo func(string) string) string

func (*ColorScheme) Gray

func (c *ColorScheme) Gray(t string) string

func (*ColorScheme) Grayf

func (c *ColorScheme) Grayf(t string, args ...interface{}) string

func (*ColorScheme) Green

func (c *ColorScheme) Green(t string) string

func (*ColorScheme) GreenBold

func (c *ColorScheme) GreenBold(t string) string

func (*ColorScheme) Greenf

func (c *ColorScheme) Greenf(t string, args ...interface{}) string

func (*ColorScheme) HexToRGB

func (c *ColorScheme) HexToRGB(hex string, x string) string

HexToRGB uses the given hex to color x if supported by the terminal.

func (*ColorScheme) Magenta

func (c *ColorScheme) Magenta(t string) string

func (*ColorScheme) Magentaf

func (c *ColorScheme) Magentaf(t string, args ...interface{}) string

func (*ColorScheme) Red

func (c *ColorScheme) Red(t string) string

func (*ColorScheme) Redf

func (c *ColorScheme) Redf(t string, args ...interface{}) string

func (*ColorScheme) SuccessIcon

func (c *ColorScheme) SuccessIcon() string

func (*ColorScheme) SuccessIconWithColor

func (c *ColorScheme) SuccessIconWithColor(colo func(string) string) string

func (*ColorScheme) WarningIcon

func (c *ColorScheme) WarningIcon() string

func (*ColorScheme) Yellow

func (c *ColorScheme) Yellow(t string) string

func (*ColorScheme) Yellowf

func (c *ColorScheme) Yellowf(t string, args ...interface{}) string

type ErrClosedPagerPipe

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

ErrClosedPagerPipe is the error returned when writing to a pager that has been closed.

type GHTerm

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

GHTerm represents information about the terminal that a process is connected to.

func FromEnv

func FromEnv() GHTerm

FromEnv initializes a GHTerm from os.Stdout and environment variables:

  • GH_FORCE_TTY
  • NO_COLOR
  • CLICOLOR
  • CLICOLOR_FORCE
  • TERM
  • COLORTERM

func (GHTerm) ErrOut

func (t GHTerm) ErrOut() io.Writer

ErrOut is the writer writing to standard error.

func (GHTerm) In

func (t GHTerm) In() io.Reader

In is the reader reading from standard input.

func (GHTerm) Is256ColorSupported

func (t GHTerm) Is256ColorSupported() bool

Is256ColorSupported reports whether the terminal advertises ANSI 256 color codes.

func (GHTerm) IsColorEnabled

func (t GHTerm) IsColorEnabled() bool

IsColorEnabled reports whether it's safe to output ANSI color sequences, depending on IsTerminalOutput and environment variables.

func (GHTerm) IsTerminalOutput

func (t GHTerm) IsTerminalOutput() bool

IsTerminalOutput returns true if standard output is connected to a terminal.

func (GHTerm) IsTrueColorSupported

func (t GHTerm) IsTrueColorSupported() bool

IsTrueColorSupported reports whether the terminal advertises support for ANSI true color sequences.

func (GHTerm) Out

func (t GHTerm) Out() io.Writer

Out is the writer writing to standard output.

func (GHTerm) Size

func (t GHTerm) Size() (int, int, error)

Size returns the width and height of the terminal that the current process is attached to. In case of errors, the numeric values returned are -1.

func (GHTerm) Theme

func (t GHTerm) Theme() string

Theme returns the theme of the terminal by analyzing the background color of the terminal.

type IOStreams

type IOStreams struct {
	In     fileReader
	Out    fileWriter
	ErrOut io.Writer

	TempFileOverride *os.File
	// contains filtered or unexported fields
}

func System

func System() *IOStreams

func Test

func Test() (*IOStreams, *bytes.Buffer, *bytes.Buffer, *bytes.Buffer)

func (*IOStreams) CanPrompt

func (s *IOStreams) CanPrompt() bool

func (*IOStreams) ColorEnabled

func (s *IOStreams) ColorEnabled() bool

func (*IOStreams) ColorScheme

func (s *IOStreams) ColorScheme() *ColorScheme

func (*IOStreams) ColorSupport256

func (s *IOStreams) ColorSupport256() bool

func (*IOStreams) DetectTerminalTheme

func (s *IOStreams) DetectTerminalTheme()

DetectTerminalTheme is a utility to call before starting the output pager so that the terminal background can be reliably detected.

func (*IOStreams) GetNeverPrompt

func (s *IOStreams) GetNeverPrompt() bool

func (*IOStreams) GetPager

func (s *IOStreams) GetPager() string

func (*IOStreams) HasTrueColor

func (s *IOStreams) HasTrueColor() bool

func (*IOStreams) IsStderrTTY

func (s *IOStreams) IsStderrTTY() bool

func (*IOStreams) IsStdinTTY

func (s *IOStreams) IsStdinTTY() bool

func (*IOStreams) IsStdoutTTY

func (s *IOStreams) IsStdoutTTY() bool

func (*IOStreams) ReadUserFile

func (s *IOStreams) ReadUserFile(fn string) ([]byte, error)

func (*IOStreams) RefreshScreen

func (s *IOStreams) RefreshScreen()

func (*IOStreams) RunWithProgress

func (s *IOStreams) RunWithProgress(label string, run func() error) error

func (*IOStreams) SetAlternateScreenBufferEnabled

func (s *IOStreams) SetAlternateScreenBufferEnabled(enabled bool)

func (*IOStreams) SetColorEnabled

func (s *IOStreams) SetColorEnabled(colorEnabled bool)

func (*IOStreams) SetNeverPrompt

func (s *IOStreams) SetNeverPrompt(v bool)

func (*IOStreams) SetPager

func (s *IOStreams) SetPager(cmd string)

func (*IOStreams) SetStderrTTY

func (s *IOStreams) SetStderrTTY(isTTY bool)

func (*IOStreams) SetStdinTTY

func (s *IOStreams) SetStdinTTY(isTTY bool)

func (*IOStreams) SetStdoutTTY

func (s *IOStreams) SetStdoutTTY(isTTY bool)

func (*IOStreams) StartAlternateScreenBuffer

func (s *IOStreams) StartAlternateScreenBuffer()

func (*IOStreams) StartPager

func (s *IOStreams) StartPager() error

func (*IOStreams) StartProgressIndicator

func (s *IOStreams) StartProgressIndicator()

func (*IOStreams) StartProgressIndicatorWithLabel

func (s *IOStreams) StartProgressIndicatorWithLabel(label string)

func (*IOStreams) StopAlternateScreenBuffer

func (s *IOStreams) StopAlternateScreenBuffer()

func (*IOStreams) StopPager

func (s *IOStreams) StopPager()

func (*IOStreams) StopProgressIndicator

func (s *IOStreams) StopProgressIndicator()

func (*IOStreams) TempFile

func (s *IOStreams) TempFile(dir, pattern string) (*os.File, error)

func (*IOStreams) TerminalTheme

func (s *IOStreams) TerminalTheme() string

TerminalTheme returns "light", "dark", or "none" depending on the background color of the terminal.

func (*IOStreams) TerminalWidth

func (s *IOStreams) TerminalWidth() int

TerminalWidth returns the width of the terminal that controls the process

Jump to

Keyboard shortcuts

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