-
Notifications
You must be signed in to change notification settings - Fork 88
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
Windows: Call update_window_size when the console is resized #32
Comments
I'm no expert on windows console APIs, but after a bit of googling this is what I found: According to https://docs.microsoft.com/en-us/windows/console/console-input-buffer#buffer-resizing-events
When we look at that mode in https://docs.microsoft.com/en-us/windows/console/setconsolemode it says:
And a cursory glance at std seems to indicate it is using ReadConsoleW (https://github.com/rust-lang/rust/blob/ebc03f7c80a7ab8cdf95c0ddc31b57e065906a13/library/std/src/sys/windows/stdio.rs#L220) By briefly looking at kibi, it seems to be reading stdin using std (https://github.com/ilai-deutel/kibi/blob/master/src/editor.rs#L216) so we might have to replicate the std behaviour here using ReadConsoleInput instead for windows which involves utf16->utf8, and it is also "fixing up surrogates" I have not really actually tested any of this much yet, if/when I do I will comment here EDIT: There is an example of reading console input buffer events here Once the ReadConsoleInput vs ReadConsole issue is solved it seems we would just need to check for https://docs.rs/winapi/0.3.9/winapi/um/wincontypes/constant.WINDOW_BUFFER_SIZE_EVENT.html Maybe we could keep the stdin reading code the same and instead just use PeekConsoleInput (https://docs.microsoft.com/en-us/windows/console/peekconsoleinput) before reading stdin just to check for resize events, but I think we'd need to use a buffer size big enough to somehow ensure std does not consume more events than we have picked |
I've got a proof of concept of the peeking approach here: nico-abram@434b355 (loc change here is 997 => 1007) Would have to dig around std to make sure a buffer of 1024 events is enough to ensure we never peek less events than std reads, but the bigger issue is it seems setting the mode to ENABLE_WINDOW_INPUT broke the way kibi was detecting ctrl |
Actually, I accidentally set the mode to ECHO above which was why it seemed to work, my apologies Naively peeking does't work properly since the next() call to the stdin bytes iterator seems to block, so I'm peeking an empty buffer and then missing all the events until a key is in the input buffer. Perhaps it could block before peeking until a key is found to try to ensure we don't miss any events |
Windows 7, kibi 0.2.2 $ kibi
Error: Io(Os { code: 87, kind: InvalidInput, message: "The parameter is incorrect." })
$ kibi --help
Error: Io(Os { code: 87, kind: InvalidInput, message: "The parameter is incorrect." })
$ kibi hello.txt
Error: Io(Os { code: 87, kind: InvalidInput, message: "The parameter is incorrect." }) |
@sergeevabc Unfortunately kibi is not compatible with Windows 7, only Windows 10 version 1703 (Creators Update, April 2017) and above are supported. |
On UNIX platforms, we call
update_window_size
when aSIGWINCH
signal is received.Similarly, we should update the window size on Windows when the console is resized.
The text was updated successfully, but these errors were encountered: