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

Sync raw mode behavior #250

Closed
1 task
TimonPost opened this issue Sep 23, 2019 · 6 comments · Fixed by crossterm-rs/crossterm-screen#8
Closed
1 task

Sync raw mode behavior #250

TimonPost opened this issue Sep 23, 2019 · 6 comments · Fixed by crossterm-rs/crossterm-screen#8

Comments

@TimonPost
Copy link
Member

TimonPost commented Sep 23, 2019

The terminal raw mode does not function the same on UNIX and Windows. I tried to find resources to figure out which flags to turn on or turn of. However, it is is not the same yet.

Task

Related

@3kyro
Copy link

3kyro commented Sep 28, 2019

Checking the windows console documentation I believe the following can approximate UNIX "raw" screen.

Based on High-Level Console Modes, for an application to be in "raw" mode the following input and output modes need to be disabled:

Input Modes

  • Line input mode
  • Processed input mode
  • Echo input mode

Output Modes

  • Processed output mode
  • Wrapping at EOL output mode

However both the output modes are not applicable for a POSIX like RawScreen.
Processed output mode is:

Used with a console screen buffer handle to cause the system to perform the appropriate action for ANSI control characters that are written to a screen buffer.

and so applicable only for AlternateScreen.

Wrapping at EOL output mode i:

Used with a console screen buffer handle to cause the current output position (cursor position) to move to the first column in the next row (line) when the end of the current row is reached.

Also applicable for an alternate screen; furthermore, this behavior is not present in POSIX "raw" and alternate screen.

For this changes, the ConsoleMode default handle needs to be changed to a HandleType::InputHandle and the RawModeCommand mask needs to be changed to ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT

Tested on Windows 10 Powershell and also appears to solve #214

@TimonPost
Copy link
Member Author

TimonPost commented Sep 28, 2019

Thanks for the research. I will look into this as well and see if it compares to unix functionality

I found some other reference as well
https://github.com/containerd/console/blob/master/console_windows.go#L173

@3kyro
Copy link

3kyro commented Sep 28, 2019

Thanks for looking into it. From my side I have tested in windows 10 Powershell and cmd and the terminal behaves similarly to a Gnome terminal on ubuntu 19.04 and a Ubuntu wls terminal on windows 10.

@TimonPost
Copy link
Member Author

TimonPost commented Sep 28, 2019

Great, so one thing I don't quite understand is why can we just change Output Handle to Input Handle?

@3kyro
Copy link

3kyro commented Sep 29, 2019

That is a good question.

Maybe relevant: SyncReader and AsyncReader::next() seems to behave differently on windows eg:

fn main() {

    let input = input();

    let mut stdin = input.read_sync(); 

    loop {
        if let Some(_) = stdin.next() {
        }    
    }    
}

does not print any characters on a windows terminal although RawScreen is not set. In a linux terminal, input characters are echoed as expected (and InputEvents are all sent together after \n)

input.read_char() behaves as expected

@3kyro
Copy link

3kyro commented Sep 29, 2019

Cursor position is reported differently between windows and Linux. In windows, cursor position is given from the start of the screen buffer, while for Linux its given in relation to current window. For example, in windows console (PowerShell an cmd) cursor.pos().1 will increment as the terminal scrolls down, while in gnome terminal it stays constant.

Interestingly, in the integrated terminal of vscode, this is not the case, and cursor position follows the linux behavior.

Sorry for the spam, but I guess I collect all these small differences here even-though they might not relate to RawScreen. If this is not ok, I can create a new issue.

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

Successfully merging a pull request may close this issue.

2 participants