text

package
v0.0.0-...-b9cfb1f Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2019 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AnsiPre   = "\u001b["
	AnsiReset = AnsiPre + "0m"

	AnsiBold       = AnsiPre + "1m"
	AnsiItalic     = AnsiPre + "3m"
	AnsiUnderlined = AnsiPre + "4m"

	AnsiBlack   = AnsiPre + "30m"
	AnsiRed     = AnsiPre + "31m"
	AnsiGreen   = AnsiPre + "32m"
	AnsiYellow  = AnsiPre + "33m"
	AnsiBlue    = AnsiPre + "34m"
	AnsiMagenta = AnsiPre + "35m"
	AnsiCyan    = AnsiPre + "36m"
	AnsiWhite   = AnsiPre + "37m"
	AnsiGray    = AnsiPre + "30;1m"

	AnsiBrightRed     = AnsiPre + "31;1m"
	AnsiBrightGreen   = AnsiPre + "32;1m"
	AnsiBrightYellow  = AnsiPre + "33;1m"
	AnsiBrightBlue    = AnsiPre + "34;1m"
	AnsiBrightMagenta = AnsiPre + "35;1m"
	AnsiBrightCyan    = AnsiPre + "36;1m"
	AnsiBrightWhite   = AnsiPre + "37;1m"
)
View Source
const (
	Pre = "§"

	Black      = Pre + "0"
	Blue       = Pre + "1"
	Green      = Pre + "2"
	Cyan       = Pre + "3"
	Red        = Pre + "4"
	Magenta    = Pre + "5"
	Orange     = Pre + "6"
	BrightGray = Pre + "7"
	Gray       = Pre + "8"
	BrightBlue = Pre + "9"

	BrightGreen   = Pre + "a"
	BrightCyan    = Pre + "b"
	BrightRed     = Pre + "c"
	BrightMagenta = Pre + "d"
	Yellow        = Pre + "e"
	White         = Pre + "f"

	Obfuscated    = Pre + "k"
	Bold          = Pre + "l"
	StrikeThrough = Pre + "m"
	Underlined    = Pre + "n"
	Italic        = Pre + "o"

	Reset = Pre + "r"
)
View Source
const (
	Debug      = "[Debug]"
	Info       = "[Info]"
	Notice     = "[Notice]"
	Alert      = "[Alert]"
	Error      = "[Error]"
	Warning    = "[Warning]"
	Critical   = "[Critical]"
	Chat       = "[Chat]"
	StackTrace = "[Stack Trace]"
)

Variables

View Source
var DefaultLogger = NewLogger("GoMine", false)

DefaultLogger is the default GoMine logger. It has the prefix `GoMine` and has debug turned off. The default logger will write only to Stdout.

Functions

This section is empty.

Types

type ColoredString

type ColoredString string

ColoredString is a string containing colours. ColoredString has functions to manipulate the colours it holds.

func (ColoredString) StripANSI

func (str ColoredString) StripANSI() string

StripANSI strips all ANSI colors in a ColoredString. A new string is returned with the colors stripped.

func (ColoredString) StripAll

func (str ColoredString) StripAll() string

StripAll strips all colors (both ANSI and MCPE) in a ColoredString. A new string is returned with the colors stripped.

func (ColoredString) StripMinecraft

func (str ColoredString) StripMinecraft() string

StripMinecraft strips all Minecraft colors in a ColoredString. A new string is returned with the colors stripped.

func (ColoredString) ToANSI

func (str ColoredString) ToANSI() string

ToANSI converts all Minecraft colors in a ColoredString to ANSI colors. A new string is returned with the colors converted.

func (ColoredString) ToMinecraft

func (str ColoredString) ToMinecraft() string

ToMinecraft converts all ANSI colors in a ColoredString to Minecraft colors. A new string is returned with the colors converted.

type CommandReader

type CommandReader struct {

	// LineReadFunctions are all line read functions.
	// These functions get executed every time a line gets read.
	LineReadFunctions []func(line string)
	// contains filtered or unexported fields
}

CommandReader implements command reading from io.Readers. CommandReader continuously processes incoming commands, and executes all associated functions with it.

func NewCommandReader

func NewCommandReader(inputReader io.Reader) *CommandReader

NewCommandReader returns a new CommandReader. The input io.Reader is encapsulated by a bufio.Reader and further used to continuously read from.

func (*CommandReader) AddReadFunc

func (reader *CommandReader) AddReadFunc(outputFunc func(string))

AddReadFunc adds a new line read function to the command reader. The function passed will get called with the line read as argument, every time a command gets read from the input reader. Example: func(line string) { os.Stdout.Write([]byte("You wrote: " + line)) }

type Logger

type Logger struct {
	// Prefix is the prefix of the logger.
	// Every message is prefixed with this string.
	// The prefix is enclosed in brackets, as such: [Prefix]
	Prefix string
	// DebugMode is the debug mode of the logger.
	// If true, writes debug messages.
	DebugMode bool
	// OutputFunctions contains all logger output functions.
	// Every output function gets called once a message gets logged.
	OutputFunctions []func(message []byte)
	// MessageQueue is the queue of messages to the processed.
	// These messages will be continuously processed on a different goroutine.
	MessageQueue chan string
	// contains filtered or unexported fields
}

Logger is a helper for writing log information to multiple locations at the same time on a different goroutine. Each logger has a prefix, which all messages will be prefixed with, and a debug mode, which if turned on will write debug messages too.

func NewLogger

func NewLogger(prefix string, debugMode bool) *Logger

NewLogger returns a new logger with the given prefix and debug mode. Additional output functions can be added to the logger once an instance has been created using this function. The logger will be made to process immediately when creating a new logger.

func (*Logger) AddOutput

func (logger *Logger) AddOutput(f func(message []byte))

AddOutput adds a new output function to the logger. The function passed will get called with the message provided as argument every time a message gets logged. Example: func(message []byte) { os.Stdout.Write(message) }

func (*Logger) Alert

func (logger *Logger) Alert(messages ...interface{})

Alert logs an alert.

func (*Logger) Critical

func (logger *Logger) Critical(messages ...interface{})

Critical logs a critical warning message.

func (*Logger) Debug

func (logger *Logger) Debug(messages ...interface{})

Debug logs a debug message.

func (*Logger) Error

func (logger *Logger) Error(messages ...interface{})

Error logs an error message.

func (*Logger) Info

func (logger *Logger) Info(messages ...interface{})

Info logs an info message.

func (*Logger) LogChat

func (logger *Logger) LogChat(messages ...interface{})

LogChat logs a chat message to the logger.

func (*Logger) LogError

func (logger *Logger) LogError(err error)

LogError logs an actual error to the logger. A nil error may also be passed, which the logger will completely ignore.

func (*Logger) LogStack

func (logger *Logger) LogStack()

LogStack logs the stack trace.

func (*Logger) Notice

func (logger *Logger) Notice(messages ...interface{})

Notice logs a notice message.

func (*Logger) Wait

func (logger *Logger) Wait()

Wait waits until the logger is done logging all messages currently in the message queue. The current goroutine will be blocked until the logger is done processing all messages, and the writing goroutine will be stopped. After waiting, the writing process gets restarted.

func (*Logger) Warning

func (logger *Logger) Warning(messages ...interface{})

Warning logs a warning message.

func (*Logger) Write

func (logger *Logger) Write(message []byte)

Write writes a byte array to the logger. All Minecraft colors are first replaced with ANSI colors. after which they get added to the message queue. The message will then get processed on a different goroutine.

func (*Logger) WriteString

func (logger *Logger) WriteString(message string)

Write writes a string to the logger. All Minecraft colors are first replaced with ANSI colors. after which they get added to the message queue. The message will then get processed on a different goroutine.

Jump to

Keyboard shortcuts

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