Giter VIP home page Giter VIP logo

getch-rs's People

Contributors

hellow554 avatar kumavale avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

getch-rs's Issues

Sending ctrl + z doesn't work on windows

I try to send a ctrl + z to sisterm to suspend a running linux process on the other end of the serial line.

But unfortunately the key doesn't go through.
Here's the output of the getch example:

Ctrl('v')
Ctrl('c')
Ctrl('x')
Null <-- should be Ctrl('z')

Do you know, whether that's a limiation of windows?
On linux this works flawlessly.

Get raw bytes of `Key`

Discussed in #12

Originally posted by kumavale September 5, 2023

getch-rs/src/lib.rs

Lines 32 to 75 in 1f1e7fb

pub enum Key {
/// Null byte.
Null,
/// Backspace.
Backspace,
/// Delete key.
Delete,
/// Esc key.
Esc,
/// Up arrow.
Up,
/// Down arrow.
Down,
/// Right arrow.
Right,
/// Left arrow.
Left,
/// End key.
End,
/// Home key.
Home,
/// Backward Tab key.
BackTab,
/// Insert key.
Insert,
/// Page Up key.
PageUp,
/// Page Down key.
PageDown,
/// Function keys.
///
/// Only function keys 1 through 12 are supported.
F(u8),
/// Normal character.
Char(char),
/// Alt modified character.
Alt(char),
/// Ctrl modified character.
///
/// Note that certain keys may not be modifiable with `ctrl`, due to limitations of terminals.
Ctrl(char),
/// Other key.
Other(Vec<u8>),
}

rethink default mode for SetConsoleMode

Currently the previous mode will be used just as it was:

getch-rs/src/lib.rs

Lines 83 to 88 in f0611a2

unsafe {
let input_handle = GetStdHandle(STD_INPUT_HANDLE);
if GetConsoleMode(input_handle, &mut console_mode) != 0 {
SetConsoleMode(input_handle, (console_mode | ENABLE_VIRTUAL_TERMINAL_INPUT) & !ENABLE_LINE_INPUT);
}
}

but I noticed for example, that ctrl + c will not be passed to the application, but instead windows handels it.
This is due ENABLE_PROCESSED_INPUT is set: https://learn.microsoft.com/en-us/windows/console/setconsolemode

I think we should set a reasonable default for the terminal, instead of relying the previous behavior.

I currently can only think of the ENABLE_VIRTUAL_TERMINAL_INPUT as a valid value, all others don't really fit in here.

What do you think?

Get raw bytes of `Key`

getch-rs/src/lib.rs

Lines 32 to 75 in 1f1e7fb

pub enum Key {
/// Null byte.
Null,
/// Backspace.
Backspace,
/// Delete key.
Delete,
/// Esc key.
Esc,
/// Up arrow.
Up,
/// Down arrow.
Down,
/// Right arrow.
Right,
/// Left arrow.
Left,
/// End key.
End,
/// Home key.
Home,
/// Backward Tab key.
BackTab,
/// Insert key.
Insert,
/// Page Up key.
PageUp,
/// Page Down key.
PageDown,
/// Function keys.
///
/// Only function keys 1 through 12 are supported.
F(u8),
/// Normal character.
Char(char),
/// Alt modified character.
Alt(char),
/// Ctrl modified character.
///
/// Note that certain keys may not be modifiable with `ctrl`, due to limitations of terminals.
Ctrl(char),
/// Other key.
Other(Vec<u8>),
}

Make `enable_...` and `disable_...` into one function

Make enable_echo_input() and disable_echo_input() into one function (echo_input(bool)).

getch-rs/src/lib.rs

Lines 158 to 204 in 49919d0

/// Enable local echo
pub fn enable_echo_input() {
#[cfg(windows)]
unsafe {
let input_handle = GetStdHandle(STD_INPUT_HANDLE);
let mut console_mode: DWORD = 0;
if input_handle == INVALID_HANDLE_VALUE {
return;
}
if GetConsoleMode(input_handle, &mut console_mode) != 0 {
SetConsoleMode(input_handle, console_mode | ENABLE_ECHO_INPUT);
}
}
#[cfg(not(windows))]
{
let mut raw_termios = termios::tcgetattr(0).unwrap();
raw_termios.local_flags.insert(termios::LocalFlags::ECHO);
termios::tcsetattr(0, termios::SetArg::TCSADRAIN, &raw_termios).unwrap();
}
}
/// Disable local echo
pub fn disable_echo_input() {
#[cfg(windows)]
unsafe {
let input_handle = GetStdHandle(STD_INPUT_HANDLE);
let mut console_mode: DWORD = 0;
if input_handle == INVALID_HANDLE_VALUE {
return;
}
if GetConsoleMode(input_handle, &mut console_mode) != 0 {
SetConsoleMode(input_handle, console_mode & !ENABLE_ECHO_INPUT);
}
}
#[cfg(not(windows))]
{
let mut raw_termios = termios::tcgetattr(0).unwrap();
raw_termios.local_flags.remove(termios::LocalFlags::ECHO);
termios::tcsetattr(0, termios::SetArg::TCSADRAIN, &raw_termios).unwrap();
}
}

Add nodelay mode

In nodelay mode, if there is no input waiting, None is returned.
In delay mode, the program will hang until the system passes text through to the program.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.