Documentation
¶
Overview ¶
Package console implements console command parsing for Nox.
Index ¶
- Constants
- func AsClient(ctx context.Context) context.Context
- func AsDedicated(ctx context.Context) context.Context
- func AsServer(ctx context.Context) context.Context
- func CurCommand(ctx context.Context) string
- func EncodeSecret(s string) string
- func IsCheats(ctx context.Context) bool
- func IsClient(ctx context.Context) bool
- func IsDedicated(ctx context.Context) bool
- func IsServer(ctx context.Context) bool
- func WithCheats(ctx context.Context) context.Context
- type Color
- type Command
- type CommandFunc
- type CommandLegacyFunc
- type Console
- func (cn *Console) BindKey(k keybind.Key, cmd string) bool
- func (cn *Console) BindKeyByName(name string, cmd string) bool
- func (cn *Console) Cheats() bool
- func (cn *Console) Commands() []*Command
- func (cn *Console) Exec(ctx context.Context, cmd string) bool
- func (cn *Console) ExecMacros(ctx context.Context, k keybind.Key) bool
- func (cn *Console) HelpString(cmd *Command) string
- func (cn *Console) Localize(sm *strman.StringManager, tokens ...string)
- func (cn *Console) Macros() bool
- func (cn *Console) ParseToken(ctx context.Context, tokInd int, tokens []string, cmds []*Command) bool
- func (cn *Console) Print(cl Color, str string)
- func (cn *Console) PrintOrError(cl Color, str string)
- func (cn *Console) Printf(cl Color, format string, args ...interface{})
- func (cn *Console) Register(c *Command)
- func (cn *Console) SetCheats(enabled bool)
- func (cn *Console) SetExec(exec ExecFunc)
- func (cn *Console) SetMacros(enabled bool)
- func (cn *Console) Strings() *strman.StringManager
- func (cn *Console) UnBindKey(k keybind.Key) bool
- func (cn *Console) UnBindKeyByName(name string) bool
- type ExecFunc
- type Flags
- type LocalizedPrinter
- type MultiPrinter
- type Printer
Constants ¶
const ( ColorBlack = Color(1) ColorDarkGrey = Color(2) ColorLightGrey = Color(3) ColorWhite = Color(4) ColorDarkRed = Color(5) ColorRed = Color(6) ColorLightRed = Color(7) ColorDarkGreen = Color(8) ColorGreen = Color(9) ColorLightGreen = Color(10) ColorDarkBlue = Color(11) ColorBlue = Color(12) ColorLightBlue = Color(13) ColorDarkYellow = Color(14) ColorYellow = Color(15) ColorLightYellow = Color(16) )
const ( // Server flag allows using this command on the server. Server = Flags(1 << 0) // Client flag allows using this command on the client. Client = Flags(1 << 2) // NoHelp hides the command from the commands list printed by help. NoHelp = Flags(1 << 3) Flag0x8 = Flags(1 << 4) // Cheat marks a command as a cheat, thus requiring enabling cheats first. Cheat = Flags(1 << 5) FlagDedicated = Flags(1 << 6) // Secret flag is used when the command token should be encrypted. Secret = Flags(1 << 7) )
const ( // ClientServer flag allows using this command on both the server and the client. ClientServer = Server | Client )
Variables ¶
This section is empty.
Functions ¶
func AsDedicated ¶
AsDedicated marks the commands as executed in a dedicated server context.
func CurCommand ¶
CurCommand gets current command string that is being executed.
func EncodeSecret ¶
EncodeSecret encodes a command token so it's kept secret. See Secret.
func IsDedicated ¶
IsDedicated checks if it's a dedicated server command context.
Types ¶
type Command ¶
type Command struct { // Token is the first token (keyword) of the command. Token string Alias string // HelpID is a string ID used to fetch the help text. HelpID strman.ID // Help is a text string used when a help text cannot be found by HelpID. Help string // Flags for this command. Flags Flags // Sub is a list of sub-commands. Sub []*Command // Func is a function that will be executed. Func CommandFunc // LegacyFunc is a legacy function that will be executed. // // Deprecated: use Func instead. LegacyFunc CommandLegacyFunc // Raw disables parsing of the rest of the tokens. // Command will receive a single token containing the rest of the line. Raw bool }
Command describes a console command.
type CommandFunc ¶
CommandFunc accepts a set of string arguments (tokens) and executes some action. The function should return true if the parsing was successful and false otherwise.
type CommandLegacyFunc ¶
CommandLegacyFunc is the same as CommandFunc, but accepts the full array of tokens and a index of the first token that is the first argument for the command. This functions is a Nox legacy and isn't designed well, e.g. changing parent of the sub-command requires changes to the code, since the number of tokens may change. The function should return true if the parsing was successful and false otherwise.
type Console ¶
type Console struct {
// contains filtered or unexported fields
}
Console handles console commands.
func New ¶
New creates a new console handler. A custom exec function can be provided. The function is used for macros only. in case it is nil, Exec will be used.
func (*Console) BindKeyByName ¶
BindKeyByName binds command to a key with a given alias.
func (*Console) ExecMacros ¶
ExecMacros runs a macros associated with a given key. It returns false if the key is not bound to anything.
func (*Console) HelpString ¶
func (*Console) Localize ¶
func (cn *Console) Localize(sm *strman.StringManager, tokens ...string)
Localize all command tokens. Additional tokens can be passed as well.
func (*Console) ParseToken ¶
func (cn *Console) ParseToken(ctx context.Context, tokInd int, tokens []string, cmds []*Command) bool
ParseToken matches the first token against a list of commands.
func (*Console) PrintOrError ¶
PrintOrError prints given text or prints a generic error if the text is empty.
func (*Console) Strings ¶
func (cn *Console) Strings() *strman.StringManager
Strings exposes the underlying string manager.
func (*Console) UnBindKeyByName ¶
UnBindKeyByName unbinds command from a key with a given alias.
type LocalizedPrinter ¶
type LocalizedPrinter interface { Strings() *strman.StringManager Printer }
LocalizedPrinter is an interface used for command output.
type MultiPrinter ¶
type MultiPrinter struct {
// contains filtered or unexported fields
}
func NewMultiPrinter ¶
func NewMultiPrinter(list ...Printer) *MultiPrinter
NewMultiPrinter prints into multiple printers at once.
func (*MultiPrinter) Add ¶
func (p *MultiPrinter) Add(p2 Printer)
func (*MultiPrinter) Print ¶
func (p *MultiPrinter) Print(cl Color, str string)
func (*MultiPrinter) Printf ¶
func (p *MultiPrinter) Printf(cl Color, format string, args ...interface{})