common

package
v0.0.0-...-ec5e93e Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2023 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TruncSuffix = iota
	TruncPrefix
	TruncMiddle
)
View Source
const (
	ColorEscape = "\033["
	Green       = "32m"
	Red         = "31m"
	ColorEnd    = ColorEscape + "0m"
	Bold        = "1"
)
View Source
const (
	CharClear     = "\x1b[H\x1b[2J"
	CharTab       = "\t"
	CharNewLine   = "\r\n"
	CharCleanLine = '\x15'
)
View Source
const LogFormat = "2006-01-02 15:04:05"

Variables

View Source
var ErrPasteIndicator = pasteIndicatorError{}

ErrPasteIndicator may be returned from ReadLine as the error, in addition to valid line data. It indicates that bracketed paste mode is enabled and that the returned line consists only of pasted data. Programs may wish to interpret pasted data more literally than typed data.

Functions

func Abs

func Abs(x int) int

func Base64Encode

func Base64Encode(s string) string

func EnsureDirExist

func EnsureDirExist(name string) error

func FileExists

func FileExists(name string) bool

func FilterPrefix

func FilterPrefix(strs []string, s string) (r []string)

func GenerateEd25519Pem

func GenerateEd25519Pem() string

func GenerateRSAPem

func GenerateRSAPem() string

func GetValidString

func GetValidString(s string, position int, positive bool) string

func GzipCompressFile

func GzipCompressFile(srcPath, dstPath string) error

func HashPassword

func HashPassword(password string) (string, error)

Hash password using the bcrypt hashing algorithm

func IgnoreErrWriteString

func IgnoreErrWriteString(writer io.Writer, s string)

func IgnoreErrWriteWindowTitle

func IgnoreErrWriteWindowTitle(writer io.Writer, title string)

func LongestCommonPrefix

func LongestCommonPrefix(strs []string) string

func LongestStr

func LongestStr(strs []string) string

func MD5Encode

func MD5Encode(b []byte) string

func MakeSignature

func MakeSignature(key, date string) string

func MarshalED25519PrivateKey

func MarshalED25519PrivateKey(key ed25519.PrivateKey) []byte

Writes ed25519 private keys into the new OpenSSH private key format. I have no idea why this isn't implemented anywhere yet, you can do seemingly everything except write it to disk in the OpenSSH private key format.

func Pretty

func Pretty(strs []string, width int) (s string)

func Sum

func Sum(i []int) int

func UUID

func UUID() string

func ValidUUIDString

func ValidUUIDString(sid string) bool

func WrapperString

func WrapperString(text string, color string, meta ...bool) string

func WrapperTitle

func WrapperTitle(text string) string

func WrapperWarn

func WrapperWarn(text string) string

Types

type AsciiConfig

type AsciiConfig struct {
	Title     string
	EnvShell  string
	EnvTerm   string
	Width     int
	Height    int
	Timestamp time.Time
}

type AsciiOption

type AsciiOption func(options *AsciiConfig)

func WithEnvShell

func WithEnvShell(shell string) AsciiOption

func WithEnvTerm

func WithEnvTerm(term string) AsciiOption

func WithHeight

func WithHeight(height int) AsciiOption

func WithTimestamp

func WithTimestamp(timestamp time.Time) AsciiOption

func WithTitle

func WithTitle(title string) AsciiOption

func WithWidth

func WithWidth(width int) AsciiOption

type AsciiWriter

type AsciiWriter struct {
	AsciiConfig
	TimestampNano int64
	// contains filtered or unexported fields
}

func NewWriter

func NewWriter(w io.Writer, opts ...AsciiOption) *AsciiWriter

func (*AsciiWriter) WriteHeader

func (w *AsciiWriter) WriteHeader() error

func (*AsciiWriter) WriteRow

func (w *AsciiWriter) WriteRow(p []byte) error

func (*AsciiWriter) WriteStdout

func (w *AsciiWriter) WriteStdout(ts float64, data []byte) error

type Env

type Env struct {
	Shell string `json:"SHELL"`
	Term  string `json:"TERM"`
}

type EscapeCodes

type EscapeCodes struct {
	// Foreground colors
	Black, Red, Green, Yellow, Blue, Magenta, Cyan, White []byte

	// Reset all attributes
	Reset []byte
}

EscapeCodes contains escape sequences that can be written to the terminal in order to achieve different styles of text.

type Header struct {
	Version   int    `json:"version"`
	Width     int    `json:"width"`
	Height    int    `json:"height"`
	Timestamp int64  `json:"timestamp"`
	Title     string `json:"title"`
	Env       Env    `json:"env"`
}

type Terminal

type Terminal struct {
	// AutoCompleteCallback, if non-null, is called for each keypress with
	// the full input line and the current position of the cursor (in
	// bytes, as an index into |line|). If it returns ok=false, the key
	// press is processed normally. Otherwise it returns a replacement line
	// and the new cursor position.
	AutoCompleteCallback func(line string, pos int, key rune) (newLine string, newPos int, ok bool)

	// Escape contains a pointer to the escape codes for this terminal.
	// It's always a valid pointer, although the escape codes themselves
	// may be empty if the terminal doesn't support them.
	Escape *EscapeCodes
	// contains filtered or unexported fields
}

Terminal contains the state for running a VT100 terminal that is capable of reading lines of input.

func NewTerminal

func NewTerminal(c io.ReadWriter, prompt string) *Terminal

NewTerminal runs a VT100 terminal on the given ReadWriter. If the ReadWriter is a local terminal, that terminal must first have been put into raw mode. prompt is a string that is written at the start of each input line (i.e. "> ").

func (*Terminal) GetSize

func (t *Terminal) GetSize() (width, height int)

func (*Terminal) ReadLine

func (t *Terminal) ReadLine() (line string, err error)

ReadLine returns a line of input from the terminal.

func (*Terminal) ReadLines

func (t *Terminal) ReadLines() (lines []string, err error)

func (*Terminal) ReadPassword

func (t *Terminal) ReadPassword(prompt string) (line string, err error)

ReadPassword temporarily changes the prompt and reads a password, without echo, from the terminal.

func (*Terminal) SetBracketedPasteMode

func (t *Terminal) SetBracketedPasteMode(on bool)

SetBracketedPasteMode requests that the terminal bracket paste operations with markers. Not all terminals support this but, if it is supported, then enabling this mode will stop any autocomplete callback from running due to pastes. Additionally, any lines that are completely pasted will be returned from ReadLine with the error set to ErrPasteIndicator.

func (*Terminal) SetEcho

func (t *Terminal) SetEcho(echo bool)

func (*Terminal) SetPrompt

func (t *Terminal) SetPrompt(prompt string)

SetPrompt sets the prompt to be used when reading subsequent lines.

func (*Terminal) SetSize

func (t *Terminal) SetSize(width, height int) error

func (*Terminal) Write

func (t *Terminal) Write(buf []byte) (n int, err error)

type WrapperTable

type WrapperTable struct {
	Labels      []string
	Fields      []string
	FieldsSize  map[string][3]int // 列宽,列最小宽,列最大宽
	Data        []map[string]string
	TotalSize   int
	TruncPolicy int

	Caption string
	// contains filtered or unexported fields
}

func (*WrapperTable) CalculateColumnsSize

func (t *WrapperTable) CalculateColumnsSize()

func (*WrapperTable) Display

func (t *WrapperTable) Display() string

func (*WrapperTable) Initial

func (t *WrapperTable) Initial()

Jump to

Keyboard shortcuts

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