Commit 722de2c0 authored by Jeremy Soller's avatar Jeremy Soller

Update to new termion

parent d7bc422f
......@@ -6,10 +6,11 @@ extern crate termion;
use std::env::args;
use std::fs::File;
use std::io::{self, Write, Read, StdoutLock};
use std::io::{self, Write, Read};
use std::path::Path;
use extra::option::OptionalExt;
use termion::raw::IntoRawMode;
static LONG_HELP: &'static str = /* @MANSTART{less} */ r#"
NAME
......@@ -51,8 +52,6 @@ COPYRIGHT
fn main() {
let mut args = args().skip(1).peekable();
let stdout = io::stdout();
let mut stdout = stdout.lock();
let stdin = io::stdin();
let mut stdin = stdin.lock();
let mut stderr = io::stderr();
......@@ -60,21 +59,21 @@ fn main() {
if let Some(x) = args.peek() {
if x == "--help" || x == "-h" {
// Print help.
stdout.write(LONG_HELP.as_bytes()).try(&mut stderr);
io::stdout().write(LONG_HELP.as_bytes()).try(&mut stderr);
return;
}
} else {
let mut terminal = termion::get_tty().try(&mut stderr);
run("-", &mut stdin, &mut terminal, &mut stdout).try(&mut stderr);
run("-", &mut stdin, &mut terminal, io::stdout()).try(&mut stderr);
};
while let Some(filename) = args.next() {
let mut file = File::open(Path::new(filename.as_str())).try(&mut stderr);
run(filename.as_str(), &mut file, &mut stdin, &mut stdout).try(&mut stderr);
run(filename.as_str(), &mut file, &mut stdin, io::stdout()).try(&mut stderr);
}
}
fn run(path: &str, file: &mut Read, controls: &mut Read, stdout: &mut StdoutLock) -> std::io::Result<()> {
fn run<W: IntoRawMode>(path: &str, file: &mut Read, controls: &mut Read, stdout: W) -> std::io::Result<()> {
let mut string = String::new();
file.read_to_string(&mut string)?;
......
......@@ -7,7 +7,7 @@ extern crate termion;
use std::env::args;
use std::fs::File;
use std::io::{self, Write, Read, StdoutLock};
use std::io::{self, Write, Read};
use std::path::{Path, PathBuf};
use std::str::Chars;
......@@ -69,8 +69,7 @@ fn terminal_path() -> String {
fn main() {
let mut args = args().skip(1).peekable();
let stdout = io::stdout();
let mut stdout = stdout.lock();
let mut stdout = io::stdout();
let stdin = io::stdin();
let mut stdin = stdin.lock();
let mut stderr = io::stderr();
......@@ -189,7 +188,7 @@ impl Block {
blocks
}
fn draw(&self, to: &mut RawTerminal<&mut StdoutLock>, path: &PathBuf, next: &mut Vec<PathBuf>, next_i: usize) -> std::io::Result<usize> {
fn draw<W: IntoRawMode>(&self, to: &mut RawTerminal<W>, path: &PathBuf, next: &mut Vec<PathBuf>, next_i: usize) -> std::io::Result<usize> {
let mut count = 0;
match *self {
......@@ -290,7 +289,7 @@ impl Buffer {
Ok(res)
}
fn draw(&self, to: &mut RawTerminal<&mut StdoutLock>, path: &PathBuf, next: &mut Vec<PathBuf>, next_i: usize, w: u16, h: u16) -> std::io::Result<usize> {
fn draw<W: IntoRawMode>(&self, to: &mut RawTerminal<W>, path: &PathBuf, next: &mut Vec<PathBuf>, next_i: usize, w: u16, h: u16) -> std::io::Result<usize> {
write!(to, "{}{}{}", clear::All, style::Reset, cursor::Goto(1, 1))?;
let mut y = 0;
......@@ -336,7 +335,7 @@ impl Buffer {
}
}
fn run(mut path: PathBuf, file: &mut Read, controls: &mut Read, stdout: &mut StdoutLock) -> std::io::Result<()> {
fn run<W: IntoRawMode>(mut path: PathBuf, file: &mut Read, controls: &mut Read, stdout: &mut W) -> std::io::Result<()> {
let mut stdout = stdout.into_raw_mode()?;
let (w, h) = {
......
......@@ -9,8 +9,8 @@ use termion::raw::IntoRawMode;
fn main() {
let mut stderr = io::stderr();
let mut terminal = termion::get_tty().try(&mut stderr)
.into_raw_mode().try(&mut stderr);
let mut terminal = termion::get_tty().try(&mut stderr);
let mut terminal = terminal.into_raw_mode().try(&mut stderr);
write!(terminal, "{}", cursor::Save).unwrap();
terminal.flush().unwrap();
......@@ -22,7 +22,7 @@ fn main() {
write!(terminal, "{}", cursor::Restore).unwrap();
terminal.flush().unwrap();
drop(terminal);
println!("export COLUMNS={};", w);
......
......@@ -7,7 +7,7 @@ extern crate termion;
use std::{cmp, str, thread};
use std::env::args;
use std::io::{self, Write, Read, StdoutLock};
use std::io::{self, Write, Read};
use std::process::{self, Command, Stdio};
use std::time::Duration;
......@@ -57,8 +57,7 @@ COPYRIGHT
fn main() {
let mut args = args().skip(1);
let stdout = io::stdout();
let mut stdout = stdout.lock();
let mut stdout = io::stdout();
let mut stderr = io::stderr();
let mut command = String::new();
......@@ -98,10 +97,10 @@ fn main() {
process::exit(1);
}
run(command, interval, &mut stdout).try(&mut stderr);
run(command, interval, stdout).try(&mut stderr);
}
fn run(command: String, interval: u64, stdout: &mut StdoutLock) -> std::io::Result<()> {
fn run<W: IntoRawMode>(command: String, interval: u64, mut stdout: W) -> std::io::Result<()> {
let title = format!("Every {}s: {}", interval, command);
let mut stdout = stdout.into_raw_mode()?;
......
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