PowerShell / ConsoleGuiTools

Modules that mix PowerShell and GUIs/CUIs!
https://www.powershellgallery.com/packages/Microsoft.PowerShell.ConsoleGuiTools
MIT License
776 stars 59 forks source link

Does not run on OpenSUSE because of ncurses incompatibility #195

Closed lxscaut closed 1 year ago

lxscaut commented 1 year ago

Prerequisites

Steps to reproduce

When running Out-ConsoleGridview on OpenSUSE Tumbleweed (latest version) I get the following error: Out-ConsoleGridView: Curses failed to initialize, the exception is: The native method "COLOR_PAIRS" does not exist

Checking the symbols of libncursesw.so.6 reveals the following issue: > nm -D /lib64/libncursesw.so.6 | grep COLOR 000000000000f3e0 T COLOR_PAIR 000000000000d740 T _nc_COLOR_PAIRS 000000000000d760 T _nc_COLORS

With ncurses5 on OpenSUSE it would work as on most other Linux distros: > nm -D /lib64/libncursesw.so.5 | grep COLOR 000000000000eeb0 T COLOR_PAIR 0000000000034034 B COLOR_PAIRS 0000000000034030 B COLORS

However OpenSUSE relies on ncurses6 and I cannot get pwsh running with libncursesw.so.5 and so Out-ConsoleGridView doesn't work on this Linux distribution.

Already updated ncurses to the latest available package version: ncurses-utils-6.4.20230617-15.1.x86_64 ncurses-devel-6.4.20230617-15.1.x86_64 libncurses6-6.4.20230617-15.1.x86_64

A few potential fixes such as trying to load _nc_COLOR_PAIRS if available instead of COLOR_PAIRS or others are described here: https://github.com/gui-cs/Terminal.Gui/issues/415

I hope you can help us here, as a change in this package is more likely than getting an update from the OpenSUSE distro.

Thanks and best regards, Alex

Expected behavior

Out-ConsoleGridview works

Actual behavior

PS > Get-Process | Out-ConsoleGridView 
Out-ConsoleGridView: Curses failed to initialize, the exception is: The native method "COLOR_PAIRS" does not exist

Error details

PS > Get-Error                                                                                         

