Skip to content

Black screen after using tui apps, but only when using Set-PSReadLineKeyHandler #2954

Closed

Description

@AsafMah

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues, especially the pinned issues.

Exception report

N/A

Screenshot

ezgif com-gif-maker

Environment data

PS Version: 7.1.5
PS HostName: ConsoleHost (Windows Terminal)
PSReadLine Version: 2.1.0
PSReadLine EditMode: Windows
OS: 10.0.22000.1 (WinBuild.160101.0800)
BufferWidth: 120
BufferHeight: 30

Steps to reproduce

#Install fzf (or any other tui app)

fzf # choose an item, it gets printed on the screen and the next prompt appears

Set-PSReadlineKeyHandler -Chord "Shift+Tab" -ScriptBlock {fzf} # Or any key
# Press the the key, select item
# Black screen, after pressing enter the next prompt appears, but the result is never printed

Expected behavior

I expect the behavior when starting the app from the hotkey to be the same as when starting directly -

When the app quits it prints its result and the next prompt appears.

Actual behavior

When quitting the app the terminal is a black screen

If the app prints something, like the result in fzf, it never gets displayed.

If you try typing, the text appears on the middle without a prompt:
image

When pressing enter the prompt appears again, but the result never does.

Activity

  1. ghost added
    Needs-Triage 🔍It's a new issue that core contributor team needs to triage.
    on Nov 7, 2021
  2. ghost added
    In-PRA PR is opened targeting the issue
    on Nov 30, 2021
  3. ghost removed
    In-PRA PR is opened targeting the issue
    on Jan 4, 2022
  4. AsafMah commented on Feb 23, 2022

    @AsafMah
    Author

    I upgraded to 2.2.2:

    get-module psreadline
    
    ModuleType Version    PreRelease Name                                ExportedCommands
    ---------- -------    ---------- ----                                ----------------
    Script     2.2.2                 PSReadLine
    

    And the issue still persists

  5. daxian-dbw commented on Feb 23, 2022

    @daxian-dbw
    Member

    If you try typing, the text appears on the middle without a prompt:

    This was fixed.

    I expect the behavior when starting the app from the hotkey to be the same as when starting directly -

    It doesn't work that way. The output from executing the script block will be captured so fzf won't write to the console. I guess what you want is Set-PSReadlineKeyHandler -Chord "Shift+Tab" -ScriptBlock { $s = fzf; [Microsoft.PowerShell.PSConsoleReadLine]::Insert($s) }, so the selected item will be used as your input.

    Animation

  6. AsafMah commented on Feb 24, 2022

    @AsafMah
    Author

    Thanks!

    For future reference, that's the full "search history command" I have now:

    function fhv() {
        if (Get-Command Get-PSReadLineOption -ErrorAction SilentlyContinue) {
            $result = Get-Content (Get-PSReadLineOption).HistorySavePath | fzf --reverse --no-sort
        } else {
            $result = Get-History | ForEach-Object { $_.CommandLine } | fzf --reverse --no-sort
        }
        return $result
    }
    
    Set-PSReadlineKeyHandler -Chord "Ctrl+Shift+R" -ScriptBlock {$s = fhv; [Microsoft.PowerShell.PSConsoleReadLine]::DeletePreviousLines(); [Microsoft.PowerShell.PSConsoleReadLine]::Insert($s.Trim()) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions