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
Ability to capture signals in PowerShell #8975
Comments
Perhaps @PaulHigin could weight this. It could be useful on Unix. Not clear about Windows. Not clear about portability. |
Question: does Windows have some sort of API that could handle this? |
Currently PowerShell Core to work with console uses Windows API on Windows and .Net Core API on Unix. So it is not easy to address your question. |
Signal handling might warrant an RFC because there are interesting design choices - map to exceptions or an event handler. Windows does have an api to report when the console is resized, but it is somewhat painful to use, see this example. If you go this route, you need to handle keyboard events that are handled by apis like |
H'm... Well, the venerable Windows API is, by definition, painful to use. Hundreds of different type of strings. Its almost as if win32 was designed to be painful to use. |
The console application in Windows usually does not need to worry about resizing the window. Another thing is WinForms... |
I would appreciate it then, if you could tell me what to do in this case. I can't really think of any other way around this. I am drawing lines of text three lines before the bottom of the screen. I need a way to clear those lines and re-draw them at the bottom of the console when the console is resized. I cannot implement this until I have a way to know when the console is resized. I suppose I'll just have to write a C program that'll call the appropriate API's and do it for me. But then I'll have to mess around with - God help me - So I guess I'll just put this off until I find a better way. *sigh* |
@kiedtl It is PowerShell Core repo. I can only say that PowerShell Core is probably not right tool for your task. But if you need PowerShell Core perhaps you have to re-design your application. |
I just remembered - wouldn't it be easy to use a If PowerShell is running on Unix, You could just throw a I suppose that this issue is for the |
It is implementation details. As I said above we should be full portable and should avoid
Feel free to discuss there if you have usecase. |
@iSazonov - a console application with a TUI has a definite need to handle window resize events - it's a problem that I never fully addressed in PSReadLIne because of the difficulty (initially) and the lack of portability (later). Now should people write console applications in PowerShell? .Net? I'd say yes, it seems reasonable. |
@lzybkr isn't this kind of already done by |
I don't know if WriteProgress is such a good example. Works kinda shaky. |
It's true, it's not perfect. But it does do this, to some extent. 😄 |
@lzybkr Perhaps I was not clear. I said about regular cases - most of console applications (and scripts too) is very simple. (For PowerShell all needed output features should be addresed by conhost/formatting system) PSReadline is heavy application and edge case. If it were a frequent case, I believe MSFT team would have addressed this a long time ago. I see that MSFT is actively developing a new console on Windows 10. We could ask them for the necessary enhancements. But I can’t imagine how it could be ported. But why not (if MSFT go to convergence)? |
Isn't there a way to do that on Unix too? I mean, how does |
@kiedtl I think it is question for MSFT console team - perhaps they could find way to port the API. |
Alright. |
I'd like to keep the issue open - it does make sense to support signals in a general way. I agree console resize events are not in scope for PowerShell. |
This issue has been marked as answered and has not had any activity for 1 day. It has been closed for housekeeping purposes. |
In bash, you have the feature of trapping signals (such as EXIT and SIGWINCH) and executing a series of statements when those signals are received. E.G.
I am aware other ways a ctrl-c event could be handled, but I'm trying to handle a SIGWINCH and to the best of my knowledge there is currently no way to do this in PowerShell.
Such functionality could easily be provided by a .NET event handler, or by a cmdlet, using the Windows API (I'm not familiar with win32, so I'm in the dark on how exactly this could be accomplished).
The text was updated successfully, but these errors were encountered: