src

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const B3TTY_CONFIG_PATH = "b3tty"
View Source
const BUFFER_SIZE = 4096
View Source
const CONFIG_FILE_NAME = "conf.yaml"
View Source
const DEFAULT_COLS = 80
View Source
const DEFAULT_PROFILE_NAME = "default"
View Source
const DEFAULT_ROWS = 24
View Source
const DOT_CONFIG_PATH = ".config"

Variables

View Source
var Profiles map[string]Profile

Functions

func Bold

func Bold(s string) string

Bold returns s wrapped in bold ANSI codes when color output is enabled, and returns s unchanged when output is piped or redirected.

func BoldGreen

func BoldGreen(s string) string

BoldGreen returns s in bold green when color output is enabled.

func Debug

func Debug(msg string)

Debug logs a debug message. Output is suppressed unless SetDebug(true) has been called.

func Debugf

func Debugf(format string, args ...any)

Debugf logs a debug message. Output is suppressed unless SetDebug(true) has been called.

func Error

func Error(msg string)

Error logs an error message.

func Errorf

func Errorf(format string, args ...any)

Errorf logs an error message.

func Fatal

func Fatal(args ...any)

Fatal logs a fatal error message and terminates the process.

func Fatalf

func Fatalf(format string, args ...any)

Fatalf logs a fatal error message and terminates the process.

func Info

func Info(msg string)

Info logs an informational message.

func Infof

func Infof(format string, args ...any)

Infof logs an informational message.

func NewWarnLogger

func NewWarnLogger() *log.Logger

NewWarnLogger returns a *log.Logger suitable for http.Server.ErrorLog. Internal HTTP/TLS messages are routed through Warnf so the timestamp and level label appear in the same order as every other log line.

func Serve

func Serve(shouldOpenBrowser bool, useTLS bool)

Serve wires up the HTTP mux and starts the server. It creates a TerminalServer from the package-level InitClient, InitServer, and Profiles variables set by the cmd layer.

func SetDebug

func SetDebug(enabled bool)

SetDebug enables or disables debug-level logging.

func ValidateConfig added in v1.3.1

func ValidateConfig(path string) error

ValidateConfig opens the YAML file at path, decodes it into typed structs with KnownFields(true) enabled, and returns a descriptive error (including the line number from the YAML parser) if any field has the wrong type or any unrecognised key is present.

func ValidateTheme

func ValidateTheme(t *Theme) error

ValidateTheme checks every color field in t against validateThemeColor. It returns an error naming the first invalid field and value, or nil when all fields are valid. Fields are identified by their JSON tag name.

func ValidateThemeColor added in v1.3.1

func ValidateThemeColor(s string) bool

validateThemeColor reports whether s is a valid theme color value. Valid values are an empty string (field not set), a CSS hex color with 3 or 6 hex digits (e.g. "#fff" or "#14181d"), or a string of only ASCII letters representing a named CSS color (e.g. "red" or "cornflowerblue").

func Warn

func Warn(msg string)

Warn logs a warning message.

func Warnf

func Warnf(format string, args ...any)

Warnf logs a warning message.

func WriteDefaultConfig added in v1.3.1

func WriteDefaultConfig(themeName string, colors map[string]any) error

WriteDefaultConfig writes a default theme config file to $HOME/.config/b3tty/conf.yaml.

Types

type CSPHeader added in v1.3.1

type CSPHeader struct {
	Name   string
	Values []string
}

func NewCSPHeader added in v1.3.1

func NewCSPHeader(name string, values ...string) *CSPHeader

func (*CSPHeader) Add added in v1.3.1

func (ch *CSPHeader) Add(value string) *CSPHeader

func (*CSPHeader) Set added in v1.3.1

func (ch *CSPHeader) Set(values ...string) *CSPHeader

func (CSPHeader) String added in v1.3.1

func (ch CSPHeader) String() string

type CSPHeaders added in v1.3.1

type CSPHeaders struct {
	Headers map[string]*CSPHeader
}

func GetCSPHeaders added in v1.3.1

func GetCSPHeaders() CSPHeaders

func NewCSPHeders added in v1.3.1

func NewCSPHeders(headers ...*CSPHeader) *CSPHeaders

func (CSPHeaders) Add added in v1.3.1

func (chs CSPHeaders) Add(key string, header *CSPHeader) *CSPHeaders

func (CSPHeaders) Get added in v1.3.1

func (chs CSPHeaders) Get(key string) *CSPHeader

func (CSPHeaders) String added in v1.3.1

func (chs CSPHeaders) String() string

type Client

type Client struct {
	Rows        int
	Columns     int
	CursorBlink bool
	FontFamily  string
	FontSize    int
	Theme       Theme
}
var InitClient *Client

func NewClient

func NewClient(rows *int, columns *int, blink *bool, fontFamily *string, fontSize *int, theme *Theme) *Client

type Profile

type Profile struct {
	Root             string
	WorkingDirectory string
	Shell            string
	Title            string
	Commands         []string
}

func NewProfile

func NewProfile(shell string, wd string, root string, title string, commands []string) Profile

func (*Profile) ApplyToCommand

func (p *Profile) ApplyToCommand(cmd *exec.Cmd) (*exec.Cmd, error)

ApplyToCommand applies the Profile's settings to the given exec.Cmd. It sets the working directory based on the Profile's WorkingDirectory field, expanding $HOME and ~ to the user's home directory. If a custom shell is specified in the Profile, it replaces the last argument of the command with the custom shell. Returns the modified exec.Cmd and any error encountered.

func (*Profile) ParseCommands

func (p *Profile) ParseCommands() ([][]string, error)

ParseCommands processes the Profile Commands and returns a slice of string slices. Each command in the Commands slice is trimmed of whitespace and split into arguments.

Returns:

  • [][]string: A slice of string slices, where each inner slice represents a parsed command with its arguments.
  • error: An error if any occurs during the parsing process, nil otherwise.

type Server

type Server struct {
	Uri      string
	Port     int
	NoAuth   bool
	FirstRun bool
	TLS
}
var InitServer *Server

func NewServer

func NewServer(uri *string, port *int, noAuth *bool, tls *TLS) *Server

func (*Server) Addr

func (s *Server) Addr() url.URL

type TLS

type TLS struct {
	Enabled      bool
	CertFilePath string
	KeyFilePath  string
}

type TermConfig

type TermConfig struct {
	TLS                bool   `json:"tls"`
	CursorBlink        bool   `json:"cursorBlink"`
	FontFamily         string `json:"fontFamily"`
	FontSize           int    `json:"fontSize"`
	Rows               int    `json:"rows"`
	Columns            int    `json:"columns"`
	Theme              Theme  `json:"theme"`
	Uri                string `json:"uri"`
	Port               int    `json:"port"`
	Debug              bool   `json:"debug"`
	HasBackgroundImage bool   `json:"backgroundImage"`
}

func NewTermConfig

func NewTermConfig(srv *Server, clnt *Client, thm *Theme) *TermConfig

type TerminalServer

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

TerminalServer bundles all mutable per-session state used by the HTTP handlers, making them independent of package-level globals and straightforward to test.

type Theme

type Theme struct {
	Foreground          string `json:"foreground,omitempty"`
	Background          string `json:"background,omitempty"`
	Cursor              string `json:"cursor,omitempty"`
	CursorAccent        string `json:"cursorAccent,omitempty"`
	SelectionForeground string `json:"selectionForeground,omitempty"`
	SelectionBackground string `json:"selectionBackground,omitempty"`
	Black               string `json:"black,omitempty"`
	BrightBlack         string `json:"brightBlack,omitempty"`
	Red                 string `json:"red,omitempty"`
	BrightRed           string `json:"brightRed,omitempty"`
	Yellow              string `json:"yellow,omitempty"`
	BrightYellow        string `json:"brightYellow,omitempty"`
	Green               string `json:"green,omitempty"`
	BrightGreen         string `json:"brightGreen,omitempty"`
	Blue                string `json:"blue,omitempty"`
	BrightBlue          string `json:"brightBlue,omitempty"`
	Magenta             string `json:"magenta,omitempty"`
	BrightMagenta       string `json:"brightMagenta,omitempty"`
	Cyan                string `json:"cyan,omitempty"`
	BrightCyan          string `json:"brightCyan,omitempty"`
	White               string `json:"white,omitempty"`
	BrightWhite         string `json:"brightWhite,omitempty"`
	// BackgroundImage is a server-side file path and is intentionally excluded
	// from JSON serialization to avoid exposing local paths to the browser.
	BackgroundImage string `json:"-"`
}

func (*Theme) MapToTheme

func (tm *Theme) MapToTheme(m map[string]any)

MapToTheme maps the key-value pairs from the given map to the corresponding fields of the Theme struct. It uses reflection to set the values of the struct fields based on the map keys. The map keys are expected to be in a format that can be converted to the struct field names. Only string values from the map are set to the corresponding struct fields.

Parameters:

  • m: A map[string]any containing the theme properties to be set.

Note: This method modifies the Theme struct in-place.

Jump to

Keyboard shortcuts

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