Minimal PowerShell Sample
See original GitHub issueusing namespace Terminal.Gui
# Load the Terminal.Gui assembly and its dependencies (assumed to be in the
# the same directory).
# NOTE: `using assmembly <path>` seemingly only works with full, literal paths
# as of PowerShell Core 7.1.0-preview.7.
# The assumption here is that all relevant DLLs are stored in subfolder
# assemblies/bin/Release/*/publish of the script directory, as shown in
# https://stackoverflow.com/a/50004706/45375
#Add-Type -Path $PSScriptRoot/assemblies/bin/Release/*/publish/Terminal.Gui.dll
# Initialize the "GUI".
# Note: This must come before creating windows and controls.
[Application]::Init()
$win = [Window] @{
Title = 'Hello World'
}
$edt = [TextField] @{
X = [Pos]::Center()
Y = [Pos]::Center()
Width = 20
Text = 'This text will be returned'
}
$win.Add($edt)
$btn = [Button] @{
X = [Pos]::Center()
Y = [Pos]::Center() + 1
Text = 'Quit'
}
$win.Add($btn)
[Application]::Top.Add($win)
# Attach an event handler to the button.
# Note: Register-ObjectEvent -Action is NOT an option, because
# the [Application]::Run() method used to display the window is blocking.
$btn.add_Clicked({
# Close the modal window.
# This call is also necessary to stop printing garbage in response to mouse
# movements later.
[Application]::RequestStop()
})
# Show the window (takes over the whole screen).
# Note: This is a blocking call.
[Application]::Run()
# As of 1.0.0-pre.4, at least on macOS, the following two statements
# are necessary on in order for the terminal to behave properly again.
[Application]::Shutdown() # Clears the screen too; required for being able to rerun the application in the same session.
#tput reset # To make PSReadLine work properly again, notably up- and down-arrow.
$edt.Text.ToString()
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:25
Top Results From Across the Web
Minimal PowerShell Sample #945 - gui-cs/Terminal.Gui
PowerShell script : broken in both Terminal.app and iTerm.app, though with different symptoms: Terminal.app: broken (doesn't seem to be aware of ...
Read more >Develop Minimal Footprint with PowerShell and Features ...
This post presents a sample process and operations for developing a minimal server footprint by using Features on Demand with Windows ...
Read more >minimal-windows-server.json 1.0.133
{{ template_dir }}/scripts/Windows/create_appveyor_user.ps1" ], "environment_vars": [ ... {{ template_dir }}/iso/minimal-windows-server.iso" ] ...
Read more >Using Experimental Features in PowerShell
The following examples use the TestExe.exe tool. You can build TestExe from the source code. See TestExe in the PowerShell source repository.
Read more >How to Write a PowerShell Module Manifest
For an example of a default module manifest, see the Sample module ... Type: Version, <empty string>, Minimum version of the PowerShell ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I wrote a slight modification of your example which installs the ConsoleGuiTools module to help make life easier.
edit 1: I struggled with status bar items and the
Key
class being not CLS compliant. Updated this example to show my workaround.Thanks for a really nice example! There are others out there, but I like how cleanly this one is implemented.