EINFO(3)

πŸ“¦
version 0.63.2 Β· 3 versions
, in alpine 3.23, alpine 3.24

🌈 EINFO(3) β€” colorful informational output πŸŽ€

Hiii bestie, welcome to the einfo family, a whole little library of functions living in libeinfo (link it with -leinfo) that make your program print cute lil' colored lines instead of boring gray ones. It's giving terminal glow-up, and honestly? Iconic. ✨


πŸ’– NAME πŸ’–

einfo, ewarn, eerror, ebegin, einfon, ewarnn, eerrorn, ebeginn, einfov, ewarnv, ebeginv, einfovn, ewarnvn, ebeginvn, ewarnx, eerrorx, eend, ewend, eendv, ewendv, ebracket, eindent, eoutdent, eindentv, eoutdentv, eprefix β€” colorful informational output πŸ¦‹


πŸ“š LIBRARY πŸ“š

Enhanced Information output library (libeinfo, -leinfo) πŸ’…


✨ SYNOPSIS ✨

#include <einfo.h>

int
einfo(const char * restrict format, ...);

int
ewarn(const char * restrict format, ...);

int
eerror(const char * restrict format, ...);

int
ebegin(const char * restrict format, ...);

int
einfon(const char * restrict format, ...);

int
ewarnn(const char * restrict format, ...);

int
eerrorn(const char * restrict format, ...);

int
ebeginn(const char * restrict format, ...);

int
einfov(const char * restrict format, ...);

int
ewarnv(const char * restrict format, ...);

int
ebeginv(const char * restrict format, ...);

int
einfovn(const char * restrict format, ...);

int
ewarnvn(const char * restrict format, ...);

int
ebeginvn(const char * restrict format, ...);

int
ewarnx(const char * restrict format, ...);

int
eerrorx(const char * restrict format, ...);

int
eend(int retval, const char * restrict format, ...);

int
ewend(int retval, const char * restrict format, ...);

int
eendv(int retval, const char * restrict format, ...);

int
ewendv(int retval, const char * restrict format, ...);

void
ebracket(int col, ECOLOR color, const char * restrict msg);

void
eindent(void);

void
eoutdent(void);

void
eindentv(void);

void
eoutdentv(void);

void
eprefix(const char * prefix);

🫢 DESCRIPTION 🫢

Okay so the einfo() family gives you simple informational output, but colorised. Basically einfo(), ewarn(), and eerror() behave exactly like printf() β€” except they slap a colored * at the front of your output. And the function you call decides the color, no cap:

  • einfo() β†’ green πŸ’š
  • ewarn() β†’ yellow πŸ’›
  • eerror() β†’ red ❀️

Also, einfo goes to stdout, and the other two go to stderr (classy). The return value is the number of real characters printed. And ebegin() is literally identical to einfo() except it appends 3 dots to the output β€” like it's leaving the group chat with a "...". 😭

einfov(), ewarnv(), and ebeginv() work the same way as einfo(), ewarn(), and ebegin() respectively, but they only actually do anything when EINFO_VERBOSE is true. Meanwhile you can make einfo(), ewarn(), and ebegin() go totally silent by setting EINFO_QUIET to true. Nothing printed. Muted. On read. πŸ”‡

So these functions were designed to output a whole line, which is why they also append a newline to the string. If you don't want that behavior, use einfon(), ewarnn(), eerrorn(), einfovn(), ewarnvn(), or ebeginvn() instead. The n means "no newline," iykyk. 🧚

Now the finale functions β€” eend(), ewend(), eendv(), and ewendv() are the counterparts to all of the above. Here's the vibe check:

  • If retval is zero, then ok in green gets printed in a bracket at the end of the prior line. πŸŽ€
  • Otherwise, the formatted string gets printed using error() (or ewarn() if you called ewend()), and !! in red (or yellow if you called ewend()) gets printed in a bracket at the end of the line.
  • Either way, the value of retval is returned.

ebracket() does the same thing as eend() but prints msg instead of ok or !!, in the color color, at the column col. Custom bracket moment. πŸ’…

eindent() indents subsequent calls to all of the above functions by 2 characters. eoutdent() removes an eindent(). And eindentv() / eoutdentv() only work when EINFO_VERBOSE is true. 🌸

eprefix() prefixes the string prefix to the above functions. Put a lil' label on everything. 🏷️


🌱 ENVIRONMENT 🌱

  • EINFO_QUIET β€” when set to true, makes the einfo() and einfon() family of functions quiet, so nothing is printed. 🀫
  • EERROR_QUIET β€” when set to true, makes the eerror() and eerrorn() family of functions quiet, so nothing is printed. 🀐
  • EINFO_VERBOSE β€” when set to true, makes the einfov() and einfovn() family of functions work, so they do print. πŸ“£

πŸ“‚ FILES πŸ“‚

  • /etc/init.d/functions.sh β€” provided by OpenRC, which lets shell scripts use all of the above functions. 🐚
Heads up bestie, historical reasons incoming: our verbose functions are prefixed with v instead of suffixed. So einfov becomes veinfo, and einfovn becomes veinfon. Rinse and repeat for the other verbose functions. It's giving old money naming conventions, but we respect the lore. πŸ’€

πŸ‘€ SEE ALSO πŸ‘€

printf(3),


πŸ‘‘ AUTHORS πŸ‘‘

Roy Marples <roy@marples.name>


That's the whole page, bestie β€” go forth and print in color, you absolute icon. 🌈

This lil' number comes from OpenRC, dated Mar 16, 2008 β€” yeah, she's been slaying since the 2000s and she's still serving. Periodt. πŸ’–

πŸ“¦ where this page comes from