diff --git a/CHANGELOG.md b/CHANGELOG.md index 511933e9..14c02151 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## Changelog +### 12.124.0 + +- `[env]` Add `Variable` struct for lazy environment reading +- `[fmtc]` Add support of `FMTC_NO_BOLD`, `FMTC_NO_ITALIC`, and `FMTC_NO_BLINK` environment variables + ### 12.123.2 - `[terminal]` Fixed bug with output messages from `Error` and `Warn` to stdout instead of stderr diff --git a/README.md b/README.md index 056aece1..763c17ae 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@

-

Platform supportInstallationSub-packagesProjects with EKCI StatusContributingLicense

+

Platform supportSub-packagesProjects with EKCI StatusContributingLicense


@@ -24,129 +24,115 @@ Currently we support Linux and macOS (_except some packages_). All packages have > [!NOTE] > Some packages cannot be used on some platforms, such as the `fsutil` package, which cannot be used on Windows because it uses syscalls, or `system` subpackages that require [procfs](https://en.wikipedia.org/wiki/Procfs). But you can still write code on these platforms, because almost all packages have stubs with information about all the constants, variables, and functions available on other platforms. For example, Sublime with [LSP](https://lsp.sublimetext.io) on Windows will show all the information about methods that are only available on the Linux platform. All stub descriptions contain the ❗ symbol at the beginning to indicate unsupported code. Code with stubs can be compiled, but any method call from stubs will cause panic. -### Installation - -Make sure you have a working Go 1.20+ workspace (_[instructions](https://go.dev/doc/install)_), then: - -``` -go get github.com/essentialkaos/ek/v12 -``` - -If you want to update `ek` to latest stable release, do: - -``` -go get -u github.com/essentialkaos/ek/v12 -``` - > [!TIP] > If you are using SublimeText 4 (`4075+`), we strongly recommend that you install [extended Go syntax highlighting](https://github.com/essentialkaos/blackhole-theme-sublime/blob/master/fmtc.sublime-syntax) with support for `fmtc` [tags](fmtc). ### Sub-packages -* [`ansi`](https://kaos.sh/g/ek.v12/ansi) — Package provides methods for working with ANSI/VT100 control sequences -* [`cache`](https://kaos.sh/g/ek.v12/cache) — Package provides a simple in-memory key:value cache -* [`color`](https://kaos.sh/g/ek.v12/color) — Package provides methods for working with colors -* [`cron`](https://kaos.sh/g/ek.v12/cron) — Package provides methods for working with cron expressions -* [`csv`](https://kaos.sh/g/ek.v12/csv) — Package with simple (without any checks) CSV parser compatible with default Go parser -* [`easing`](https://kaos.sh/g/ek.v12/easing) — Package with easing functions (Back, Bounce, Circ, Cubic, Elastic, Expo, Linear, Quad, Quint, Sine) -* [`emoji`](https://kaos.sh/g/ek.v12/emoji) — Package provides methods for working with emojis -* [`env`](https://kaos.sh/g/ek.v12/env) — Package provides methods for working with environment variables -* [`errutil`](https://kaos.sh/g/ek.v12/errutil) — Package provides methods for working with errors -* [`events`](https://kaos.sh/g/ek.v12/events) — Package provides methods and structs for creating event-driven systems -* [`directio`](https://kaos.sh/g/ek.v12/directio) — Package provides methods for reading/writing files with direct io -* [`fmtc`](https://kaos.sh/g/ek.v12/fmtc) — Package provides methods similar to fmt for colored output -* [`fmtutil`](https://kaos.sh/g/ek.v12/fmtutil) — Package provides methods for output formatting -* [`fmtutil/barcode`](https://kaos.sh/g/ek.v12/fmtutil/barcode) — Package provides methods to generate colored representation of unique data -* [`fmtutil/panel`](https://kaos.sh/g/ek.v12/fmtutil/panel) — Package contains methods for rendering panels with text -* [`fmtutil/table`](https://kaos.sh/g/ek.v12/fmtutil/table) — Package contains methods and structs for rendering data in tabular format -* [`fsutil`](https://kaos.sh/g/ek.v12/fsutil) — Package provides methods for working with files on POSIX compatible systems (BSD/Linux/macOS) -* [`hash`](https://kaos.sh/g/ek.v12/hash) — Package hash contains different hash algorithms and utilities -* [`httputil`](https://kaos.sh/g/ek.v12/httputil) — Package provides methods for working with HTTP request/responses -* [`initsystem`](https://kaos.sh/g/ek.v12/initsystem) — Package provides methods for working with different init systems (sysv, upstart, systemd) -* [`initsystem/sdnotify`](https://kaos.sh/g/ek.v12/initsystem/sdnotify) — Package provides methods methods for sending [notifications to systemd](https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html#Well-known%20assignments) -* [`jsonutil`](https://kaos.sh/g/ek.v12/jsonutil) — Package provides methods for working with JSON data -* [`knf`](https://kaos.sh/g/ek.v12/knf) — Package provides methods for working with configuration files in [KNF format](https://kaos.sh/knf-spec) -* [`knf/united`](https://kaos.sh/g/ek.v12/knf/united) — Package provides united configuration (_knf + options + environment variables_) -* [`log`](https://kaos.sh/g/ek.v12/log) — Package with an improved logger -* [`lock`](https://kaos.sh/g/ek.v12/lock) — Package provides methods for working with lock files -* [`lscolors`](https://kaos.sh/g/ek.v12/lscolors) — Package provides methods for colorizing file names based on colors from dircolors -* [`mathutil`](https://kaos.sh/g/ek.v12/mathutil) — Package provides some additional math methods -* [`netutil`](https://kaos.sh/g/ek.v12/netutil) — Package provides methods for working with network -* [`options`](https://kaos.sh/g/ek.v12/options) — Package provides methods for working with command-line options -* [`pager`](https://kaos.sh/g/ek.v12/pager) — Package provides methods for pager setup (more/less) -* [`passthru`](https://kaos.sh/g/ek.v12/passthru) — Package provides Reader and Writer with information about the amount of data being passed -* [`passwd`](https://kaos.sh/g/ek.v12/passwd) — Package contains methods for working with passwords -* [`path`](https://kaos.sh/g/ek.v12/path) — Package for working with paths (fully compatible with base path package) -* [`pid`](https://kaos.sh/g/ek.v12/pid) — Package for working with PID files -* [`pluralize`](https://kaos.sh/g/ek.v12/pluralize) — Package provides methods for pluralization -* [`progress`](https://kaos.sh/g/ek.v12/progress) — Package provides methods and structs for creating terminal progress bar -* [`protip`](https://kaos.sh/g/ek.v12/protip) — Package for displaying usage tips -* [`rand`](https://kaos.sh/g/ek.v12/rand) — Package for generating random data -* [`req`](https://kaos.sh/g/ek.v12/req) — Package simplify working with an HTTP requests -* [`secstr`](https://kaos.sh/g/ek.v12/secstr) — Package provides methods and structs for working with protected (secure) strings -* [`signal`](https://kaos.sh/g/ek.v12/signal) — Package provides methods for handling POSIX signals -* [`sliceutil`](https://kaos.sh/g/ek.v12/sliceutil) — Package provides methods for working with slices -* [`sortutil`](https://kaos.sh/g/ek.v12/sortutil) — Package provides methods for sorting slices -* [`spellcheck`](https://kaos.sh/g/ek.v12/spellcheck) — Package provides spellcheck based on Damerau–Levenshtein distance algorithm -* [`spinner`](https://kaos.sh/g/ek.v12/spinner) — Package provides methods for creating spinner animation for long-running tasks -* [`strutil`](https://kaos.sh/g/ek.v12/strutil) — Package provides methods for working with strings -* [`support`](https://kaos.sh/g/ek.v12/support) — Package provides methods for collecting and printing support information about system -* [`system/container`](https://kaos.sh/g/ek.v12/system/container) — Package provides methods for checking container engine info -* [`system/exec`](https://kaos.sh/g/ek.v12/system/exec) — Package provides methods for executing commands -* [`system/process`](https://kaos.sh/g/ek.v12/system/process) — Package provides methods for gathering information about active processes -* [`system/procname`](https://kaos.sh/g/ek.v12/system/procname) — Package provides methods for changing process name in the process tree -* [`system/sensors`](https://kaos.sh/g/ek.v12/system/sensors) — Package provide methods for collecting sensors information -* [`system`](https://kaos.sh/g/ek.v12/system) — Package provides methods for working with system data (metrics/users) -* [`terminal`](https://kaos.sh/g/ek.v12/terminal) — Package provides methods for printing messages to terminal -* [`terminal/input`](https://kaos.sh/g/ek.v12/terminal/input) — Package provides methods for working with user input -* [`terminal/tty`](https://kaos.sh/g/ek.v12/terminal/tty) — Package provides methods for working with TTY -* [`timeutil`](https://kaos.sh/g/ek.v12/timeutil) — Package provides methods for working with time and date -* [`tmp`](https://kaos.sh/g/ek.v12/tmp) — Package provides methods for working with temporary data -* [`usage`](https://kaos.sh/g/ek.v12/usage) — Package usage provides methods and structs for generating usage info for command-line tools -* [`usage/update`](https://kaos.sh/g/ek.v12/usage/update) — Package contains update checkers for different services -* [`usage/completion/bash`](https://kaos.sh/g/ek.v12/usage/completion/bash) — Package provides methods for generating bash completion -* [`usage/completion/fish`](https://kaos.sh/g/ek.v12/usage/completion/fish) — Package provides methods for generating fish completion -* [`usage/completion/zsh`](https://kaos.sh/g/ek.v12/usage/completion/zsh) — Package provides methods for generating zsh completion -* [`uuid`](https://kaos.sh/g/ek.v12/uuid) — Package provides methods for generating version 4 and 5 UUID's -* [`version`](https://kaos.sh/g/ek.v12/version) — Package version provides methods for working with semver version info +- [`ansi`](https://kaos.sh/g/ek.v12/ansi) — Package provides methods for working with ANSI/VT100 control sequences +- [`cache`](https://kaos.sh/g/ek.v12/cache) — Package provides a simple in-memory key/value cache +- [`color`](https://kaos.sh/g/ek.v12/color) — Package provides methods for working with colors +- [`cron`](https://kaos.sh/g/ek.v12/cron) — Package provides methods for working with cron expressions +- [`csv`](https://kaos.sh/g/ek.v12/csv) — Package with simple CSV parser compatible with default Go parser +- [`easing`](https://kaos.sh/g/ek.v12/easing) — Package with easing functions (_Back, Bounce, Circ, Cubic, Elastic, Expo, Linear, Quad, Quint, Sine_) +- [`emoji`](https://kaos.sh/g/ek.v12/emoji) — Package provides methods for working with emojis +- [`env`](https://kaos.sh/g/ek.v12/env) — Package provides methods for working with environment variables +- [`errutil`](https://kaos.sh/g/ek.v12/errutil) — Package provides methods for working with errors +- [`events`](https://kaos.sh/g/ek.v12/events) — Package provides methods and structs for creating event-driven systems +- [`directio`](https://kaos.sh/g/ek.v12/directio) — Package provides methods for reading/writing files with direct io +- [`fmtc`](https://kaos.sh/g/ek.v12/fmtc) — Package provides methods similar to fmt for colored output ([_more info and examples_](fmtc/README.md)) +- [`fmtutil`](https://kaos.sh/g/ek.v12/fmtutil) — Package provides methods for output formatting +- [`fmtutil/barcode`](https://kaos.sh/g/ek.v12/fmtutil/barcode) — Package provides methods to generate colored representation of unique data +- [`fmtutil/panel`](https://kaos.sh/g/ek.v12/fmtutil/panel) — Package contains methods for rendering panels with text +- [`fmtutil/table`](https://kaos.sh/g/ek.v12/fmtutil/table) — Package contains methods and structs for rendering data in tabular format +- [`fsutil`](https://kaos.sh/g/ek.v12/fsutil) — Package provides methods for working with files on POSIX compatible systems (_BSD/Linux/macOS_) +- [`hash`](https://kaos.sh/g/ek.v12/hash) — Package hash contains different hash algorithms and utilities +- [`httputil`](https://kaos.sh/g/ek.v12/httputil) — Package provides methods for working with HTTP request/responses +- [`initsystem`](https://kaos.sh/g/ek.v12/initsystem) — Package provides methods for working with different init systems (_sysv, upstart, systemd_) +- [`initsystem/sdnotify`](https://kaos.sh/g/ek.v12/initsystem/sdnotify) — Package provides methods methods for sending [notifications to systemd](https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html#Well-known%20assignments) +- [`jsonutil`](https://kaos.sh/g/ek.v12/jsonutil) — Package provides methods for working with JSON data +- [`knf`](https://kaos.sh/g/ek.v12/knf) — Package provides methods for working with configuration files in [KNF format](https://kaos.sh/knf-spec) +- [`knf/united`](https://kaos.sh/g/ek.v12/knf/united) — Package provides united configuration (_knf + options + environment variables_) +- [`log`](https://kaos.sh/g/ek.v12/log) — Package with an improved logger +- [`lock`](https://kaos.sh/g/ek.v12/lock) — Package provides methods for working with lock files +- [`lscolors`](https://kaos.sh/g/ek.v12/lscolors) — Package provides methods for colorizing file names based on colors from dircolors +- [`mathutil`](https://kaos.sh/g/ek.v12/mathutil) — Package provides some additional math methods +- [`netutil`](https://kaos.sh/g/ek.v12/netutil) — Package provides methods for working with network +- [`options`](https://kaos.sh/g/ek.v12/options) — Package provides methods for working with command-line options +- [`pager`](https://kaos.sh/g/ek.v12/pager) — Package provides methods for pager setup (_like_ `more`/`less`) +- [`passthru`](https://kaos.sh/g/ek.v12/passthru) — Package provides Reader and Writer with information about the amount of data being passed +- [`passwd`](https://kaos.sh/g/ek.v12/passwd) — Package contains methods for working with passwords +- [`path`](https://kaos.sh/g/ek.v12/path) — Package for working with paths (_fully compatible with base path package_) +- [`pid`](https://kaos.sh/g/ek.v12/pid) — Package for working with PID files +- [`pluralize`](https://kaos.sh/g/ek.v12/pluralize) — Package provides methods for pluralization +- [`progress`](https://kaos.sh/g/ek.v12/progress) — Package provides methods and structs for creating terminal progress bar +- [`protip`](https://kaos.sh/g/ek.v12/protip) — Package for displaying usage tips +- [`rand`](https://kaos.sh/g/ek.v12/rand) — Package for generating random data +- [`req`](https://kaos.sh/g/ek.v12/req) — Package simplify working with an HTTP requests +- [`secstr`](https://kaos.sh/g/ek.v12/secstr) — Package provides methods and structs for working with protected (_secure_) strings +- [`signal`](https://kaos.sh/g/ek.v12/signal) — Package provides methods for handling POSIX signals +- [`sliceutil`](https://kaos.sh/g/ek.v12/sliceutil) — Package provides methods for working with slices +- [`sortutil`](https://kaos.sh/g/ek.v12/sortutil) — Package provides methods for sorting slices +- [`spellcheck`](https://kaos.sh/g/ek.v12/spellcheck) — Package provides spellcheck based on Damerau–Levenshtein distance algorithm +- [`spinner`](https://kaos.sh/g/ek.v12/spinner) — Package provides methods for creating spinner animation for long-running tasks +- [`strutil`](https://kaos.sh/g/ek.v12/strutil) — Package provides methods for working with strings +- [`support`](https://kaos.sh/g/ek.v12/support) — Package provides methods for collecting and printing support information about system +- [`system/container`](https://kaos.sh/g/ek.v12/system/container) — Package provides methods for checking container engine info +- [`system/exec`](https://kaos.sh/g/ek.v12/system/exec) — Package provides methods for executing commands +- [`system/process`](https://kaos.sh/g/ek.v12/system/process) — Package provides methods for gathering information about active processes +- [`system/procname`](https://kaos.sh/g/ek.v12/system/procname) — Package provides methods for changing process name in the process tree +- [`system/sensors`](https://kaos.sh/g/ek.v12/system/sensors) — Package provide methods for collecting sensors information +- [`system`](https://kaos.sh/g/ek.v12/system) — Package provides methods for working with system data (_system metrics/users_) +- [`terminal`](https://kaos.sh/g/ek.v12/terminal) — Package provides methods for printing messages to terminal +- [`terminal/input`](https://kaos.sh/g/ek.v12/terminal/input) — Package provides methods for working with user input +- [`terminal/tty`](https://kaos.sh/g/ek.v12/terminal/tty) — Package provides methods for working with TTY +- [`timeutil`](https://kaos.sh/g/ek.v12/timeutil) — Package provides methods for working with time and date +- [`tmp`](https://kaos.sh/g/ek.v12/tmp) — Package provides methods for working with temporary data +- [`usage`](https://kaos.sh/g/ek.v12/usage) — Package usage provides methods and structs for generating usage info for command-line tools +- [`usage/update`](https://kaos.sh/g/ek.v12/usage/update) — Package contains update checkers for different services +- [`usage/completion/bash`](https://kaos.sh/g/ek.v12/usage/completion/bash) — Package provides methods for generating bash completion +- [`usage/completion/fish`](https://kaos.sh/g/ek.v12/usage/completion/fish) — Package provides methods for generating fish completion +- [`usage/completion/zsh`](https://kaos.sh/g/ek.v12/usage/completion/zsh) — Package provides methods for generating zsh completion +- [`uuid`](https://kaos.sh/g/ek.v12/uuid) — Package provides methods for generating version 4 and 5 UUID's +- [`version`](https://kaos.sh/g/ek.v12/version) — Package version provides methods for working with semver version info ### Projects with `EK` -* [aligo](https://kaos.sh/aligo) — Utility for checking and viewing Golang struct alignment info -* [artefactor](https://kaos.sh/artefactor) — Utility for downloading artefacts from GitHub -* [atlassian-cloud-backuper](https://kaos.sh/atlassian-cloud-backuper) — Tool for backuping Atlassian cloud services (_Jira and Confluence_) -* [Bastion](https://kaos.sh/bastion) — Utility for temporary disabling access to server -* [bibop](https://kaos.sh/bibop) — Utility for testing command-line tools -* [bop](https://kaos.sh/bop) — Utility for generating bibop tests for RPM packages -* [Deadline](https://kaos.sh/deadline) — Simple utility for controlling application working time -* [fz](https://kaos.sh/fz) — Simple tool for formatting `go-fuzz` output -* [GoHeft](https://kaos.sh/goheft) — Utility for listing sizes of all used static libraries compiled into golang binary -* [GoMakeGen](https://kaos.sh/gomakegen) — Utility for generating makefiles for golang applications -* [icecli](https://kaos.sh/icecli) — Command-line tools for Icecast -* [IMC](https://kaos.sh/imc) — Simple terminal dashboard for Icecast -* [init-exporter](https://github.com/funbox/init-exporter) — Utility for exporting services described by Procfile to init system -* [jira-reindex-runner](https://kaos.sh/jira-reindex-runner) — Application for periodical running Jira re-index process -* [knf](https://kaos.sh/knf) — Simple utility for reading values from KNF files -* [MDToc](https://kaos.sh/mdtoc) — Utility for generating table of contents for markdown files -* [path](https://kaos.sh/path) — Dead simple tool for working with paths -* [perfecto](https://kaos.sh/perfecto) — Tool for checking perfectly written RPM specs -* [RBInstall](https://kaos.sh/rbinstall) — Utility for installing prebuilt ruby to RBEnv -* [RDS](https://kaos.sh/rds) — Tool for Redis orchestration -* [Redis CLI Monitor](https://kaos.sh/redis-cli-monitor) — Tiny redis client for renamed MONITOR commands -* [Redis Latency Monitor](https://kaos.sh/redis-latency-monitor) — Tiny Redis client for latency measurement -* [Redis Monitor Top](https://kaos.sh/redis-monitor-top) — Tiny Redis client for aggregating stats from MONITOR flow -* [rep](https://kaos.sh/rep) — YUM repository management utility -* [rsz](https://kaos.sh/rsz) — Simple utility for image resizing -* [scratch](https://kaos.sh/scratch) — Simple utility for generating blank files for Go apps, utilities and packages -* [SHDoc](https://kaos.sh/shdoc) — Tool for viewing and exporting docs for shell scripts -* [Sonar](https://kaos.sh/sonar) — Utility for showing user Slack status in Atlassian Jira -* [SourceIndex](https://kaos.sh/source-index) — Utility for generating an index for source archives -* [SSLScan Client](https://kaos.sh/sslcli) — Pretty awesome command-line client for public SSLLabs API -* [subdy](https://kaos.sh/subdy) — CLI for subdomain.center API -* [swptop](https://kaos.sh/swptop) — Simple utility for viewing swap consumption of processes -* [uc](https://kaos.sh/uc) — Simple utility for counting unique lines -* [updown-badge-server](https://kaos.sh/updown-badge-server) — Service for generating badges for updown.io checks -* [yo](https://kaos.sh/yo) — Command-line YAML processor +- [aligo](https://kaos.sh/aligo) — Utility for checking and viewing Golang struct alignment info +- [artefactor](https://kaos.sh/artefactor) — Utility for downloading artefacts from GitHub +- [atlassian-cloud-backuper](https://kaos.sh/atlassian-cloud-backuper) — Tool for backuping Atlassian cloud services (_Jira and Confluence_) +- [Bastion](https://kaos.sh/bastion) — Utility for temporary disabling access to server +- [bibop](https://kaos.sh/bibop) — Utility for testing command-line tools +- [bop](https://kaos.sh/bop) — Utility for generating bibop tests for RPM packages +- [Deadline](https://kaos.sh/deadline) — Simple utility for controlling application working time +- [fz](https://kaos.sh/fz) — Simple tool for formatting `go-fuzz` output +- [GoHeft](https://kaos.sh/goheft) — Utility for listing sizes of all used static libraries compiled into golang binary +- [GoMakeGen](https://kaos.sh/gomakegen) — Utility for generating makefiles for golang applications +- [icecli](https://kaos.sh/icecli) — Command-line tools for Icecast +- [IMC](https://kaos.sh/imc) — Simple terminal dashboard for Icecast +- [init-exporter](https://github.com/funbox/init-exporter) — Utility for exporting services described by Procfile to init system +- [jira-reindex-runner](https://kaos.sh/jira-reindex-runner) — Application for periodical running Jira re-index process +- [knf](https://kaos.sh/knf) — Simple utility for reading values from KNF files +- [MDToc](https://kaos.sh/mdtoc) — Utility for generating table of contents for markdown files +- [path](https://kaos.sh/path) — Dead simple tool for working with paths +- [perfecto](https://kaos.sh/perfecto) — Tool for checking perfectly written RPM specs +- [RBInstall](https://kaos.sh/rbinstall) — Utility for installing prebuilt ruby to RBEnv +- [RDS](https://kaos.sh/rds) — Tool for Redis orchestration +- [Redis CLI Monitor](https://kaos.sh/redis-cli-monitor) — Tiny redis client for renamed MONITOR commands +- [Redis Latency Monitor](https://kaos.sh/redis-latency-monitor) — Tiny Redis client for latency measurement +- [Redis Monitor Top](https://kaos.sh/redis-monitor-top) — Tiny Redis client for aggregating stats from MONITOR flow +- [rep](https://kaos.sh/rep) — YUM repository management utility +- [rsz](https://kaos.sh/rsz) — Simple utility for image resizing +- [scratch](https://kaos.sh/scratch) — Simple utility for generating blank files for Go apps, utilities and packages +- [SHDoc](https://kaos.sh/shdoc) — Tool for viewing and exporting docs for shell scripts +- [Sonar](https://kaos.sh/sonar) — Utility for showing user Slack status in Atlassian Jira +- [SourceIndex](https://kaos.sh/source-index) — Utility for generating an index for source archives +- [SSLScan Client](https://kaos.sh/sslcli) — Pretty awesome command-line client for public SSLLabs API +- [subdy](https://kaos.sh/subdy) — CLI for subdomain.center API +- [swptop](https://kaos.sh/swptop) — Simple utility for viewing swap consumption of processes +- [uc](https://kaos.sh/uc) — Simple utility for counting unique lines +- [updown-badge-server](https://kaos.sh/updown-badge-server) — Service for generating badges for updown.io checks +- [yo](https://kaos.sh/yo) — Command-line YAML processor ### CI Status diff --git a/ek.go b/ek.go index 6b9a176a..67d3fbf0 100644 --- a/ek.go +++ b/ek.go @@ -21,7 +21,7 @@ import ( // ////////////////////////////////////////////////////////////////////////////////// // // VERSION is current ek package version -const VERSION = "12.123.1" +const VERSION = "12.124.0" // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/env/env.go b/env/env.go index d76e3dfa..a302a441 100644 --- a/env/env.go +++ b/env/env.go @@ -23,8 +23,20 @@ import ( // Env is map with environment values type Env map[string]string +// Variable is environment variable for lazy reading +type Variable struct { + key string + value string + isRead bool +} + // ////////////////////////////////////////////////////////////////////////////////// // +// Var creates new environment variable struct +func Var(name string) *Variable { + return &Variable{key: name} +} + // Get return key-value map with environment values func Get() Env { env := make(Env) @@ -54,6 +66,43 @@ func Which(name string) string { // ////////////////////////////////////////////////////////////////////////////////// // +// Get returns environment variable value +func (v *Variable) Get() string { + if v == nil { + return "" + } + + if !v.isRead { + v.value = os.Getenv(v.key) + v.isRead = true + } + + return v.value +} + +// Is returns true if environment variable value is equal to given one +func (v *Variable) Is(value string) bool { + return v.Get() == value +} + +// String returns environment variable value as string +func (v *Variable) String() string { + return v.Get() +} + +// Reset resets reading state of variable +func (v *Variable) Reset() *Variable { + if v == nil { + return nil + } + + v.value, v.isRead = "", false + + return v +} + +// ////////////////////////////////////////////////////////////////////////////////// // + // Path return path as string slice func (e Env) Path() []string { return strings.Split(e["PATH"], ":") diff --git a/env/env_test.go b/env/env_test.go index 58452f80..303cb3ba 100644 --- a/env/env_test.go +++ b/env/env_test.go @@ -8,6 +8,7 @@ package env // ////////////////////////////////////////////////////////////////////////////////// // import ( + "os" "testing" . "github.com/essentialkaos/check" @@ -28,6 +29,10 @@ var _ = Suite(&ENVSuite{}) // ////////////////////////////////////////////////////////////////////////////////// // func (s *ENVSuite) TestEnv(c *C) { + if os.Getenv("EK_TEST_PORT") == "" { + os.Setenv("EK_TEST_PORT", "8080") + } + envs := Get() c.Assert(envs["EK_TEST_PORT"], Equals, "8080") @@ -42,4 +47,17 @@ func (s *ENVSuite) TestEnv(c *C) { c.Assert(Which("cat"), Not(Equals), "") c.Assert(Which("catABCD1234"), Equals, "") + + var v *Variable + + c.Assert(v.Get(), Equals, "") + c.Assert(v.String(), Equals, "") + c.Assert(v.Reset(), IsNil) + + v = Var("EK_TEST_PORT") + + c.Assert(v.Get(), Equals, "8080") + c.Assert(v.String(), Equals, "8080") + c.Assert(v.Is("8080"), Equals, true) + c.Assert(v.Reset(), NotNil) } diff --git a/env/env_windows.go b/env/env_windows.go index 8ef60f88..66b85f4f 100644 --- a/env/env_windows.go +++ b/env/env_windows.go @@ -11,18 +11,50 @@ package env // ❗ Env is map with environment values type Env map[string]string +// ❗ Variable is environment variable for lazy reading +type Variable struct { + key string + value string + isRead bool +} + // ////////////////////////////////////////////////////////////////////////////////// // +// ❗ Var creates new environment variable struct +func Var(name string) *Variable { + panic("UNSUPPORTED") +} + // ❗ Get return key-value map with environment values func Get() Env { panic("UNSUPPORTED") - return Env{} } // ❗ Which find full path to some app func Which(name string) string { panic("UNSUPPORTED") - return "" +} + +// ////////////////////////////////////////////////////////////////////////////////// // + +// ❗ Get returns environment variable value +func (v *Variable) Get() string { + panic("UNSUPPORTED") +} + +// ❗ Is returns true if environment variable value is equal to given one +func (v *Variable) Is(value string) bool { + panic("UNSUPPORTED") +} + +// ❗ String returns environment variable value as string +func (v *Variable) String() string { + panic("UNSUPPORTED") +} + +// ❗ Reset resets reading state of variable +func (v *Variable) Reset() *Variable { + panic("UNSUPPORTED") } // ////////////////////////////////////////////////////////////////////////////////// // @@ -30,23 +62,19 @@ func Which(name string) string { // ❗ Path return path as string slice func (e Env) Path() []string { panic("UNSUPPORTED") - return nil } // ❗ GetS return environment variable value as string func (e Env) GetS(name string) string { panic("UNSUPPORTED") - return "" } // ❗ GetI return environment variable value as int func (e Env) GetI(name string) int { panic("UNSUPPORTED") - return 0 } // ❗ GetF return environment variable value as float func (e Env) GetF(name string) float64 { panic("UNSUPPORTED") - return 0.0 } diff --git a/env/example_test.go b/env/example_test.go index 226e1bcb..a478a660 100644 --- a/env/example_test.go +++ b/env/example_test.go @@ -35,3 +35,9 @@ func ExampleWhich() { fmt.Printf("Full path to echo binary is %s\n", echoPath) } + +func ExampleVar() { + v := Var("PATH") + + fmt.Println(v.Get()) +} diff --git a/fmtc/README.md b/fmtc/README.md index 97debbaa..9e231147 100644 --- a/fmtc/README.md +++ b/fmtc/README.md @@ -6,6 +6,15 @@ If you are using SublimeText 4 (`4075+`), we strongly recommend that you install ![#colors](../.github/images/fmtc_highlight.png) +#### Environment variables + +`fmtc` supports configuration via environment variables. + +- `NO_COLOR` — disable all colors and modificators; +- `FMTC_NO_BOLD` — disable **bold** text; +- `FMTC_NO_ITALIC` — disable _italic_ text; +- `FMTC_NO_BLINK` — disable blinking text. + #### Modificators | Name | Tag | Reset Tag | Code | diff --git a/fmtc/fmtc.go b/fmtc/fmtc.go index dccf40d1..298a2d42 100644 --- a/fmtc/fmtc.go +++ b/fmtc/fmtc.go @@ -19,6 +19,7 @@ import ( "sync" "github.com/essentialkaos/ek/v12/color" + "github.com/essentialkaos/ek/v12/env" ) // ////////////////////////////////////////////////////////////////////////////////// // @@ -75,15 +76,19 @@ var DisableColors = os.Getenv("NO_COLOR") != "" // ////////////////////////////////////////////////////////////////////////////////// // -var colorsSupported bool // 16 colors support -var colors256Supported bool // 256 colors support -var colorsTCSupported bool // 24bit (TrueColor) colors support -var colorsSupportChecked bool +var isColorsSupported bool // 16 colors support +var isColors256Supported bool // 256 colors support +var isColorsTCSupported bool // 24bit (TrueColor) colors support +var isColorsSupportChecked bool + +var boldDisableEnvVar = env.Var("FMTC_NO_BOLD") +var italicDisableEnvVar = env.Var("FMTC_NO_ITALIC") +var blinkDisableEnvVar = env.Var("FMTC_NO_BLINK") var colorsMap *sync.Map -var term = os.Getenv("TERM") -var colorTerm = os.Getenv("COLORTERM") +var termEnvVar = env.Var("TERM") +var colorTermEnvVar = env.Var("COLORTERM") // ////////////////////////////////////////////////////////////////////////////////// // @@ -329,35 +334,35 @@ func Bell() { // IsColorsSupported returns true if 16 colors is supported by terminal func IsColorsSupported() bool { - if colorsSupportChecked { - return colorsSupported + if isColorsSupportChecked { + return isColorsSupported } checkForColorsSupport() - return colorsSupported + return isColorsSupported } // Is256ColorsSupported returns true if 256 colors is supported by terminal func Is256ColorsSupported() bool { - if colorsSupportChecked { - return colors256Supported + if isColorsSupportChecked { + return isColors256Supported } checkForColorsSupport() - return colors256Supported + return isColors256Supported } // IsTrueColorSupported returns true if TrueColor (24-bit colors) is supported by terminal func IsTrueColorSupported() bool { - if colorsSupportChecked { - return colorsTCSupported + if isColorsSupportChecked { + return isColorsTCSupported } checkForColorsSupport() - return colorsTCSupported + return isColorsTCSupported } // IsTag tests whether the given value is a valid color tag (or sequence @@ -394,6 +399,13 @@ func tag2ANSI(tag string, clean bool) string { var chars string for _, key := range tag { + switch { + case key == '*' && !boldDisableEnvVar.Is(""), + key == '&' && !italicDisableEnvVar.Is(""), + key == '~' && !blinkDisableEnvVar.Is(""): + continue + } + code := codes[key] switch { @@ -654,24 +666,27 @@ func isValidNamedTag(tag string) bool { } func checkForColorsSupport() { + term := termEnvVar.Get() + colorTerm := colorTermEnvVar.Get() + switch { case strings.Contains(term, "xterm"), strings.Contains(term, "color"), term == "screen": - colorsSupported = true + isColorsSupported = true } if strings.Contains(term, "256color") { - colors256Supported = true + isColors256Supported = true } if term == "iterm" || colorTerm == "truecolor" || strings.Contains(term, "truecolor") || strings.HasPrefix(term, "vte") { - colors256Supported, colorsTCSupported = true, true + isColors256Supported, isColorsTCSupported = true, true } - colorsSupportChecked = true + isColorsSupportChecked = true } // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/fmtc/fmtc_test.go b/fmtc/fmtc_test.go index 6a25f43a..136b638f 100644 --- a/fmtc/fmtc_test.go +++ b/fmtc/fmtc_test.go @@ -13,6 +13,8 @@ import ( "os" "testing" + "github.com/essentialkaos/ek/v12/env" + . "github.com/essentialkaos/check" ) @@ -109,26 +111,38 @@ func (s *FormatSuite) TestIsTag(c *C) { } func (s *FormatSuite) Test256Colors(c *C) { - term = "xterm-256color" - colorTerm = "" + origTerm := os.Getenv("TERM") + origColorTerm := os.Getenv("COLORTERM") + + os.Setenv("TERM", "xterm-256color") + os.Setenv("COLORTERM", "") + termEnvVar = env.Var("TERM") + colorTermEnvVar = env.Var("COLORTERM") - colorsSupportChecked = false + isColorsSupportChecked = false + isColors256Supported = false + isColorsTCSupported = false c.Assert(Is256ColorsSupported(), Equals, true) c.Assert(IsTrueColorSupported(), Equals, false) - colorsSupportChecked = false - colors256Supported = false - colorsTCSupported = false - term = "" - colorTerm = "" + isColorsSupportChecked = false + isColors256Supported = false + isColorsTCSupported = false + + os.Setenv("TERM", "") + os.Setenv("COLORTERM", "") + termEnvVar = env.Var("TERM") + colorTermEnvVar = env.Var("COLORTERM") c.Assert(Is256ColorsSupported(), Equals, false) c.Assert(Is256ColorsSupported(), Equals, false) c.Assert(IsTrueColorSupported(), Equals, false) - term = os.Getenv("TERM") - colorTerm = os.Getenv("COLORTERM") + os.Setenv("TERM", origTerm) + os.Setenv("COLORTERM", origColorTerm) + termEnvVar = env.Var("TERM") + colorTermEnvVar = env.Var("COLORTERM") c.Assert(Sprint("{#214}o{!}"), Equals, "\x1b[38;5;214mo\x1b[0m") c.Assert(Sprint("{%214}O{!}"), Equals, "\x1b[48;5;214mO\x1b[0m") @@ -139,29 +153,41 @@ func (s *FormatSuite) Test256Colors(c *C) { } func (s *FormatSuite) Test24BitColors(c *C) { - term = "xterm-256color" - colorTerm = "truecolor" + origTerm := os.Getenv("TERM") + origColorTerm := os.Getenv("COLORTERM") - colorsSupportChecked = false + os.Setenv("TERM", "xterm-256color") + os.Setenv("COLORTERM", "truecolor") + termEnvVar = env.Var("TERM") + colorTermEnvVar = env.Var("COLORTERM") + + isColorsSupportChecked = false + isColors256Supported = false + isColorsTCSupported = false c.Assert(IsTrueColorSupported(), Equals, true) - colorsSupportChecked = false + isColorsSupportChecked = false c.Assert(Is256ColorsSupported(), Equals, true) - colorsSupportChecked = false + isColorsSupportChecked = false c.Assert(IsColorsSupported(), Equals, true) c.Assert(IsColorsSupported(), Equals, true) - colorsSupportChecked = false - colors256Supported = false - colorsTCSupported = false - term = "" - colorTerm = "" + os.Setenv("TERM", "") + os.Setenv("COLORTERM", "") + termEnvVar = env.Var("TERM") + colorTermEnvVar = env.Var("COLORTERM") + + isColorsSupportChecked = false + isColors256Supported = false + isColorsTCSupported = false c.Assert(IsTrueColorSupported(), Equals, false) c.Assert(IsTrueColorSupported(), Equals, false) - term = os.Getenv("TERM") - colorTerm = os.Getenv("COLORTERM") + os.Setenv("TERM", origTerm) + os.Setenv("COLORTERM", origColorTerm) + termEnvVar = env.Var("TERM") + colorTermEnvVar = env.Var("COLORTERM") c.Assert(Sprint("{#f1c1b2}o{!}"), Equals, "\x1b[38;2;241;193;178mo\x1b[0m") c.Assert(Sprint("{%1F2E3D}O{!}"), Equals, "\x1b[48;2;31;46;61mO\x1b[0m") @@ -171,6 +197,22 @@ func (s *FormatSuite) Test24BitColors(c *C) { c.Assert(Sprint("{#-1}o"), Equals, "{#-1}o") } +func (s *FormatSuite) TestModDisable(c *C) { + os.Setenv("FMTC_FLAG", "1") + + boldDisableEnvVar = env.Var("FMTC_FLAG") + italicDisableEnvVar = env.Var("FMTC_FLAG") + blinkDisableEnvVar = env.Var("FMTC_FLAG") + + c.Assert(Sprint("{*}test{!}"), Equals, "test\x1b[0m") + c.Assert(Sprint("{&}test{!}"), Equals, "test\x1b[0m") + c.Assert(Sprint("{~}test{!}"), Equals, "test\x1b[0m") + + boldDisableEnvVar = env.Var("FMTC_NO_BOLD") + italicDisableEnvVar = env.Var("FMTC_NO_ITALIC") + blinkDisableEnvVar = env.Var("FMTC_NO_BLINK") +} + func (s *FormatSuite) TestNamedColors(c *C) { RemoveColor("myTest_1") parseNamedColor("?myTest_1", false)