forked from mars/breed
cargo fmt
This commit is contained in:
parent
8a110c5b01
commit
f5ea473328
38
src/main.rs
38
src/main.rs
|
@ -20,12 +20,7 @@
|
||||||
use std::{
|
use std::{
|
||||||
env::args,
|
env::args,
|
||||||
fs::File,
|
fs::File,
|
||||||
io::{
|
io::{stdout, Read, Stdout, Write},
|
||||||
Read,
|
|
||||||
stdout,
|
|
||||||
Stdout,
|
|
||||||
Write,
|
|
||||||
},
|
|
||||||
os::fd::FromRawFd,
|
os::fd::FromRawFd,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -35,7 +30,7 @@ use crossterm::{
|
||||||
terminal, ExecutableCommand, Result,
|
terminal, ExecutableCommand, Result,
|
||||||
};
|
};
|
||||||
use ropey::Rope;
|
use ropey::Rope;
|
||||||
use yacexits::{ exit, EX_DATAERR, EX_UNAVAILABLE };
|
use yacexits::{exit, EX_DATAERR, EX_UNAVAILABLE};
|
||||||
|
|
||||||
struct Buffer {
|
struct Buffer {
|
||||||
pub text: Rope,
|
pub text: Rope,
|
||||||
|
@ -288,7 +283,7 @@ impl State {
|
||||||
self.mode = Mode::Insert(state);
|
self.mode = Mode::Insert(state);
|
||||||
}
|
}
|
||||||
KeyCode::Char('o') => {
|
KeyCode::Char('o') => {
|
||||||
let state = InsertState { append: false};
|
let state = InsertState { append: false };
|
||||||
self.cursor.line += 1;
|
self.cursor.line += 1;
|
||||||
self.cursor.column = 0;
|
self.cursor.column = 0;
|
||||||
let index = self.buffer.cursor_to_char(self.cursor);
|
let index = self.buffer.cursor_to_char(self.cursor);
|
||||||
|
@ -463,23 +458,22 @@ fn main() -> Result<()> {
|
||||||
let stdin = 0; // get stdin as a file descriptor
|
let stdin = 0; // get stdin as a file descriptor
|
||||||
if unsafe { libc::isatty(stdin) } == 0 {
|
if unsafe { libc::isatty(stdin) } == 0 {
|
||||||
unsafe { File::from_raw_fd(stdin) }
|
unsafe { File::from_raw_fd(stdin) }
|
||||||
} else { File::open("/dev/null").unwrap() }
|
} else {
|
||||||
},
|
File::open("/dev/null").unwrap()
|
||||||
Some(path) => {
|
}
|
||||||
std::fs::File::open(path).unwrap_or_else(|_| {
|
}
|
||||||
eprintln!(
|
Some(path) => std::fs::File::open(path).unwrap_or_else(|_| {
|
||||||
"{}: {}: No such file or directory.",
|
eprintln!("{}: {}: No such file or directory.", argv[0], argv[1]);
|
||||||
argv[0],
|
exit(EX_UNAVAILABLE);
|
||||||
argv[1]
|
}),
|
||||||
);
|
}
|
||||||
exit(EX_UNAVAILABLE);
|
.read_to_end(&mut buf)
|
||||||
})
|
.unwrap();
|
||||||
},
|
|
||||||
}.read_to_end(&mut buf).unwrap();
|
|
||||||
|
|
||||||
let text = String::from_utf8(buf).unwrap_or_else(|_| {
|
let text = String::from_utf8(buf).unwrap_or_else(|_| {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"{}: {}: File contents are not valid UTF-8.", argv[0], argv[1]
|
"{}: {}: File contents are not valid UTF-8.",
|
||||||
|
argv[0], argv[1]
|
||||||
);
|
);
|
||||||
exit(EX_DATAERR);
|
exit(EX_DATAERR);
|
||||||
});
|
});
|
||||||
|
|
Reference in New Issue
Block a user