Skip to content
This repository has been archived by the owner on Oct 22, 2019. It is now read-only.

change console modes for raw screen #3

Closed
wants to merge 4 commits into from
Closed

change console modes for raw screen #3

wants to merge 4 commits into from

Conversation

3kyro
Copy link

@3kyro 3kyro commented Sep 28, 2019

As described in crossterm-rs/crossterm#250, this change aims to replicate UNIX "raw" screen in windows console.

@TimonPost
Copy link
Member

@TimonPost
Copy link
Member

I ran this example:

// cargo run --example raw_mode
fn main() -> Result<()> {
    let _alt = RawScreen::into_raw_mode()?;
    for i in 0..10 {
        println!("some input");
    }

    Ok(())
}

Results:
linux
image

windows
image

It still looks like they differ somehow. The new line is interpreted differently on windows and linux.

@3kyro
Copy link
Author

3kyro commented Oct 8, 2019

I can confirm the same behavior when I try to replicate the "raw" mode flags from here.

impl RawModeCommand {
    pub fn new() -> Self {
        RawModeCommand {
            mask: ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT, 
        }
    }
}

impl RawModeCommand {
    /// Enables raw mode.
    pub fn enable(&mut self) -> Result<()> {
        let console_mode = ConsoleMode::from(Handle::input_handle()?);
    
        let mut dw_mode = console_mode.mode()?;

        // enabling these three
        let ENABLE_EXTENDED_FLAGS = 0x0080;
        let ENABLE_INSERT_MODE = 0x0020;
        let ENABLE_QUICK_EDIT_MODE = 0x0040;

        dw_mode |= ENABLE_EXTENDED_FLAGS;
        dw_mode |= ENABLE_INSERT_MODE;
        dw_mode |= ENABLE_QUICK_EDIT_MODE;

        // disabling the mask
        let new_mode = dw_mode & !self.mask;

        console_mode.set_mode(new_mode)?;

        Ok(())
    }

Looks like, to me at least, that the UNIX raw behavior cannot be duplicated in windows console only with the use of flags.

@zrzka
Copy link
Contributor

zrzka commented Oct 17, 2019

Any progress on this PR? This is the last problem which needs to be solved before we proceed with the merge. Would be nice to have it fixed somehow or if there's a problem we can't solve, we don't know how, there's also a possibility to withdraw this issue from the list of issues we have to solve before merge. I'm afraid I can't help here, Linux/macOS only, just asking.

@TimonPost
Copy link
Member

TimonPost commented Oct 17, 2019

I am not how to go about mimicking the exact Linux behavior. The console modes are somewhat the same now however the new line behaves a bit different (as shown above).

I know of the following libraries trying to do the same thing as we do here, maybe we can take a look over there:

  1. https://github.com/containerd/console/blob/master/console_windows.go#L173
  2. https://gitlab.redox-os.org/Jezza/termion/blob/windows-support/src/sys/windows/attr.rs#L45
  3. https://github.com/murarth/mortal/blob/master/src/windows/terminal.rs#L360

@TimonPost
Copy link
Member

I also spoke about raw modes issue in discord with some people, it seems like it is impossible or very difficult to sync output to be the exact same on both Windows and Linux. The flags we are currently disabling are right.

What we see now is that println! isn't working. Which is obvious because line wraps are disabled in raw modes.

I propose to merge the PR, update the readme, or docstrings and add the notice that When using raw modes the user should only use write! because println! doesn't make much sense here. Because you're trying to use something you just disabled.

@TimonPost TimonPost mentioned this pull request Oct 18, 2019
@TimonPost
Copy link
Member

TimonPost commented Oct 18, 2019

I have moved your commits over to this PR, I fixed the build and changed documentation to make clear what can be expected by raw modes.

@TimonPost TimonPost closed this Oct 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants