Last active
May 19, 2021 14:46
-
-
Save AndrewPla/e2fef1f8c976e9538347bf5c1b206fd1 to your computer and use it in GitHub Desktop.
Displays a visual representation of a Trello Board inside the terminal.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Requires -modules Microsoft.PowerShell.ConsoleGuiTools, PowerTrello | |
# Read more about positions | |
# https://migueldeicaza.github.io/gui.cs/api/Terminal.Gui/Terminal.Gui.Pos.html | |
# Getting started with Terminal.UI by Adam Driscoll | |
# https://blog.ironmansoftware.com/tui-powershell/ | |
# options https://github.com/cbttrevor/powershell-terminal | |
# take note of your buffer size | |
# $host.ui.rawui.buffersize | |
# https://github.com/rothgar | |
$BoardName = 'Posts+Projects' | |
# Import the module and got things started | |
Import-Module Microsoft.PowerShell.ConsoleGuiTools | |
$module = (Get-Module Microsoft.PowerShell.ConsoleGuiTools -List).ModuleBase | |
Add-Type -Path (Join-path $module Terminal.Gui.dll) | |
[Terminal.Gui.Application]::Init() | |
# Grab information from trello | |
$board = Get-TrelloBoard -Name $BoardName | |
$lists = Get-TrelloList -BoardId $board.id | Sort-Object pos | |
$cards = Get-TrelloCard -Board $board | |
# Instantiate window | |
$Window = [Terminal.Gui.Window]::new() | |
# Determine how wide each frame view should be | |
$widthPercent = 100 / $lists.count | |
# Foreach List we generate a frame view | |
foreach ($list in $lists) { | |
Write-Verbose "Generating frame view for $($list.name) list" | |
# grab all cards in the current list | |
$listCards = $cards | Where-Object idlist -eq $list.id | |
#region Generate Frame View - container view that has title, border, and contain other subviews | |
$Frame = [Terminal.Gui.FrameView]::new() | |
$Frame.Title = $list.name | |
$Frame.Width = [Terminal.Gui.Dim]::Percent($widthPercent) | |
$Frame.Height = [Terminal.Gui.Dim]::Fill() | |
# If there is already a frame we will put this to the right of it | |
if ($previousFrame) { $frame.x = [Terminal.Gui.Pos]::right($previousFrame) } | |
# Grab a copy of the frame so we can refer to it later for positioning | |
$previousFrame = $frame | |
#endregion | |
#region Go through each card and generate a clickable button | |
foreach ($card in $listCards) { | |
# Generate button for each card | |
$button = [Terminal.Gui.Button]::new() | |
$button.text = $card.name | |
$button.height = 2 | |
$button.Width = [Terminal.Gui.Dim]::Fill() | |
# Add a dialog box when you click on an action | |
$button.add_clicked( { | |
$result = [Terminal.Gui.MessageBox]::Query($card.name, "Read Description/Move/Archive/", @("Description", "Move","Archive")) | |
switch ($result) { | |
0 { } | |
1 { } | |
2 { } | |
Default {} | |
} | |
} ) | |
# If there is a previous button we need to put this below it | |
if ($previousButton) { $button.y = [Terminal.Gui.Pos]::Bottom($previousButton) } | |
$previousButton = $button | |
$Frame.Add($Button) | |
} | |
# Nullify the variable so it doesn't trigger for the next iteration | |
$previousButton = $null | |
#DElete this i think $previousLabel = $Label | |
# nullify the variable so that it doesn't exist in the next loop | |
$previousButton = $null | |
#endregion #> | |
# Add the newly created frame to the window | |
$Window.Add($Frame) | |
} | |
$Window.Title = "$BoardName Trello Board" | |
[Terminal.Gui.Application]::Top.Add($Window) | |
# This is was actually RUNS the application | |
[Terminal.Gui.Application]::Run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment