Commit 9e35f915 authored by Jezza's avatar Jezza

Fix formatting.

parent 453879d3
Pipeline #7236 failed with stages
in 54 seconds
use std::{io, mem};
use super::Termios;
use super::crossterm_winapi::{ConsoleMode, Handle};
use super::Termios;
pub fn get_terminal_attr() -> io::Result<Termios> {
let console_mode = ConsoleMode::from(Handle::current_in_handle()?);
let console_mode = ConsoleMode::from(Handle::current_in_handle()?);
let mode = console_mode.mode()?;
let mode = console_mode.mode()?;
Ok(Termios(mode))
Ok(Termios(mode))
}
pub fn set_terminal_attr(termios: &Termios) -> io::Result<()> {
let console_mode = ConsoleMode::from(Handle::current_in_handle()?);
let console_mode = ConsoleMode::from(Handle::current_in_handle()?);
console_mode.set_mode(termios.0)?;
console_mode.set_mode(termios.0)?;
Ok(())
Ok(())
}
pub fn raw_terminal_attr(termios: &mut Termios) {
// These are copied from the MSDocs.
// Yes, technically, not the best, but Windows won't change these for obvious reasons.
// We could link in winapi explicitly, as crossterm_winapi is already doing that, but
// I feel it just adds a bit too much cruft, when we can just do this.
//
// https://docs.microsoft.com/en-us/windows/console/setconsolemode#parameters
const ENABLE_PROCESSED_INPUT: u32 = 0x0001;
const ENABLE_LINE_INPUT: u32 = 0x0002;
const ENABLE_ECHO_INPUT: u32 = 0x0004;
const RAW_MODE_MASK: u32 = ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT;
termios.0 = termios.0 & !RAW_MODE_MASK;
// These are copied from the MSDocs.
// Yes, technically, not the best, but Windows won't change these for obvious reasons.
// We could link in winapi explicitly, as crossterm_winapi is already doing that, but
// I feel it just adds a bit too much cruft, when we can just do this.
//
// https://docs.microsoft.com/en-us/windows/console/setconsolemode#parameters
const ENABLE_PROCESSED_INPUT: u32 = 0x0001;
const ENABLE_LINE_INPUT: u32 = 0x0002;
const ENABLE_ECHO_INPUT: u32 = 0x0004;
const RAW_MODE_MASK: u32 = ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT;
termios.0 = termios.0 & !RAW_MODE_MASK;
}
......@@ -4,10 +4,10 @@ use super::crossterm_winapi::ScreenBuffer;
/// Get the size of the terminal.
pub fn terminal_size() -> io::Result<(u16, u16)> {
let terminal_size = ScreenBuffer::current()?.info()?.terminal_size();
// windows starts counting at 0, unix at 1, add one to replicated unix behaviour.
Ok((
(terminal_size.width + 1) as u16,
(terminal_size.height + 1) as u16,
))
let terminal_size = ScreenBuffer::current()?.info()?.terminal_size();
// windows starts counting at 0, unix at 1, add one to replicated unix behaviour.
Ok((
(terminal_size.width + 1) as u16,
(terminal_size.height + 1) as u16,
))
}
use std::os::windows::io::{AsRawHandle};
use std::io::{self, Read, Write, Stdin, Stdout, Result};
use std::io::{self, Read, Result, Stdin, Stdout, Write};
use std::os::windows::io::AsRawHandle;
/// Is this stream a TTY?
pub fn is_tty<T: AsRawHandle>(stream: &T) -> bool {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment