question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[PowerShell] Object initialiser does not work for Label but does for Window

See original GitHub issue

Hi

I’m investigating Terminal.Gui in PowerShell. I found that I can create a Label using the constructor, but not using object initialisation. I get no errors, but the label is not displayed. However, object initialisation works for Window. What am I doing wrong?

Sample code (please excuse the quality, it’s my first attempt):

using namespace Terminal.Gui

Add-Type -Path 'C:\Users\<removed>\.nuget\packages\terminal.gui\1.0.0-pre.99.1\lib\net5.0\Terminal.Gui.dll'
Add-Type -Path 'C:\Users\<removed>\.nuget\packages\nstack.core\0.16.0\lib\netstandard2.0\NStack.dll'

[Application]::Init()

$top = [Application]::Top

# This object initialiser works for Window
$mainWindow = [Window] @{
    Title  = 'Testing'
    X      = 0
    Y      = 1
    Width  = [Dim]::Fill()
    Height = [Dim]::Fill()
}

$top.Add($mainWindow)

# Using the constructor works. Label is displayed
$testLabel1 = [Label]::new(0, 0, 'Test1')

# Using object initialiser does not work for Label
# No errors, but the label is not displayed
$testLabel2 = [Label] @{
    X    = 0
    Y    = 1
    Text = 'Test2'
}

$mainWindow.Add($testLabel1)
$mainWindow.Add($testLabel2)

$menu1 = [MenuBar]::new(
    @(
        [MenuBarItem] @{
            Title    = '_File'
            Children = @(
                [MenuItem] @{
                    Title  = '_Quit'
                    Action = {[Application]::RequestStop()}
                }
            )
        }
    )
)

$top.Add($menu1)

[Application]::Run()
[Application]::Shutdown()

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mrboringcommented, Dec 29, 2020

PowerShell 7 and latest master works:

image

Hopefully there is a solution to it working in Windows Terminal.

0reactions
BDispcommented, Dec 29, 2020

I only could make it working with this code:

$menu1 = [MenuBar]::new(
    @(
        [MenuBarItem]::new('_File',
            @(
                [MenuItem]::new('_Quit', '',
                    {[Application]::RequestStop()}
                )
            )
        )
    )
)

powershell-menu

If you don’t need this issue open anymore, please close it. Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PowerShell Form not displaying full Label message
I am using a label for this and I added a text. The problem is that my text does not show completely in...
Read more >
Use PowerShell to Initialize Raw Disks and to Partition and ...
To do this I use the Get-Disk function, and I use the Where-Object cmdlet to limit the results to those with a 'Raw'...
Read more >
PowerShell connection from MacOS not working
I trying PowerShell 7 on MacOS and I have installed SharePoint Online Management Shell but the " Connect-SPOService" command is not found.
Read more >
Statements - PowerShell
A statement specifies some sort of action that is to be performed.
Read more >
Initialize-Disk (Storage) - PowerShell
The Initialize-Disk cmdlet initializes a Disk object with the RAW ... Disks must be initialized before they can be formatted and used to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found