Skip to content

Produces an array (with optional embedded text) which can be used for formatting console output

License

Notifications You must be signed in to change notification settings

ryan-leap/ShapeArray

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 

Repository files navigation

ShapeArray

Creates an array whose arrangement of characters resembles a shape when displayed to the console. Specifically, New-ShapeRectangle produces a rectangularly shaped array which can optionally have embedded text justified to your needs. This is intended to be used for displaying nicely formatted messages to the end-user of your tool/script.

Installing

Download from GitHub repository

Usage

# Dot-source the file to bring the function in scope
. .\ShapeArray.ps1

# Get help
Get-Help New-ShapeArray

Get-Help Join-Shape

Examples

Produces an empty rectangle and rectangles with embedded text

PS C:\> New-ShapeRectangle -EdgeChar '-'

  ---------------------------------------------------------------------------------------------------------
  -                                                                                                       -
  -                                                                                                       -
  -                                                                                                       -
  -                                                                                                       -
  ---------------------------------------------------------------------------------------------------------

PS C:\> New-ShapeRectangle -TextEmbed "Hello World!"

  *********************************************************************************************************
  *                                                                                                       *
  *                                             Hello World!                                              *
  *                                                                                                       *
  *                                                                                                       *
  *********************************************************************************************************

PS C:\> New-ShapeRectangle -Height 8 -TextEmbed 'Hello World!' -TextAlignHorizontal Left -TextAlignVertical Bottom

  *********************************************************************************************************
  *                                                                                                       *
  *                                                                                                       *
  *                                                                                                       *
  *                                                                                                       *
  * Hello World!                                                                                          *
  *                                                                                                       *
  *********************************************************************************************************

PS C:\> $header = New-ShapeRectangle -Height 5 -TextEmbed "The Title"
PS C:\> $body = New-ShapeRectangle -Height 10 -EdgeChar ' ' -TextEmbed "The Content"
PS C:\> $footer = New-ShapeRectangle -Height 5 -TextEmbed "The End!"
PS C:\> $header; $body; $footer

  *********************************************************************************************************
  *                                                                                                       *
  *                                               The Title                                               *
  *                                                                                                       *
  *********************************************************************************************************






                                                 The Content







  *********************************************************************************************************
  *                                                                                                       *
  *                                               The End!                                                *
  *                                                                                                       *
  *********************************************************************************************************

Combines shape arrays into a single shape array

PS C:\> Join-Shape -Left (New-ShapeRectangle -Width 20) -Right (New-ShapeRectangle -Width 50)

  ********************   **************************************************
  *                  *   *                                                *
  *                  *   *                                                *
  *                  *   *                                                *
  *                  *   *                                                *
  ********************   **************************************************

PS C:\> $box = New-ShapeRectangle -Height 5 -Width 10 -MarginLeft 0 -EdgeChar 'X' -FillChar 'O'
PS C:\> $box

XXXXXXXXXX
XOOOOOOOOX
XOOOOOOOOX
XOOOOOOOOX
XXXXXXXXXX

PS C:\> $boxes = $box
PS C:\> for ($i = 0; $i -lt 9; $i++) { $boxes = Join-Shape -Left $boxes -Right $box }
PS C:\> $boxes

XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX
XOOOOOOOOX XOOOOOOOOX XOOOOOOOOX XOOOOOOOOX XOOOOOOOOX XOOOOOOOOX XOOOOOOOOX XOOOOOOOOX XOOOOOOOOX XOOOOOOOOX
XOOOOOOOOX XOOOOOOOOX XOOOOOOOOX XOOOOOOOOX XOOOOOOOOX XOOOOOOOOX XOOOOOOOOX XOOOOOOOOX XOOOOOOOOX XOOOOOOOOX
XOOOOOOOOX XOOOOOOOOX XOOOOOOOOX XOOOOOOOOX XOOOOOOOOX XOOOOOOOOX XOOOOOOOOX XOOOOOOOOX XOOOOOOOOX XOOOOOOOOX
XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX

Author(s)

  • Ryan Leap - Initial work

License

Licensed under the MIT License. See LICENSE file for details.

About

Produces an array (with optional embedded text) which can be used for formatting console output

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published