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

inconsistent reporting of ^Enter #508

Closed
pm100 opened this issue Nov 6, 2020 · 7 comments
Closed

inconsistent reporting of ^Enter #508

pm100 opened this issue Nov 6, 2020 · 7 comments

Comments

@pm100
Copy link

pm100 commented Nov 6, 2020

on version 0.18 with raw mode enabled

If I type Ctrl+Enter

  • on windows I get Key = enter, mods = ctrl
  • on linux I get key = j, Mods = ctrl

The linux one seems wrong

@pm100 pm100 closed this as completed Nov 6, 2020
@pm100 pm100 reopened this Nov 6, 2020
@pm100
Copy link
Author

pm100 commented Nov 6, 2020

test app - using doc sample

use crossterm::event::{read, Event};

fn print_events() -> crossterm::Result<()> {
    loop {
        // `read()` blocks until an `Event` is available
        match read()? {
            Event::Key(event) => println!("{:?}", event),
            Event::Mouse(event) => println!("{:?}", event),
            Event::Resize(width, height) => println!("New size {}x{}", width, height),
        }
    }
    Ok(())
}

fn main(){
    crossterm::terminal::enable_raw_mode();
    print_events();
}

run this on linux and go ctrl+enter
image

on windows

image

note, on linux ctrl+j is also reported as ctrl+j

@imsnif
Copy link

imsnif commented Nov 7, 2020

Can confirm, same here.

@imsnif
Copy link

imsnif commented Nov 7, 2020

Found the issue. For me this happened because of this line: https://github.com/crossterm-rs/crossterm/blob/master/src/event/sys/unix/parse.rs#L76

I was in raw mode, but didn't use crossterm to enter raw mode (I was using tcsetattr from termios). Crossterm was checking its own internal state to see whether I was in raw mode and that's why this issue happened.

EDIT: to fix this, I used crossterm::terminal::enable_raw_mode instead nof the tcsetattr.

@TimonPost
Copy link
Member

TimonPost commented Nov 7, 2020

@pm100 I tried it on a tmate terminal and I don't seem to get the CTRL + J, but the ENTER without CTRL. Perhaps you can trie what @imsnif proposed?

@pm100
Copy link
Author

pm100 commented Nov 7, 2020

@TimonPost what is he suggesting? In my code I used what he suggests

@TimonPost
Copy link
Member

Enabling raw modes? What terminal are you using on Linux?

@TimonPost
Copy link
Member

TimonPost commented Jun 30, 2022

Closing in favor of #685.

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

No branches or pull requests

3 participants