fn enable_raw_mode(&mut self) -> Result<(ConsoleMode, ConsoleKeyMap)> {
        if !self.conin_isatty {
            Err(io::Error::new(
                io::ErrorKind::Other,
                "no stdio handle available for this process",
            ))?;
        }
        let original_conin_mode = get_console_mode(self.conin)?;
        // Disable these modes
        let mut raw = original_conin_mode
            & !(wincon::ENABLE_LINE_INPUT
                | wincon::ENABLE_ECHO_INPUT
                | wincon::ENABLE_PROCESSED_INPUT);
        // Enable these modes
        raw |= wincon::ENABLE_EXTENDED_FLAGS;
        raw |= wincon::ENABLE_INSERT_MODE;
        raw |= wincon::ENABLE_QUICK_EDIT_MODE;
        raw |= wincon::ENABLE_WINDOW_INPUT;

        let original_conout_mode = if self.conout_isatty {
            let original_conout_mode = get_console_mode(self.conout)?;

            let mut mode = original_conout_mode;
            if mode & wincon::ENABLE_WRAP_AT_EOL_OUTPUT == 0 {
                mode |= wincon::ENABLE_WRAP_AT_EOL_OUTPUT;
                debug!(target: "rustyline", "activate ENABLE_WRAP_AT_EOL_OUTPUT");
                unsafe {
                    assert_ne!(consoleapi::SetConsoleMode(self.conout, mode), 0);
                }
            }
            // To enable ANSI colors (Windows 10 only):
            // https://docs.microsoft.com/en-us/windows/console/setconsolemode
            self.ansi_colors_supported = mode & wincon::ENABLE_VIRTUAL_TERMINAL_PROCESSING != 0;
            if self.ansi_colors_supported {
                if self.color_mode == ColorMode::Disabled {
                    mode &= !wincon::ENABLE_VIRTUAL_TERMINAL_PROCESSING;
                    debug!(target: "rustyline", "deactivate ENABLE_VIRTUAL_TERMINAL_PROCESSING");
                    unsafe {
                        assert_ne!(consoleapi::SetConsoleMode(self.conout, mode), 0);
                    }
                } else {
                    debug!(target: "rustyline", "ANSI colors already enabled");
                }
            } else if self.color_mode != ColorMode::Disabled {
                mode |= wincon::ENABLE_VIRTUAL_TERMINAL_PROCESSING;
                self.ansi_colors_supported =
                    unsafe { consoleapi::SetConsoleMode(self.conout, mode) != 0 };
                debug!(target: "rustyline", "ansi_colors_supported: {}", self.ansi_colors_supported);
            }
            if self.ansi_colors_supported && self.enable_bracketed_paste {
                raw |= wincon::ENABLE_VIRTUAL_TERMINAL_INPUT;
                write_all(self.conout, escape::BRACKETED_PASTE_ON)?;
                debug!(target: "rustyline", "Turned bracketed paste on");
            }
            Some(original_conout_mode)
        } else {
            None
        };

        self.raw_mode.store(true, Ordering::SeqCst);
        // when all ExternalPrinter are dropped there is no need to use `pipe_reader`
        if Arc::strong_count(&self.raw_mode) == 1 {
            self.pipe_writer = None;
            self.pipe_reader = None;
        }
        check(unsafe { consoleapi::SetConsoleMode(self.conin, raw) })?;

        Ok((
            ConsoleMode {
                original_conin_mode,
                conin: self.conin,
                original_conout_mode,
                conout: self.conout,
                raw_mode: self.raw_mode.clone(),
            },
            (),
        ))
    }
