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.

Putting results of ocgv on command line erases cursor

See original GitHub issue

I may be missing something, but this feels like a bug in GraphicalTools:

I want to define F7 as “Show command history using ocgv”:

$parameters = @{
  Key = 'F7'
  BriefDescription = 'ShowHistoryOcgv'
  LongDescription = 'Show History using Out-ConsoleGridView'
  ScriptBlock = {
    param($key, $arg)   # The arguments are ignored in this example
    $history = Get-History -Count 100 | Out-ConsoleGridView -Title "Select Command" -OutputMode Single
    if (-Not [string]::IsNullOrWhiteSpace($history)){
        [Microsoft.PowerShell.PSConsoleReadLine]::Insert($history)
    }
  }
}
Set-PSReadLineKeyHandler @parameters

If I hit F7 I get, as expected: image

I hit ENTER and get: image

So, it put the item I selected (ls) on the command line, but nuked my prompt.

(I’ve tested this without posh-git and oh-my-posh in-play and it reproduces, so it’s not related to that).

This may be a psreadline issue? Or I may not have written ShowHistoryOcgv correctly.

But I think it’s related to GraphicalTools because If I change my $history = above to:

$history = Get-History -Count 1

It works as expected.

This works as expected as well:

$history = Get-History -Count 100 | Out-GridView -Title "Select Command" -PassThru

Anyone have any insight?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
tigcommented, May 14, 2020

Just verified the bad behavior described here does not repro on Linux. My little F7 script above works awesome under Ubuntu on WSL!

1reaction
tigcommented, May 13, 2020

Not 100% confident this is the root of the problem yet, but WindowsDriver.cs does a Console.Clear() before it ends up calling CreateConsoleScreenBuffer as shown above. Thus, even thought the logic is there to allocate and use a different screen buffer, it clears the existing one.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Delete from cursor position until end of line in command- ...
I am trying to emulate readline keybindings in insert and command-line modes (for example, <C-u> for deleting from cursor position to ...
Read more >
Fastest way(s) to move the cursor on a terminal command ...
Ctrl-e Move to the end of the line. Meta-f Move forward a word, where a word is composed of letters and digits. Meta-b...
Read more >
Delete command line after cursor position - conemu
Manipulation with command line is a shell function. ... Try clink for cmd, PSReadLine for PowerShell, or even bash from cygwin or MsysGit....
Read more >
Bash: delete word ahead of cursor - command line
Bash: delete word ahead of cursor · Ctrl u is an option for erasing from cursor location to beginning... · Try alt +...
Read more >
5 ways to navigate the Linux terminal faster
Similarly, CTRL+K erases everything from the current cursor position to the end of the line. Shortcuts: Instead of Backspace, use CTRL+U.
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