Skip to content
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

execute handler #3900

Closed
1 task done
steve02081504 opened this issue Dec 13, 2023 · 1 comment
Closed
1 task done

execute handler #3900

steve02081504 opened this issue Dec 13, 2023 · 1 comment
Labels
Issue-Enhancement It's a feature request. Resolution-Declined The enhancement request is declined.

Comments

@steve02081504
Copy link

steve02081504 commented Dec 13, 2023

Prerequisites

  • Write a descriptive title.

Description of the new feature/enhancement

I want my pwsh to store the return value of a command in the global variable $ans after running the command.
I've searched high and low for a way to implement it and it looks like the only way is Set-PSReadLineKeyHandler -Key Enter.
And I can't just modify the buffer and call AcceptLine in the EnterKeyHandler, because that would change what's already on the screen. I had to do my own expression evaluation via Invoke-Expression, then record the start and end times, build a structure to pass to Add-History, catch exceptions, and apply a loop to handle the possibility of multiple lines of input......
I'm almost on the verge of handwriting another AcceptLine implementation!
And all I want to do is add a bit of custom logic to the execution of the input.

I would like to add a new handler for additional processing of expressions after AcceptLine has been called without modifying the content on the screen (or taking over the execution process and returning the value)

This might simplify a lot of customisation requirements

Proposed technical implementation details (optional)

Add-PSReadLineExecuteHandler -ScriptBlock {
	prarm($expr)
	"`$global:ans=($expr)"
}
# or
Add-PSReadLineExecuteResultHandler -ScriptBlock {
	prarm($result)
	$global:ans=$result
	$result
}
@steve02081504 steve02081504 added the Issue-Enhancement It's a feature request. label Dec 13, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Triage 🔍 It's a new issue that core contributor team needs to triage. label Dec 13, 2023
@daxian-dbw daxian-dbw added Issue-Enhancement It's a feature request. Resolution-Declined The enhancement request is declined. and removed Issue-Enhancement It's a feature request. labels Jan 31, 2024
@daxian-dbw
Copy link
Member

We are not going to add a handler like this in PSReadLine.
PowerShell team has been investigating a way to allow user to be able to capture output from native commands, by utilizing PTY, but no ETA for it. If you want to capture output from cmdlets, then see if $PSDefaultParameterValues could be helpful, for example, by setting $PSDefaultParameterValues = @{"*:OutVariable"=myvar}.

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs-Triage 🔍 It's a new issue that core contributor team needs to triage. label Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Enhancement It's a feature request. Resolution-Declined The enhancement request is declined.
Projects
None yet
Development

No branches or pull requests

2 participants