Documentation
¶
Overview ¶
Package core holds process-wide primitives shared by every terminull app:
- signals: a context cancelled on Ctrl+C (SIGINT) and SIGTERM
- exit codes: ExitCodeError maps errors to process exit codes
- version: binary version and commit, with `go install` fallback
- log level: one shared slog.LevelVar behind --verbose/--debug
Core has no third-party dependencies and behaves identically on Linux, macOS, and Windows.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( Version = "unknown" Commit = "unknown" )
Version and Commit are set at link time via -ldflags for releases:
go build -ldflags "-X github.com/CHE3MZ/terminull/core.Version=1.2.3 -X github.com/CHE3MZ/terminull/core.Commit=abc123"
When left as "unknown" (plain `go build` / `go install`), Version falls back to the module version from the build info, else stays "unknown".
var Level = &slog.LevelVar{}
Level is the single shared slog level for the process. --verbose/--debug flip it to slog.LevelDebug via SetDebug. Apps wire it into their handler, e.g. slog.NewTextHandler(out, &slog.HandlerOptions{Level: core.Level}).
Functions ¶
func ExitCodeOf ¶
ExitCodeOf maps any error to a process exit code: the carried code for ExitCodeError (even when wrapped), 130 for a cancelled context (Ctrl+C), 1 for anything else, 0 for nil.
func FullVersion ¶
func FullVersion() string
FullVersion returns "Version-Commit" for --version output.
func SignalContext ¶
SignalContext returns a context cancelled on SIGINT (Ctrl+C) or SIGTERM. Callers must defer the returned cancel func. Works on Linux, macOS, and Windows (Go maps console Ctrl+C to SIGINT on all three).
Types ¶
type ExitCodeError ¶
type ExitCodeError struct {
// contains filtered or unexported fields
}
ExitCodeError carries a process exit code alongside the cause. Main functions map any returned error via ExitCodeOf and os.Exit.
func NewExitCodeError ¶
func NewExitCodeError(code int, err error) ExitCodeError
NewExitCodeError builds an ExitCodeError with the given code and cause.
func (ExitCodeError) ExitCode ¶
func (e ExitCodeError) ExitCode() int
ExitCode returns the process exit code.
func (ExitCodeError) Unwrap ¶
func (e ExitCodeError) Unwrap() error
Unwrap returns the cause so errors.Is/As see through it.