From 54e4ab71d918c778fa380a25250942c77a793be9 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Sat, 2 Sep 2017 08:06:55 -0700 Subject: [PATCH] Enable pager in cton-util. --- cranelift/Cargo.toml | 3 +++ cranelift/src/cton-util.rs | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/cranelift/Cargo.toml b/cranelift/Cargo.toml index 45b39ef0a3..b328febdd0 100644 --- a/cranelift/Cargo.toml +++ b/cranelift/Cargo.toml @@ -26,6 +26,9 @@ num_cpus = "1.5.1" tempdir="0.3.5" term = "0.4.6" +[target.'cfg(unix)'.dependencies] +pager = "0.13.0" + [workspace] # Enable debug assertions and parallel compilation when building cretonne-tools diff --git a/cranelift/src/cton-util.rs b/cranelift/src/cton-util.rs index b08fa8cde3..15eb250f5e 100644 --- a/cranelift/src/cton-util.rs +++ b/cranelift/src/cton-util.rs @@ -10,11 +10,17 @@ extern crate num_cpus; extern crate tempdir; extern crate term; +#[cfg(unix)] +extern crate pager; + use cretonne::VERSION; use docopt::Docopt; use std::io::{self, Write}; use std::process; +#[cfg(unix)] +use pager::Pager; + mod utils; mod filetest; mod cat; @@ -107,7 +113,19 @@ fn cton_util() -> CommandResult { } } +#[cfg(unix)] +fn enable_pager() { + Pager::new().skip_on_notty().setup(); +} + +#[cfg(not(unix))] +fn enable_pager() { + // For now, pager only supports unix-type platforms. +} + fn main() { + enable_pager(); + if let Err(mut msg) = cton_util() { if !msg.ends_with('\n') { msg.push('\n');