Coder Social home page Coder Social logo

Comments (7)

tsjensen avatar tsjensen commented on June 3, 2024

Well, boxes has -a (docs) which should be very similar to Figlet's -lrcx.
You can even center Figlet text, e.g. figlet foo | boxes -a hc -s 50.

Terminal width is normally something that boxes is agnostic of, because boxes will always try to match the input text. Additional padding can be specified with -p.

Let me know if maybe that already solves your case!

from boxes.

tsjensen avatar tsjensen commented on June 3, 2024

I just found that on my terminal (Debian / bash), I can

figlet "Hello World !" | boxes -d peek -a hc -s $COLUMNS

To get a box which spans exactly the terminal width. Don't know who keeps the $COLUMNS up-to-date, but it works out of the box.

from boxes.

Davidy22 avatar Davidy22 commented on June 3, 2024

The -p and -a flags let me shift the text around inside an oversized box, but I want to realign the box itself to be centered in the terminal, but still fitted to the width of the text. $COLUMNS gets us a bit of the way there, but currently we only have the option to have our box take up the full width, can't center or right justify a smaller box within the width of $COLUMNS.

from boxes.

tsjensen avatar tsjensen commented on June 3, 2024

Ah, I think I get your point now. Thanks for clarifying.
Try this.

Centered box with figlet text:

figlet centered | boxes -d unicornthink | boxes -s $COLUMNS -c x -a hc -i none | cut -c 2-

Right-aligned box with figlet text:

figlet right-aligned | boxes -d unicornthink | boxes -s $COLUMNS -c x -a hr -i none | sed -e 's/^x/ /'

The basic idea is to call boxes twice, the second time with only a few x in the first column of the result, which we remove again with the cut command. In this way, boxes centers the box.
Some googling gave me that one might use $(tput cols) instead of $COLUMNS for slightly better coverage of different shells.

from boxes.

Davidy22 avatar Davidy22 commented on June 3, 2024

well i guess that works, a lotta extra work over just a flag. Actually if this is going to be the recommended approach, maybe there could be a blank "box" that prints nothing, is only for alignment purposes and is appropriately named, so that the command chain gets cut down to:

figlet right-aligned | boxes -d unicornthink | boxes -s $COLUMNS -d align -a hr

Saving a sed or cut command, making this a lot more discoverable and easier to figure out independently. A box that prints nothing should be easy enough for me to write actually.

from boxes.

tsjensen avatar tsjensen commented on June 3, 2024

In order to make this easier to discover, I added a section to the FAQ.

While trying out the commands above, I found that a blank box actually causes an error boxes may not consist entirely of whitespace. I'll open a new issue as a reminder to myself to find out why that is. Maybe we can enable a new use case for boxes.

In general, unix philosophy says that tools should do one thing, and do it well. So, aligning stuff in a terminal window should be a task for another tool. (On Mac, fmt is supposed to be able to do that.) It would be hard for boxes to reliably determine the terminal width on all of the platforms it runs on. For example, I wouldn't know how to do this on Windows.

from boxes.

Davidy22 avatar Davidy22 commented on June 3, 2024

I guess the blank box for formatting would handle this well enough, closing in favor of the other ticket

from boxes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.