Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ryan-leap/ShapeArray

Produces an array (with optional embedded text) which can be used for formatting console output
https://github.com/ryan-leap/ShapeArray

Last synced: 5 days ago
JSON representation

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

Awesome Lists containing this project

README

        

# 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

* Download the repository from https://github.com/ryan-leap/ShapeArray
* Unblock the zip file ((on Windows) Right Click -> Properties -> [v/] Unblock)

## Usage
```powershell
# 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
```powershell
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
```powershell
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](LICENSE.md) file for details.