/// Enable RAW mode for the terminal.
Enable RAW mode for the terminal.
Enable RAW mode for the terminal .
fn enable_raw_mode(&mut self) -> Result<(ConsoleMode, ConsoleKeyMap)> {
        if !self.conin_isatty {
            Err(io::Error::new(
                io::ErrorKind::Other,
                "no stdio handle available for this process",
            ))?;
        }
        let original_conin_mode = get_console_mode(self.conin)?;
        // Disable these modes
        let mut raw = original_conin_mode
            & !(wincon::ENABLE_LINE_INPUT
                | wincon::ENABLE_ECHO_INPUT
                | wincon::ENABLE_PROCESSED_INPUT);
        // Enable these modes
        raw |= wincon::ENABLE_EXTENDED_FLAGS;
        raw |= wincon::ENABLE_INSERT_MODE;
        raw |= wincon::ENABLE_QUICK_EDIT_MODE;
        raw |= wincon::ENABLE_WINDOW_INPUT;
        let original_conout_mode = if self.conout_isatty {
            let original_conout_mode = get_console_mode(self.conout)?;
            let mut mode = original_conout_mode;
            if mode & wincon::ENABLE_WRAP_AT_EOL_OUTPUT == 0 {
                mode |= wincon::ENABLE_WRAP_AT_EOL_OUTPUT;
                debug!(target: "rustyline", "activate ENABLE_WRAP_AT_EOL_OUTPUT");
                unsafe {
                    assert_ne!(consoleapi::SetConsoleMode(self.conout, mode), 0);
                }
            }
            // To enable ANSI colors (Windows 10 only):
            // https://docs.microsoft.com/en-us/windows/console/setconsolemode
            self.ansi_colors_supported = mode & wincon::ENABLE_VIRTUAL_TERMINAL_PROCESSING != 0;
            if self.ansi_colors_supported {
                if self.color_mode == ColorMode::Disabled {
                    mode &= !wincon::ENABLE_VIRTUAL_TERMINAL_PROCESSING;
                    debug!(target: "rustyline", "deactivate ENABLE_VIRTUAL_TERMINAL_PROCESSING");
                    unsafe {
                        assert_ne!(consoleapi::SetConsoleMode(self.conout, mode), 0);
                    }
                } else {
                    debug!(target: "rustyline", "ANSI colors already enabled");
                }
            } else if self.color_mode != ColorMode::Disabled {
                mode |= wincon::ENABLE_VIRTUAL_TERMINAL_PROCESSING;
                self.ansi_colors_supported =
                    unsafe { consoleapi::SetConsoleMode(self.conout, mode) != 0 };
                debug!(target: "rustyline", "ansi_colors_supported: {}", self.ansi_colors_supported);
            }
            if self.ansi_colors_supported && self.enable_bracketed_paste {
                raw |= wincon::ENABLE_VIRTUAL_TERMINAL_INPUT;
                write_all(self.conout, escape::BRACKETED_PASTE_ON)?;
                debug!(target: "rustyline", "Turned bracketed paste on");
            }
            Some(original_conout_mode)
        } else {
            None
        };
        self.raw_mode.store(true, Ordering::SeqCst);
        // when all ExternalPrinter are dropped there is no need to use `pipe_reader`
        if Arc::strong_count(&self.raw_mode) == 1 {
            self.pipe_writer = None;
            self.pipe_reader = None;
        }
        check(unsafe { consoleapi::SetConsoleMode(self.conin, raw) })?;
        Ok((
            ConsoleMode {
                original_conin_mode,
                conin: self.conin,
                original_conout_mode,
                conout: self.conout,
                raw_mode: self.raw_mode.clone(),
            },
            (),
        ))
    }
fn enable_raw_mode ( & mut self ) -> Result < ( ConsoleMode , ConsoleKeyMap ) > { if ! self . conin_isatty { Err ( io :: Error :: new ( io :: ErrorKind :: Other , " " , ) ) ? ; } let original_conin_mode = get_console_mode ( self . conin ) ? ; // Disable these modes let mut raw = original_conin_mode & ! ( wincon :: ENABLE_LINE_INPUT | wincon :: ENABLE_ECHO_INPUT | wincon :: ENABLE_PROCESSED_INPUT ) ; // Enable these modes raw |= wincon :: ENABLE_EXTENDED_FLAGS ; raw |= wincon :: ENABLE_INSERT_MODE ; raw |= wincon :: ENABLE_QUICK_EDIT_MODE ; raw |= wincon :: ENABLE_WINDOW_INPUT ; let original_conout_mode = if self . conout_isatty { let original_conout_mode = get_console_mode ( self . conout ) ? ; let mut mode = original_conout_mode ; if mode & wincon :: ENABLE_WRAP_AT_EOL_OUTPUT == 0 { mode |= wincon :: ENABLE_WRAP_AT_EOL_OUTPUT ; debug ! ( target " " " " ) ; unsafe { assert_ne ! ( consoleapi SetConsoleMode ( self conout mode ) 0 ) ; } } // To enable ANSI colors (Windows 10 only): // https://docs.microsoft.com/en-us/windows/console/setconsolemode self . ansi_colors_supported = mode & wincon :: ENABLE_VIRTUAL_TERMINAL_PROCESSING != 0 ; if self . ansi_colors_supported { if self . color_mode == ColorMode :: Disabled { mode &= ! wincon :: ENABLE_VIRTUAL_TERMINAL_PROCESSING ; debug ! ( target " " " " ) ; unsafe { assert_ne ! ( consoleapi SetConsoleMode ( self conout mode ) 0 ) ; } } else { debug ! ( target " " " " ) ; } } else if self . color_mode != ColorMode :: Disabled { mode |= wincon :: ENABLE_VIRTUAL_TERMINAL_PROCESSING ; self . ansi_colors_supported = unsafe { consoleapi :: SetConsoleMode ( self . conout , mode ) != 0 } ; debug ! ( target " " " " self ansi_colors_supported ) ; } if self . ansi_colors_supported && self . enable_bracketed_paste { raw |= wincon :: ENABLE_VIRTUAL_TERMINAL_INPUT ; write_all ( self . conout , escape :: BRACKETED_PASTE_ON ) ? ; debug ! ( target " " " " ) ; } Some ( original_conout_mode ) } else { None } ; self . raw_mode . store ( true , Ordering :: SeqCst ) ; // when all ExternalPrinter are dropped there is no need to use `pipe_reader` if Arc :: strong_count ( & self . raw_mode ) == 1 { self . pipe_writer = None ; self . pipe_reader = None ; } check ( unsafe { consoleapi :: SetConsoleMode ( self . conin , raw ) } ) ? ; Ok ( ( ConsoleMode { original_conin_mode , conin : self . conin , original_conout_mode , conout : self . conout , raw_mode : self . raw_mode . clone ( ) , } , ( ) , ) ) }
Enable RAW mode for the terminal.
Enable RAW mode for the terminal .
&mut self
&mut self