core

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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".

View Source
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

func ExitCodeOf(err error) int

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 SetDebug

func SetDebug(debug bool)

SetDebug enables debug logging when debug is true.

func SignalContext

func SignalContext(parent context.Context) (context.Context, context.CancelFunc)

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) Error

func (e ExitCodeError) Error() string

Error returns the cause message.

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.

Jump to

Keyboard shortcuts

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