1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

more: fix build on windows

This commit is contained in:
Wim Hueskes 2016-10-06 23:35:16 +02:00
parent 9a1f320bed
commit 046ff62af6
2 changed files with 33 additions and 9 deletions

View file

@ -10,9 +10,11 @@ path = "more.rs"
[dependencies]
getopts = "*"
libc = "*"
nix = "*"
uucore = { path="../uucore" }
[target."cfg(unix)".dependencies]
nix = "*"
[[bin]]
name = "more"
path = "main.rs"

View file

@ -18,7 +18,9 @@ use getopts::Options;
use std::io::{stdout, Write, Read};
use std::fs::File;
#[cfg(unix)]
extern crate nix;
#[cfg(unix)]
use nix::sys::termios;
#[derive(Clone, Eq, PartialEq)]
@ -74,17 +76,39 @@ fn help(usage: &str) {
println!("{}", msg);
}
fn more(matches: getopts::Matches) {
let files = matches.free;
let mut f = File::open(files.first().unwrap()).unwrap();
let mut buffer = [0; 1024];
#[cfg(unix)]
fn setup_term() -> termios::Termios {
let mut term = termios::tcgetattr(0).unwrap();
// Unset canonical mode, so we get characters immediately
term.c_lflag.remove(termios::ICANON);
// Disable local echo
term.c_lflag.remove(termios::ECHO);
termios::tcsetattr(0, termios::TCSADRAIN, &term).unwrap();
term
}
#[cfg(windows)]
fn setup_term() -> usize {
0
}
#[cfg(unix)]
fn reset_term(term: &mut termios::Termios) {
term.c_lflag.insert(termios::ICANON);
term.c_lflag.insert(termios::ECHO);
termios::tcsetattr(0, termios::TCSADRAIN, &term).unwrap();
}
#[cfg(windows)]
fn reset_term(_: &mut usize) {
}
fn more(matches: getopts::Matches) {
let files = matches.free;
let mut f = File::open(files.first().unwrap()).unwrap();
let mut buffer = [0; 1024];
let mut term = setup_term();
let mut end = false;
while let Ok(sz) = f.read(&mut buffer) {
@ -104,8 +128,6 @@ fn more(matches: getopts::Matches) {
if end { break;}
}
term.c_lflag.insert(termios::ICANON);
term.c_lflag.insert(termios::ECHO);
termios::tcsetattr(0, termios::TCSADRAIN, &term).unwrap();
reset_term(&mut term);
println!("");
}