Socket
Book a DemoInstallSign in
Socket

terminal-join

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

terminal-join

1.0.3
bundlerRubygems
Version published
Maintainers
1
Created
Source

💡 About

Terminal Layout let you style and join ANSI strings horizontally/vertically.

📥 Installation

Install the gem and add to the application's Gemfile by executing:

bundle add terminal-join

If bundler is not being used to manage dependencies, install the gem by executing:

gem install terminal-join

⌨️ Usage

📃 API

In Ruby do:

require 'terminal/join'

To style ANSI string:

Terminal::Join.style(`figlet Hello, World!`)
Terminal::Join.style(
  `figlet Hello, World!`,
  :bold, :italic, # Paint arguments (check out https://github.com/janlelis/paint#usage)
  halign: :bottom, # Horizontal alignment, available options are :top, :bottom and :center (default)
  valign: :right, # Vertical alignment, available options are :left, :right and :center (default)
  width: IO.console.winsize[1],
  height: 6,
  margin: [0, 2] # [horizontal_margin, vertical_margin]
  # You can write `margin: 2` to margin on all side.
)

Join ANSI strings horizontally or vertically:

Terminal::Join.horizontal(*%w[Foo Bar].map { `figlet #{_1}` })
# =>
#  _____            ____
# |  ___|__   ___  | __ )  __ _ _ __
# | |_ / _ \ / _ \ |  _ \ / _` | '__|
# |  _| (_) | (_) || |_) | (_| | |
# |_|  \___/ \___/ |____/ \__,_|_|

Terminal::Join.horizontal(
  *[*'A'..'D'].map { `figlet "#{_1}\n#{_1}"` },
  separator: `figlet ,`,
  align: :bottom
)
# =>
#     _        ____       ____     ____
#    / \      | __ )     / ___|   |  _ \
#   / _ \     |  _ \    | |       | | | |
#  / ___ \    | |_) |   | |___    | |_| |
# /_/   \_\   |____/     \____|   |____/
#
#     _        ____       ____     ____
#    / \      | __ )     / ___|   |  _ \
#   / _ \     |  _ \    | |       | | | |
#  / ___ \  _ | |_) | _ | |___  _ | |_| |
# /_/   \_\( )|____/ ( ) \____|( )|____/
#          |/        |/        |/

Terminal::Join.horizontal(*%w[Foo Bar].map { `figlet #{_1}` }) do |max_height|
  "  |  \n" * max_height
end
# =>
#  _____             |   ____
# |  ___|__   ___    |  | __ )  __ _ _ __
# | |_ / _ \ / _ \   |  |  _ \ / _` | '__|
# |  _| (_) | (_) |  |  | |_) | (_| | |
# |_|  \___/ \___/   |  |____/ \__,_|_|
#                    |

Terminal::Join.vertical(*[*1..3].map { `figlet #{_1}` })
# =>
#    _
#   / |
#   | |
#   | |
#   |_|
#
#  ____
# |___ \
#   __) |
#  / __/
# |_____|
#
#  _____
# |___ /
#   |_ \
#  ___) |
# |____/

Terminal::Join.vertical(
  *[*1..3].map { `figlet #{_1.to_s * _1}` },
  separator: '-' * 8,
  align: :right
)
# =>
#                _
#               / |
#               | |
#               | |
#               |_|
#
#          --------
#      ____  ____
#     |___ \|___ \
#       __) | __) |
#      / __/ / __/
#     |_____|_____|
#
#          --------
#  _______________
# |___ /___ /___ /
#   |_ \ |_ \ |_ \
#  ___) |__) |__) |
# |____/____/____/

Terminal::Join.vertical(*[*1..3].map { `figlet #{_1.to_s * _1}` }) do |max_width|
  '-' * max_width
end
# =>
#         _
#        / |
#        | |
#        | |
#        |_|
#
# -----------------
#    ____  ____
#   |___ \|___ \
#     __) | __) |
#    / __/ / __/
#   |_____|_____|
#
# -----------------
#  _______________
# |___ /___ /___ /
#   |_ \ |_ \ |_ \
#  ___) |__) |__) |
# |____/____/____/

➕ String and array extensions

require 'terminal/join/extensions'

`figlet Hello, World!`.style(:bold, margin: [4, 1])

%w[Foo Bar].map { `figlet #{_1}` }.hjoin
[*'A'..'D'].map { `figlet "#{_1}\n#{_1}"` }.hjoin(`figlet ,`, align: :bottom)
%w[Foo Bar].map { `figlet #{_1}` }.hjoin { "  |  \n" * _1 }

[*1..3].map { `figlet #{_1}` }.vjoin
[*1..3].map { `figlet #{_1.to_s * _1}` }.vjoin('-' * 8, align: :right)
[*1..3].map { `figlet #{_1.to_s * _1}` }.vjoin { '-' * _1 }

💌 Credits

  • Gum by Charm

FAQs

Package last updated on 14 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.