-
Notifications
You must be signed in to change notification settings - Fork 700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minimal PowerShell Sample #945
Comments
tput reset # To make PSReadLine work properly again, notably up- and down-arrow. What's up with this? What does |
I hope that could fix the #931 issue. |
@tig:
|
Actually, resetting the terminal with It is effective in preventing subsequent command-line editing problems on both macOS and Ubuntu, so it might indeed help in WSL too. The problem only occurs in-process in PowerShell and is not related to the Possibly related: there's a longstanding bug report that describes the opposite problem (up/down-arrow keys not working in a utility that displays an alternate screen): PowerShell/PowerShell#7375 If you call the code via PowerShell's CLI - |
@mklement0 Do you know where I can find the source to I have a feeling this is relevant: I thought I had removed this and moved it into gui.cs already.
See #418 |
I can confirm that replacing Examining what escape sequences PS> (tput init) -replace '\e', '\u001b'
\u001b[!p\u001b[?3;4l\u001b[4l\u001b> Even executing I don't think the implementation of Based on
where terminfo(5) (
|
The only sequence escape which worked to me, after testing many of them, was as shown in my PR #953. On enter |
The portable equivalent of VT100 escape sequence @BDisp, I get similar escape sequences via PS> (tput rmkx) -replace '\e', '\x1b'; (tput smkx) -replace '\e', '\x1b'
\x1b[?1l\x1b>
\x1b[?1h\x1b= |
@mklement0 that great, thanks. Work better than the other because the prompt is maintained sequential instead pushing to the bottom of the terminal. With the |
@BDisp, for maximum robustness we shouldn't hard-code these sequences, as they may vary by terminal emulation. - though perhaps, pragmatically speaking, that is fine nonetheless, given that terminal emulators today mostly seem to be Xterm-compatible (I don't know, however). If we do have to make this terminal-agnostic: While we don't want to have to create an expensive As for what At the moment I'm not aware of a reverse Terminfo lookup, but the table of VT100 escape sequences at http://ascii-table.com/ansi-escape-sequences-vt-100.php - whose identifiers do NOT respond to the TermInfo capability names - suggest the following:
That is, they seem to act on the keys of the numeric keypad. |
@mklement0 I ended up to use like #418 (comment)
as documented at http://ascii-table.com/ansi-escape-sequences-vt-100.php |
@mklement0 I'm experiencing another strange behavior with both escapes sequences on screen resizing as it's not refreshing well letting the screen all messed up. Do you know why this happens? |
@BDisp, I think that problem is not related to the escape sequences we've discussed per se: Even without these sequences, I see the following behavior: macOS:
Linux (Ubuntu 18.04):
So it seems that PowerShell is at least part of the problem - are you saying that with compiled executables you only started seeing the problem after emitting the escape sequence on shutdown and therefore only in subsequent runs? Also, I've noticed that both terminal apps on macOS apparently don't draw the application on the alternate screen: you can actually scroll up while the application is running (using the terminal app's scroll bars) and see the previous terminal output. Furthermore, the radio buttons and checkboxes in the example application aren't drawing, in both terminal apps. |
I've noticed too. It's annoying.
I run with dotnet ./app.dll and I seeing the problem while the app is open and resizing the screen. I can exit and reopen again but the messed screen on resizing is worse than the terminal hang.
I noticed that too and is very annoying too on both Terminal and iTerm2.
Yes that true unfortunately. Mac does not handle very well with unicode. I tested with many configurations without success. I debugged into the code and the keys are sending correct but both the Terminal and iTerm2 don't process them. I think Mac is causing that. |
I'm still a bit unclear: did emitting the escape sequence on shutdown make the resizing problem worse in your dotnet application on rerunning it in the same session?
Ah, yes, it hadn't occurred to me that this was also the lack of Unicode support - I'll provide more feedback in #949. |
The escape sequence works perfectly on shutdown but while running the app on the same session the screen does not redraws well. In WSL it's a messy screen and in linux the app does not resize as the screen size changes. |
Perhaps if we take a step back and try to let ncurses handle restoring the previous terminal state - which is preferable anyway - the problem would go away: On macOS, However, it suggests that pairing
|
I think that will be the way in the future to manage properly ncurses (save and restore previous state). |
To shed some more light on the original problem:
PowerShell exhibits the same problematic behavior: These misbehaviors rarely surface as a problem, at least in single-platform use, because By contrast, |
Unfortunately, I misspoke - please see the updated previous comment; in short: irrespective of whether the Terminal.Gui application is run in-process as PowerShell code or via an external executable, the application-cursor mode is unconditionally turned off. However, that is only problematic for PowerShell in the in-process case, because when it runs external applications it always turns that mode back on for itself. |
Started thinking about this again. 'tis a bummer this is not fixed: PowerShell/PowerShell#6724 |
Thanks for a really nice example! There are others out there, but I like how cleanly this one is implemented. |
I wrote a slight modification of your example which installs the ConsoleGuiTools module to help make life easier. using namespace Terminal.Gui
if (!$(Get-Module Microsoft.PowerShell.ConsoleGuiTools)) {
Install-Module Microsoft.PowerShell.ConsoleGuiTools
}
Import-Module Microsoft.PowerShell.ConsoleGuiTools
$module = (Get-Module Microsoft.PowerShell.ConsoleGuiTools -List).ModuleBase
Add-Type -Path (Join-path $module Terminal.Gui.dll)
[Application]::Init()
$topLevel = [TopLevel]@{}
$topLevel.Add([StatusBar]@{
Visible = $true
Items = @(
[StatusItem]::new([int][Key]("CtrlMask") -bor [int][Key]("Q"), '~CTRL-Q~ Quit', {
[Application]::RequestStop()
})
)
})
$dialog = [Dialog]@{
X = [Pos]::Center()
Y = [Pos]::Center()
Title = 'Dialog'
}
$text = [TextField]@{
X = [Pos]::Center()
Y = [Pos]::Center()
Width = 20
Text = 'Howdy!'
}
$dialog.Add($text)
$quit = [Button]@{
X = [Pos]::Center()
Y = [Pos]::Center() + 1
Text = 'Quit'
}
$quit.add_Clicked({ [Application]::RequestStop() })
$dialog.Add($quit)
$topLevel.Add($dialog)
[Application]::Run($topLevel)
[Application]::Shutdown()
Write-Output "Got ""$($text.Text.ToString())"" from user input" edit 1: I struggled with status bar items and the |
Thanks, @ca0abinary - that's the definitely the simplest option in v7.2+. I took the liberty of integrating your I've also updated the answer, which was written pre-v1, to reflect the status quo. |
The text was updated successfully, but these errors were encountered: