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.

OCGV: Sometimes exits as soon as arrow key is pressed

See original GitHub issue

Prerequisites

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

Steps to reproduce

This one seems a bit random but ive managed to isolate it a block of code i think can trigger it sometimes. It might take a good few runs of the below code to get it to happen.

$list=@(1..100)
$count =0
do{
[PSCustomObject]$platform = $list  | Out-consoleGridView -verbose -OutputMode Single -Title $count
$platform.name.split()
Write-Host "fgfg"
$count ++
}
while ($count -lt 3)
Write-Host "gh"

I know the split will error on this by design as it seems to help trigger this more often.

What should happen is when running this loop with F8 in VS code sometime the first iteration will skip when you try to arrow down to select one in the list.

Version used is master compiled from source but same exact thing happens with 0.6.2

Expected behavior

OCGV not to skip

Actual behavior

occasionally OCGV exits without allowing you to select anything

Error details

Exception             : 
    Type        : System.Management.Automation.RuntimeException
    ErrorRecord : 
        Exception             : 
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : You cannot call a method on a null-valued expression.
            HResult : -2146233087
        CategoryInfo          : InvalidOperation: (:) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : InvokeMethodOnNull
        InvocationInfo        : 
            ScriptLineNumber : 3
            OffsetInLine     : 1
            HistoryId        : -1
            Line             : $platform.name.split()
                               
            PositionMessage  : At line:3 char:1
                               + $platform.name.split()
                               + ~~~~~~~~~~~~~~~~~~~~~~
            CommandOrigin    : Internal
        ScriptStackTrace      : at <ScriptBlock>, <No file>: line 3
    TargetSite  : System.Object CallSite.Target(System.Runtime.CompilerServices.Closure, 
System.Runtime.CompilerServices.CallSite, System.Object)
    Message     : You cannot call a method on a null-valued expression.
    Data        : System.Collections.ListDictionaryInternal
    Source      : Anonymously Hosted DynamicMethods Assembly
    HResult     : -2146233087
    StackTrace  : 
   at CallSite.Target(Closure , CallSite , Object )
   at System.Management.Automation.Interpreter.DynamicInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
CategoryInfo          : InvalidOperation: (:) [], RuntimeException
FullyQualifiedErrorId : InvokeMethodOnNull
InvocationInfo        : 
    ScriptLineNumber : 3
    OffsetInLine     : 1
    HistoryId        : -1
    Line             : $platform.name.split()
                       
    PositionMessage  : At line:3 char:1
                       + $platform.name.split()
                       + ~~~~~~~~~~~~~~~~~~~~~~
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 3

Environment data

Name                           Value
----                           -----
PSVersion                      7.2.6
PSEdition                      Core
GitCommitId                    7.2.6
OS                             Darwin 21.6.0 Darwin Kernel Version 21.6.0: Wed Aug 10 14:28:23 PDT 2022; root:xnu-8020.141.5~2…
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Version

0.6.3

Visuals

Screen Recording 2022-08-21 at 21 49 08

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:30

github_iconTop GitHub Comments

1reaction
Tigger2014commented, Aug 27, 2022

Yep did that and can confirm this fixes it

1reaction
tznindcommented, Aug 26, 2022

Found these docs (see below) on the feature I think you are talking about @BDisp. Looks like you can change the setting at runtime with an Environment Variable e.g.

export ESCDELAY=1

Set time taken to release an Escape keystroke to 1ms

I tested setting it to 2000 and saw Esc being delayed so it seems to work.

Although from the docs docs it sounds like the same setting interacts with mouse events:

Environment

The following environment symbols are useful for customizing the runtime behavior of the ncurses library. The most important ones have been already discussed in detail.

[…]

ESCDELAY Specifies the total time, in milliseconds, for which ncurses will await a character sequence, e.g., a function key. The default value, 1000 milliseconds, is enough for most uses. However, it is made a variable to accommodate unusual applications. The most common instance where you may wish to change this value is to work with slow hosts, e.g., running on a network. If the host cannot read characters rapidly enough, it will have the same effect as if the terminal did not send characters rapidly enough. The library will still see a timeout.

Note that xterm mouse events are built up from character sequences received from the xterm. If your application makes heavy use of multiple-clicking, you may wish to lengthen this default value because the timeout applies to the composed multi-click event as well as the individual clicks.

In addition to the environment variable, this implementation provides a global variable with the same name. Portable applications should not rely upon the presence of ESCDELAY in either form, but setting the environment variable rather than the global variable does not create problems when compiling an application.

_https://linux.die.net/man/3/ncurses_

Read more comments on GitHub >

github_iconTop Results From Across the Web

pressing arrow key when editing code cell sometimes ...
By doing so, the arrow keys start functioning properly. I hope this solution proves helpful in your situation.
Read more >
Arrow key acts as it's pressed up only on windows ...
In Command prompt type sfc /scannow and press enter. Restart the computer. If that doesn't work then try this,
Read more >
Computer has right arrow key constantly 'held down'
This may be due to 'sticky keys'. Press shift five or more times, then open the underlined thing, and uncheck all. Click Apply...
Read more >
ncurses: program exiting when arrow key pressed
my question is exactly as the title says. My program exits right after I press an arrow up. Here's my program: pub fn...
Read more >
How do I stop the "[A" showing sometimes when I press ...
If you e.g. run sleep 3 and then press Up Arrow, you'll get ^[[A , which will get to Bash as the arrow...
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