Skip to content

Neved4/center

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

C IEEE Homebrew

center - Centers text from stdin! 🛠️

center reads input from stdin, calculates the width of each line (considering multibyte characters), and center-aligns the text within the terminal window. Fully supports UTF-8.

Originally by Lizzy Fleckenstein 🤍

Highlights

  • Terminal size detection: Adjusts text to fit the terminal width.
  • Multibyte support: Properly handles UTF-8 Unicode characters.
  • Text centering: Prints each line centered within the terminal.
  • Error handling: Graceful handling of system call failures.

Getting Started

Prerequisites

If you are building center, you'll need:

  • A C compiler that supports C99 or later.

Installing

If you have Homebrew installed, just run:

brew install Neved4/homebrew-tap/center

Implementation

center operates as follows:

  1. Opens /dev/tty to get the terminal width.
  2. Reads input line-by-line.
  3. Calculates character width (supporting multibyte characters).
  4. Prints each line centered in the terminal.

Examples

Below is an example of how the center command works in practice:

$ echo 'Hello World!' | center
                                  Hello World!

Compatibility

Runs on Linux, macOS and *BSD systems on x86_64 and arm64, and compiles with zig, clang, gcc, tcc and any other compiler that supports C99 or later.

Standards

center is compatible with POSIX.1-20241 as well as the C232 standard.

See Also

For further reference and related tools, check out the following:

License

center is licensed under the terms of the GPLv3 License.

See the LICENSE file for details.

Footnotes

  1. IEEE Std 1003.1-2024: Standard for Information Technology — Portable Operating System Interface (POSIX®),
    ISO/IEC DIS 9945. URL: https://pubs.opengroup.org/onlinepubs/9799919799/

  2. ISO/IEC 9899: Standard for Information Technology — Programming languages — C, ISO/IEC 9899:2023.
    URL: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf

About

🛠️ Centers text read from stdin!

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •