Cargo fmt and use STDOUT_FILENO for getting Termios
This commit is contained in:
parent
0dd537dc14
commit
b9dee69522
@ -421,7 +421,6 @@ impl Editor {
|
||||
// If you can't write to stdout, you might as well just panic
|
||||
handle.write_all(query.as_bytes()).unwrap();
|
||||
|
||||
|
||||
let stdin = io::stdin();
|
||||
let stdin = stdin.lock();
|
||||
let mut handle = stdin.take(32);
|
||||
@ -430,7 +429,10 @@ impl Editor {
|
||||
clean_unwrap(read_res);
|
||||
|
||||
if input.len() < 6 {
|
||||
panic!("Invalid or missing response to cursor location query: {:?}", input);
|
||||
panic!(
|
||||
"Invalid or missing response to cursor location query: {:?}",
|
||||
input
|
||||
);
|
||||
}
|
||||
|
||||
let mut row_str = String::new();
|
||||
@ -455,10 +457,7 @@ impl Editor {
|
||||
let rows = clean_unwrap(row_str.parse());
|
||||
let cols = clean_unwrap(row_str.parse());
|
||||
|
||||
return TermSize {
|
||||
cols,
|
||||
rows,
|
||||
}
|
||||
return TermSize { cols, rows };
|
||||
}
|
||||
|
||||
fn get_window_size(&mut self) -> TermSize {
|
||||
@ -544,11 +543,7 @@ impl Editor {
|
||||
|
||||
// End of a comment
|
||||
if &row.render[mce_range.clone()] == mce {
|
||||
highlight_range(
|
||||
&mut row.highlight,
|
||||
mce_range,
|
||||
Highlight::MultiLineComment,
|
||||
);
|
||||
highlight_range(&mut row.highlight, mce_range, Highlight::MultiLineComment);
|
||||
|
||||
i += mce.len();
|
||||
in_comment = false;
|
||||
@ -560,11 +555,7 @@ impl Editor {
|
||||
}
|
||||
} else if &row.render[mcs_range.clone()] == mcs {
|
||||
// Start of a multi-line comment
|
||||
highlight_range(
|
||||
&mut row.highlight,
|
||||
mcs_range,
|
||||
Highlight::MultiLineComment,
|
||||
);
|
||||
highlight_range(&mut row.highlight, mcs_range, Highlight::MultiLineComment);
|
||||
|
||||
i += mcs.len();
|
||||
in_comment = true;
|
||||
@ -1612,7 +1603,9 @@ fn get_syntax_db() -> Vec<Syntax> {
|
||||
"in",
|
||||
"as",
|
||||
],
|
||||
vec!["=>", "Number", "String", "Object", "Math", "JSON", "Boolean"],
|
||||
vec![
|
||||
"=>", "Number", "String", "Object", "Math", "JSON", "Boolean",
|
||||
],
|
||||
"//",
|
||||
"/*",
|
||||
"*/",
|
||||
|
@ -9,7 +9,7 @@ pub mod terminal_helpers;
|
||||
|
||||
use crate::editor::Editor;
|
||||
use crate::terminal_helpers::*;
|
||||
use nix::libc::STDIN_FILENO;
|
||||
use nix::libc::STDOUT_FILENO;
|
||||
use nix::sys::termios::Termios;
|
||||
use std::env;
|
||||
use std::io::Error;
|
||||
@ -19,7 +19,7 @@ use std::sync::{Arc, Mutex};
|
||||
// Much ugliness to get and keep a reference to the original terminal settings
|
||||
lazy_static! {
|
||||
// Save terminal flags on start
|
||||
pub static ref ORIGINAL_TERMIOS: Arc<Mutex<Termios>> = Arc::new(Mutex::new(get_termios(STDIN_FILENO)));
|
||||
pub static ref ORIGINAL_TERMIOS: Arc<Mutex<Termios>> = Arc::new(Mutex::new(get_termios(STDOUT_FILENO)));
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Error> {
|
||||
@ -50,7 +50,7 @@ fn main() -> Result<(), Error> {
|
||||
editor::KeyCode::OtherKey('\0') => (),
|
||||
|
||||
// Just for debugging
|
||||
_ => () //println!("{:?}\r\n", key)
|
||||
_ => (), //println!("{:?}\r\n", key)
|
||||
}
|
||||
}
|
||||
None => break,
|
||||
|
@ -18,17 +18,6 @@ pub struct TermSize {
|
||||
pub cols: u16,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
struct UnixTermSize {
|
||||
/// number of rows
|
||||
pub rows: c_ushort,
|
||||
/// number of columns
|
||||
pub cols: c_ushort,
|
||||
x: c_ushort,
|
||||
y: c_ushort,
|
||||
}
|
||||
|
||||
/// Get a `Termios` struct, for getting/setting terminal flags
|
||||
pub fn get_termios(fd: RawFd) -> Termios {
|
||||
termios::tcgetattr(fd).unwrap()
|
||||
@ -41,7 +30,7 @@ pub fn enable_raw_mode() {
|
||||
let mutex = Arc::clone(&super::ORIGINAL_TERMIOS);
|
||||
mutex.lock().unwrap();
|
||||
|
||||
let mut raw = get_termios(STDIN_FILENO);
|
||||
let mut raw = get_termios(STDOUT_FILENO);
|
||||
|
||||
raw.input_flags.remove(
|
||||
InputFlags::BRKINT
|
||||
@ -79,7 +68,19 @@ pub fn disable_raw_mode() {
|
||||
}
|
||||
|
||||
/// Attempt to get the size of the terminal (in rows and columns) from an `ioctl` call
|
||||
#[inline]
|
||||
pub fn get_term_size() -> Option<TermSize> {
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
struct UnixTermSize {
|
||||
/// number of rows
|
||||
pub rows: c_ushort,
|
||||
/// number of columns
|
||||
pub cols: c_ushort,
|
||||
x: c_ushort,
|
||||
y: c_ushort,
|
||||
}
|
||||
|
||||
let raw = UnixTermSize {
|
||||
rows: 0,
|
||||
cols: 0,
|
||||
|
Loading…
Reference in New Issue
Block a user