Exception            :  
   Type      : System.Exception 
   TargetSite :  
       Name         : Init 
       DeclaringType : Terminal.Gui.CursesDriver, Terminal.Gui, Version=1.7.2.0, Culture=neutral, PublicKeyToken=null 
       MemberType   : Method 
       Module       : Terminal.Gui.dll 
   Message   : Curses failed to initialize, the exception is: The native method "COLOR_PAIRS" does not exist 
   Source    : Terminal.Gui 
   HResult   : -2146233088 
   StackTrace :  
  at Terminal.Gui.CursesDriver.Init(Action terminalResized) 
  at Terminal.Gui.Application.Init(Func`1 topLevelFactory, ConsoleDriver driver, IMainLoopDriver mainLoopDriver) 
  at Terminal.Gui.Application.Init(ConsoleDriver driver, IMainLoopDriver mainLoopDriver) 
  at OutGridView.Cmdlet.ConsoleGui.Start(ApplicationData applicationData) in D:\a\_work\1\s\src\Microsoft.PowerShell.ConsoleGuiTools\ConsoleGui.cs:line 31 
  at OutGridView.Cmdlet.OutConsoleGridViewCmdletCommand.EndProcessing() in D:\a\_work\1\s\src\Microsoft.PowerShell.ConsoleGuiTools\OutConsoleGridviewCmdletCommand.cs:line 147 
  at System.Management.Automation.CommandProcessorBase.Complete() 
CategoryInfo         : NotSpecified: (:) [Out-ConsoleGridView], Exception 
FullyQualifiedErrorId : System.Exception,OutGridView.Cmdlet.OutConsoleGridViewCmdletCommand 
InvocationInfo       :  
   MyCommand       : Out-ConsoleGridView 
   ScriptLineNumber : 1 
   OffsetInLine    : 15 
   HistoryId       : 2 
   Line            : Get-Process | Out-ConsoleGridView 
   Statement       : Out-ConsoleGridView 
   PositionMessage : At line:1 char:15 
                      + Get-Process | Out-ConsoleGridView 
                      +              ~~~~~~~~~~~~~~~~~~~ 
   InvocationName  : Out-ConsoleGridView 
   CommandOrigin   : Internal 
ScriptStackTrace     : at <ScriptBlock>, <No file>: line 1

Environment data

PS > $PSVersionTable                            

Name                          Value 
----                          ----- 
PSVersion                     7.4.0-preview.4 
PSEdition                     Core 
GitCommitId                   7.4.0-preview.4 
OS                            openSUSE Tumbleweed 
Platform                      Unix 
PSCompatibleVersions          {1.0, 2.0, 3.0, 4.0…} 
PSRemotingProtocolVersion     2.3 
SerializationVersion          1.1.0.1 
WSManStackVersion             3.0

Version

0.7.2

Visuals

No response

BDisp commented 1 year ago

What echo $TERM outputs?

lxscaut commented 1 year ago

> echo $TERM xterm-256color

BDisp commented 1 year ago

Do you are using a docker image?

rainerklier commented 1 year ago

Do you are using a docker image?

no. a real native bare metal linux installation

BDisp commented 1 year ago

Lol you answered with other user name, you both are the same person?

rainerklier commented 1 year ago

hi,

Lol you answered with other user name, you both are the same person?

no. first, my colleague created the issue for me. but as i anyhow also have a github account, i can answer your questions myself.

BDisp commented 1 year ago

Understood. I already get rid from the COLOR_PAIRS error, but now I'm getting the error Could not load the key stdscr. I think it's related with locale configuration. Do you know how to set it with a command line? Or if it's other issue that you know what, please let me know. Thanks.

rainerklier commented 1 year ago

Understood. I already get rid from the COLOR_PAIRS error, but now I'm getting the error Could not load the key stdscr. I think it's related with locale configuration. Do you know how to set it with a command line?

on my system the LANG environment variable is set to "de_AT.UTF-8". https://www.tecmint.com/set-system-locales-in-linux/

Or if it's other issue that you know what, please let me know. Thanks.

the "stdscr" seems to be some kind of standard variable. but i don't know anything about it.

BDisp commented 1 year ago

Yes they are variables:

stdscr = read_static_ptr ("stdscr");
curscr_ptr = get_ptr ("curscr");
lines_ptr = get_ptr ("LINES");
cols_ptr = get_ptr ("COLS");

None of this instructions returns a valid handle and only returns empty's IntPtr. I think the ncurses installed isn't the correct versions:

S  | Name                          | Summary                                                          | Type
---+-------------------------------+------------------------------------------------------------------+--------
   | busybox-ncurses-utils         | Busybox applets replacing ncurses-utils                          | package
i+ | libncurses5                   | Terminal control library                                         | package
   | libncurses5-32bit             | Terminal control library                                         | package
i  | libncurses6                   | Terminal control library                                         | package
i+ | libncurses6-32bit             | Terminal control library                                         | package
   | libyui-ncurses-devel          | Libyui - Header fles for the NCurses (text based) user interface | package
   | libyui-ncurses-pkg-devel      | Libyui-ncurses-pkg header files                                  | package
i+ | libyui-ncurses-pkg16          | Libyui - yast2 package selector widget for the NCurses UI        | package
   | libyui-ncurses-rest-api-devel | Libyui - Header files for the NCurses REST API plugin            | package
   | libyui-ncurses-rest-api16     | Libyui - REST API plugin for the Ncurses frontend                | package
   | libyui-ncurses-tools          | Libyui - tools for the NCurses (text based) user interface       | package
i  | libyui-ncurses16              | Libyui - NCurses (text based) user interface                     | package
i+ | ncurses-devel                 | Development files for the ncurses6 terminal control library      | package
   | ncurses-devel-32bit           | Development files for the ncurses6 terminal control library      | package
   | ncurses-devel-static          | Static libraries for the ncurses6 terminal control library       | package
   | ncurses-examples              | Tools using the new curses libraries                             | package
i  | ncurses-utils                 | Tools using the new curses libraries                             | package
i+ | ncurses5-devel                | Development files for the ncurses5 terminal control library      | package
   | ncurses5-devel-32bit          | Development files for the ncurses5 terminal control library      | package
   | ncurses5-devel-static         | Static libraries for the ncurses5 terminal control library       | package

How did you install ncurses?

rainerklier commented 1 year ago

these are the ncurses packages i have installed:

libyui-ncurses-pkg16-4.6.0-1.1.x86_64
libncurses5-6.4.20230617-15.1.x86_64
ncurses5-devel-6.4.20230617-15.1.x86_64
libncurses5-32bit-6.4.20230617-15.1.x86_64
libncurses6-32bit-6.4.20230617-15.1.x86_64
libyui-ncurses16-4.6.0-1.1.x86_64
ncurses-utils-6.4.20230617-15.1.x86_64
ncurses-devel-6.4.20230617-15.1.x86_64
libncurses6-6.4.20230617-15.1.x86_64

seems to be about the same as yours.

but you can search for more ncurses packages here: https://software.opensuse.org/search?baseproject=ALL&q=ncurses

BDisp commented 1 year ago

I think is missing the libncursesw6 or libncursesw5 for wider chars, but I can't install. Can you check that please.

rainerklier commented 1 year ago

I think is missing the libncursesw6 or libncursesw5 for wider chars, but I can't install. Can you check that please.

the package libncurses5 includes the file /usr/lib64/libncursesw.so.5 and package libncurses6 includes /usr/lib64/libncursesw.so.6.

the package ncurses-term and the packages libncursesw6 or libncursesw5 are only available for debian: https://software.opensuse.org/package/libncursesw5 https://software.opensuse.org/package/libncursesw6 https://software.opensuse.org/package/ncurses-term

and the available package https://software.opensuse.org/package/ncurses is only a source ("src") package.

BDisp commented 1 year ago

@rainerklier the workaround is install the libncurses5 (sudo zypper install libncurses5) and using the fix in this PR https://github.com/gui-cs/Terminal.Gui/pull/2749, which will force using this version.

rainerklier commented 1 year ago

@rainerklier the workaround is install the libncurses5 and using the fix in this PR, which will force using this version.

@BDisp Cool! Thanks. libncurses5 i already have installed. i am looking forward installing this new version. what do i have to do to install this new version once the PR has been merged into release? Install-Module Microsoft.PowerShell.ConsoleGuiTools? Update-Module Microsoft.PowerShell.ConsoleGuiTools?

BDisp commented 1 year ago

You welcome. Even if you already have installed libncurses5 it doesn't work without the fix. I hope @tig understand the inconvenience that OpenSuse users are facing and can publish this fix as quickly as possible. I'm not very familiar with PowerShell and maybe someone else can answer what's the right declaration.

rainerklier commented 1 year ago

Even if you already have installed libncurses5 it doesn't work without the fix.

yes, i know. that's why i am looking forward to receive your fix.... ;-)

I hope @tig understand the inconvenience that OpenSuse users are facing and can publish this fix as quickly as possible. I'm not very familiar with PowerShell and maybe someone else can answer what's the right declaration.

thanks. i am waiting for info when your PR is merged and how i can install it.

BDisp commented 1 year ago

@rainerklier the Terminal.Gui v1.13.1 with the fix was published https://www.nuget.org/packages/Terminal.Gui.

rainerklier commented 1 year ago

@rainerklier the Terminal.Gui v1.13.1 with the fix was published https://www.nuget.org/packages/Terminal.Gui.

ok. thanks. i immediatelly tried to use it, but i failed. what i did is the following:

  1. from the new Terminal.Gui package from nuget i copied the file lib/net7.0/Terminal.Gui.dll to the package folder of Microsoft.PowerShell.ConsoleGuiTools/0.7.2, and overwrote the old existing version of that file.
  2. then i tried a test with Get-Process | Out-ConsoleGridView
  3. the result was error: Out-ConsoleGridView: Curses failed to initialize, the exception is: Could not load file or assembly 'Microsoft.DotNet.PlatformAbstractions, Version=3.1.6.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
  4. i then downloaded microsoft.dotnet.platformabstractions.3.1.6.nupkg and copied from that package the files lib/net45/Microsoft.DotNet.PlatformAbstractions.* also to the package folder of Microsoft.PowerShell.ConsoleGuiTools/0.7.2
  5. now i receive the error message Out-ConsoleGridView: Method not found: 'System.Rune System.Rune.op_Implicit(Int32)'

and it seems that the dependency to Microsoft.DotNet.PlatformAbstractions is new. with the old Terminal.Gui.dll this was not the case. do i have to wait for a new package of Microsoft.PowerShell.ConsoleGuiTools to fix all of this? (https://www.powershellgallery.com/packages/Microsoft.PowerShell.ConsoleGuiTools)

BDisp commented 1 year ago

The Microsoft.DotNet.PlatformAbstractions is needed to check the OperatingSystem is "opensuse". The System.Rune belong to the NStack.Core nuget package (https://www.nuget.org/packages/NStack.Core), which perhaps isn't installed.

Edit:

Maybe @tig need to create a new PR here to update the Terminal.Gui nuget package in the ConsoleGuiTools.

rainerklier commented 1 year ago

The Microsoft.DotNet.PlatformAbstractions is needed to check the OperatingSystem is "opensuse". The System.Rune belong to the NStack.Core nuget package (https://www.nuget.org/packages/NStack.Core), which perhaps isn't installed.

after also copying file lib/netstandard2.0/NStack.dll from packlage nstack.core.1.0.7.nupkg to ~/.local/share/powershell/Modules/Microsoft.PowerShell.ConsoleGuiTools/0.7.2 it seems to work now!

:-D

thanks a lot! this is great!

Maybe @tig need to create a new PR here to update the Terminal.Gui nuget package in the ConsoleGuiTools.

of course, this would be a much nicer approach......