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

mintty read_key fails with "Incorrect function" #35

Open
EdenEast opened this issue Oct 13, 2019 · 11 comments
Open

mintty read_key fails with "Incorrect function" #35

EdenEast opened this issue Oct 13, 2019 · 11 comments

Comments

@EdenEast
Copy link

use console::Term;
fn main() {
    let term = Term::stdout();
    let result = term.read_key();
    match result {
        Ok(k) => println!("Key: {:?}", k),
        Err(e) => println!("Error: {:?}", e),
    };
}

Running this code using mintty. Ran this code using msys and mingw. When running though the integrated terminal in visual studio code the code passes. When running it on mintty it fails with the line

Error: Os { code: 1, kind: Other, message: "Incorrect function." }

@mitsuhiko
Copy link
Collaborator

I would need help tracking this down. I'm not using mintty myself.

@MichaelMcDonnell
Copy link

This issue is the root cause of mitsuhiko/insta#79.

@MichaelMcDonnell
Copy link

MichaelMcDonnell commented Nov 3, 2019

It's the call to ReadConsoleInputW in the read_key_event function in the file windows_term.rs that fails. I tried adding a println! inside the branch that handles success being 0, and that's the last thing I see before the error message.

Maybe the problem is that windows_term is used instead of unix_term? Just saw that windows_termalso handles MSYS.

@MichaelMcDonnell
Copy link

The root cause seems to be mintty/mintty#906?

@mitsuhiko
Copy link
Collaborator

I wonder if the msys detection does not work here. This is how we detect msys currently: https://github.com/mitsuhiko/console/blob/d35ce3e524106bb3c05e9747c8e41408bc073663/src/windows_term.rs#L334-L362

@MichaelMcDonnell
Copy link

MichaelMcDonnell commented Nov 21, 2019

The code seems correct to me? I printed the name and got \msys-1888ae32e00d56aa-pty0-to-master. The function msys_tty_on returns true. That is what is expected right?

UPDATE: Forgot to mention I'm running C:\Program Files\Git\bin\git-bash.exe, so it might work differently. Btw. if I run bash straight from C:\Program Files\Git\bin\bash.exe then it works fine.

@MichaelMcDonnell
Copy link

MichaelMcDonnell commented Nov 22, 2019

It seems like git-bash.exe is redirecting the standard input. I added the following lines in get_stdin_handle:

let file_type = unsafe { winapi::um::fileapi::GetFileType(handle) };
println!("file_type is {}", file_type);

It prints 3 when I use git-bash.exe and 2 when I use bash.exe or cmd.exe. The three is FILE_TYPE_PIPE which means the input has been redirected. Maybe the ReadConsoleInput function doesn't work with redirected input?

@mitsuhiko
Copy link
Collaborator

Would be happy to merge a fix if someone has one. I'm not using git-bash myself.

@rafamerlin
Copy link

So, one workaround that should work on mingw64 is to use winpty.

So let's say the app you have which uses this library is called test

So you run winpty test + any arguments
If you want to keep it permanent you can just create an alias in .bashrc file and you can just call it directly.

dtolnay pushed a commit to dtolnay-contrib/console that referenced this issue Feb 4, 2022
This PR delays the formatting of the fields and instead
stores them on the `Task` struct. This allows for nicer formatting
options. Currently we just bold the field names in the task tables view.

fix console-rs#33

Signed-off-by: Zahari Dichev <zaharidichev@gmail.com>
@mitsuhiko
Copy link
Collaborator

I would still like to fix this issue but as mentioned I do not use mintty. If someone is, help would really be appreciated here.

@Lemminkyinen
Copy link

I would still like to fix this issue but as mentioned I do not use mintty. If someone is, help would really be appreciated here.

I am occasionally using git-bash.exe and with it "Incorrect function" error is happening. What information would help you to fix the issue?

TERM: xterm, MSYSTEM: "MINGW64"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants