Created
August 9, 2019 04:37
-
-
Save Jaykul/abf14ba4ea2b66430d20eb0c9e8a36ef to your computer and use it in GitHub Desktop.
The problem with gui.cs is once you create something, you can't create another. I.e. you can't run this script twice.
This file contains 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
using namespace Terminal.Gui # maybe it isn't installed yet, but who cares? | |
if (!(Test-Path Libraries)) { | |
mkdir Libraries -Confirm | |
} | |
if (!(Test-Path .\Libraries\Terminal.Gui.0.24.0\lib\netcoreapp2.0\Terminal.Gui.dll)) { | |
Install-Package Terminal.Gui -Destination .\Libraries\ | |
} | |
add-type -path .\Libraries\NStack.Core.0.11.0\lib\netstandard1.5\NStack.dll | |
add-type -path .\Libraries\Terminal.Gui.0.24.0\lib\netcoreapp2.0\Terminal.Gui.dll | |
$Win = [Window]::new("Posh") | |
$global:Text = [TextView]@{ | |
Width = [Dim]::Fill() | |
Height = [Dim]::Fill() | |
ReadOnly = $false | |
} | |
$Win.Add($global:Text) | |
$Menu = [MenuBar]::new([MenuBarItem[]]@( | |
[MenuBarItem]::new("_File", [MenuItem[]]@( | |
[MenuItem]::new("_New", "Creates new file", { | |
$global:Text.Text = "" | |
$global:OpenFile = "" | |
}), | |
[MenuItem]::new("_Save", "Save the file", { | |
if (!$global:OpenFile) { | |
$dialog = [SaveDialog]::new("Save", "Save as...") | |
[Application]::Run($dialog) | |
Write-Warning "FileName $($dialog.FileName)" | |
Write-Warning "FilePath $($dialog.FilePath)" | |
$global:OpenFile = [string]$dialog.FileName | |
} | |
if ($global:Text.Text) { | |
Set-Content $global:OpenFile $global:Text.Text | |
} | |
$global:Text.EnsureFocus() | |
}), | |
[MenuItem]::new("Save _As", "Save with a new name", { | |
$dialog = [SaveDialog]::new("Save", "Save as...") | |
[Application]::Run($dialog) | |
$global:OpenFile = [string]$dialog.FileName | |
if ($global:Text.Text) { | |
Set-Content $global:OpenFile $global:Text.Text | |
} | |
$global:Text.EnsureFocus() | |
}), | |
[MenuItem]::new("_Open", "Opens an existing file", { | |
$dialog = [OpenDialog]::new("Open", "Open a file") | |
[Application]::Run($dialog) | |
$global:OpenFile = [string]$dialog.FilePaths[0] | |
$global:Text.LoadFile($global:OpenFile) | |
$global:Text.EnsureFocus() | |
}), | |
[MenuItem]::new("_Close", "", { }), | |
[MenuItem]::new("E_xit", "", { [Application]::RequestStop() }) | |
)) | |
)) | |
[Application]::Init() | |
[Application]::Top.Add($win, $menu); | |
[Application]::Run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment