config

package
v0.0.0-...-aadac20 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: MIT Imports: 10 Imported by: 1

Documentation

Overview

Package config contains various structs and utilities meant to hold and deal with configuration for Stimmtausch.

Index

Constants

View Source
const DefaultConfig string = `` /* 3697-byte string literal not displayed */

Variables

View Source
var (
	HomeDir    string
	ConfigDir  string
	WorkingDir string
	LogDir     string
)

Functions

func InitDirs

func InitDirs()

InitDirs initializes the directories used by Stimmtausch.

Types

type Client

type Client struct {
	Syslog  Syslog
	Profile Profile
	Logging Logging
	UI      UI
}

Client holds information regarding how Stimmtausch runs.

type Config

type Config struct {
	// Version of the configuration structure.
	Version int

	// A list of server types (MUCK, MUD, etc), dictating how to connect.
	ServerTypes map[string]ServerType `yaml:"server_types" toml:"server_types"`

	// A list of servers.
	Servers map[string]Server

	// A list of worlds (characters/users/accounts/etc) tying login information
	// to servers.
	Worlds map[string]World

	// A list of triggers to match on input.
	Triggers []Trigger

	// References to compiled triggers.
	CompiledTriggers []*Trigger `yaml:"-" toml:"-"`

	Client Client

	HomeDir    string `yaml:"-" toml:"-"`
	ConfigDir  string `yaml:"-" toml:"-"`
	WorkingDir string `yaml:"-" toml:"-"`
	LogDir     string `yaml:"-" toml:"-"`
}

Config holds all the configuration for Stimmtausch. For information about what the settings are used for and how they should appear, see the files in _conf

func New

func New() (*Config, error)

New returns a new config object all loaded and validated.

func (*Config) Dump

func (c *Config) Dump() string

func (*Config) FinalizeAndValidate

func (c *Config) FinalizeAndValidate() []error

func (*Config) Reload

func (c *Config) Reload() error

Reload loads config into a new object and then copies over its internals into the old object.

type Logging

type Logging struct {

	// The time format to use when logging times.
	// TODO validate
	TimeString string `yaml:"time_string" toml:"time_string"`

	// Whether or not to log timestamps.
	LogTimestamps bool `yaml:"log_timestamps" toml"log_timestamps"`

	// Whether or not to keep logs of the connection after disconnect.
	LogWorld bool `yaml:"log_world" toml:"log_world"`
}

Logging holds information regarding logging from connections.

type Profile

type Profile struct {

	// Whether or not to profile memory usage.
	Mem bool

	// Whether or not to profile CPU usage.
	CPU bool `yaml:"cpu" toml:"cpu"`
}

Profile holds information regarding profiling resources in development.

type Server

type Server struct {
	// The key for the server in the configuration file.
	Name string

	// The hostname for the server.
	Host string

	// The port to connect to.
	Port uint

	// Whether or not to use SSL.
	SSL bool

	// Whether or not self-signed certs should be trusted.
	Insecure bool

	// The type of server (MUCK, MUSH, etc...) this is.
	ServerType string `yaml:"type" toml:"type"`

	// The maximum length of a buffer
	MaxBuffer uint `yaml:"max_buffer"m toml:"max_buffer"`
}

Server represents information required to connect to a remote server.

func NewServer

func NewServer(name, host string, port uint, ssl, insecure bool, srvType string) *Server

NewServer returns a new server object for the given values.

type ServerType

type ServerType struct {
	Name             string
	ConnectString    string `yaml:"connect_string" toml:"connect_string"`
	DisconnectString string `yaml:"disconnect_string" toml:"disconnect_string"`
}

ServerType represents a type of server (MUCK, MUSH, etc...), which mostly boils down to things such as how to connect to it, etc.

func NewServerType

func NewServerType(name, connectString, disconnectString string) *ServerType

NewServerType returns a new serverType object for the given values.

type Syslog

type Syslog struct {

	// Whether or not to show the system log in a pane in the UI.
	ShowSyslog bool `yaml:"show_syslog" toml:"log_level"`

	// Lowest log level to show by default. Options are:
	// TRACE, DEBUG, INFO (default), WARNING, ERROR, CRITICAL
	LogLevel string `yaml:"log_level" toml:"log_level"`
}

Syslog holds nformation regarding the logging generated by the program (as opposed to the connections).

type Trigger

type Trigger struct {
	// The name of the trigger.
	Name string

	// The type of trigger: hilite, gag, script, macro.
	Type string

	// The world to which this trigger applies (if blank, applies to all).
	World string

	// A regexp to match against.
	Match string

	// A list of regexps to match against.
	Matches []string

	// A list of attributes used in hilite (color, style, etc).
	Attributes string

	// For gags, whether or not to log the gagged string anyway.
	LogAnyway bool `yaml:"log_anyway" toml:"log_anyway"`

	// The path of a script to run.
	Script string

	// Whether or not to send the output of the script or macro to the world.
	// If false, the user will be shown the output
	OutputToWorld string `yaml:"output_to_world" toml:"output_to_world"`

	// The name of a macro to run.
	Macro string
	// contains filtered or unexported fields
}

func (Trigger) Compile

func (t Trigger) Compile() (*Trigger, error)

Compile returns a pointer to the compiled trigger.

func (*Trigger) Run

func (t *Trigger) Run(world, input string, cfg *Config) (bool, string, []error)

Run takes the provided byte-slice from the world and, if it matches, runs the action specified in the trigger based on the type (hilite, gag, script macro) if the world matches the one specified in the trigger (if none is specified, it matches all worlds). It returns the (potentially modified) input, whether or not the trigger matched, and any errors it encountered along the way.

type UI

type UI struct {

	// How many lines of scrollback (data received) to keep in memory.
	Scrollback int

	// How many lines of history (data sent) to keep in memory.
	History int

	// How many columns to restrict the output view to.
	MaxWidth int `yaml:"max_width" toml:"max_width"`

	// Whether or not to use a unified history buffer for all
	// connections, or one per.
	// TODO
	UnifiedHistoryBuffer bool `yaml:"unified_history_buffer" toml:"unified_history_buffer"`

	// Whether or not to use Vim-style key bindings
	// TODO
	VimKeybindings bool `yaml:"vim_keybindings" toml:"vim_keybindings"`

	// Indentation of wrapped lines.
	IndentFirst      int `yaml:"indent_first" toml:"indent_first"`
	IndentSubsequent int `yaml:"indent_subsequent" toml:"indent_subsequent"`

	// Whether or not to support mouse events
	// TODO
	Mouse bool

	// Colors in the UI
	Colors struct {
		// The colors for the input buffer titles in ansigo specifications.
		SendTitle struct {
			Active             string
			ActiveMore         string `yaml:"active_more" toml:"active_more"` // TODO
			Inactive           string
			InactiveMore       string `yaml:"inactive_more" toml:"inactive_more"` // TODO
			Disconnected       string
			DisconnectedMore   string `yaml:"disconnected_more" toml:"disconnected_more"`     // TODO
			DisconnectedActive string `yaml:"disconnected_active" toml:"disconnected_active"` // TODO
		} `yaml:"send_title" toml:"send_title"`
		ModalTitle string `yaml:"modal_title" toml:"modal_title"`
	}
}

UI holds information regarding the user interface.

type World

type World struct {
	// The key for the world in the configuration file.
	Name string

	// A free-form display name for the world.
	DisplayName string `yaml:"display_name" toml:"display_name"`

	// The server to which this world belongs.
	Server string

	// The username and password to connect with.
	Username, Password string

	// Whether or not to maintain a rotated log of each connection to this world.
	Log bool
}

World represents the union between a server and a character.

func NewWorld

func NewWorld(name, displayName, srv, username, password string, logByDefault bool) *World

NewWorld returns a new world object for the given values.

Jump to

Keyboard shortcuts

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