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.

The predictive suggestion feature cannot be enabled

See original GitHub issue

Hi,

How avoid this warning with PSReadLine and predictionsource ?

Environment

PS version: 5.1.19041.610
PSReadline version: 2.1.0
os: 10.0.19041.561 (WinBuild.160101.0800)
PS file version: 10.0.19041.561 (WinBuild.160101.0800)
HostName: ConsoleHost (Windows Terminal)
BufferWidth: 120
BufferHeight: 30

Modules :

image

Exception report

Some script throw error like flutter for example :

image

Or minikube :

image

This error can stop script execution…

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
WojciechNagorskicommented, Apr 27, 2023

The profile file should look:

function IsVirtualTerminalProcessingEnabled {
	$MethodDefinitions = @'
[DllImport("kernel32.dll", SetLastError = true)]
public static extern IntPtr GetStdHandle(int nStdHandle);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint lpMode);
'@
	$Kernel32 = Add-Type -MemberDefinition $MethodDefinitions -Name 'Kernel32' -Namespace 'Win32' -PassThru
	$hConsoleHandle = $Kernel32::GetStdHandle(-11) # STD_OUTPUT_HANDLE
	$mode = 0
	$Kernel32::GetConsoleMode($hConsoleHandle, [ref]$mode) >$null
	if ($mode -band 0x0004) { # 0x0004 ENABLE_VIRTUAL_TERMINAL_PROCESSING
		return $true
	}
	return $false
}

function CanUsePredictionSource {
	return (! [System.Console]::IsOutputRedirected) -and (IsVirtualTerminalProcessingEnabled)
}

if (CanUsePredictionSource){ 
  Import-Module -Name Terminal-Icons
  Import-Module PSReadLine
  Set-PSReadLineOption -PredictionViewStyle ListView -PredictionSource History -HistoryNoDuplicates
}

1reaction
EArminjoncommented, Apr 27, 2023

The profile file should look:

function IsVirtualTerminalProcessingEnabled {
	$MethodDefinitions = @'
[DllImport("kernel32.dll", SetLastError = true)]
public static extern IntPtr GetStdHandle(int nStdHandle);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint lpMode);
'@
	$Kernel32 = Add-Type -MemberDefinition $MethodDefinitions -Name 'Kernel32' -Namespace 'Win32' -PassThru
	$hConsoleHandle = $Kernel32::GetStdHandle(-11) # STD_OUTPUT_HANDLE
	$mode = 0
	$Kernel32::GetConsoleMode($hConsoleHandle, [ref]$mode) >$null
	if ($mode -band 0x0004) { # 0x0004 ENABLE_VIRTUAL_TERMINAL_PROCESSING
		return $true
	}
	return $false
}

function CanUsePredictionSource {
	return (! [System.Console]::IsOutputRedirected) -and (IsVirtualTerminalProcessingEnabled)
}

if (CanUsePredictionSource){ 
  Import-Module -Name Terminal-Icons
  Import-Module PSReadLine
  Set-PSReadLineOption -PredictionViewStyle ListView -PredictionSource History -HistoryNoDuplicates
}

Ty 😉 !

Read more comments on GitHub >

github_iconTop Results From Across the Web

PSReadLine history doesn't load
The history suggestions start showing up. I close the terminal ps, open it again, no history suggestions there until i run the command...
Read more >
Set-PSReadLineOption (PSReadLine) - PowerShell
Specifies the source for PSReadLine to get predictive suggestions. Valid values are: None - disable the predictive IntelliSense feature (default). History - ...
Read more >
7 Quick Fixes for Predictive Emoji Not Working on an ...
Now, make sure the Predictive function is enabled. Go back to Settings > General > Keyboard, then scroll down and enable the Predictive...
Read more >
Installing and setting up PowerShell PSReadline with ...
When trying to enable the predictions Set-PSReadLineOption -PreditionSource History I received this error: Set-PSReadLineOption : A parameter ...
Read more >
Adding Predictive IntelliSense to my Windows Terminal ...
Adding Predictive IntelliSense to my Windows Terminal PowerShell Prompt with PSReadline.
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