Skip to content

Commit ad8b906

Browse files
committed
Use libc isatty (nix never worked apparently)
1 parent 25d49c6 commit ad8b906

File tree

4 files changed

+9
-29
lines changed

4 files changed

+9
-29
lines changed

Cargo.lock

+2-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pq"
3-
version = "1.1.0"
3+
version = "1.1.1"
44
authors = ["Sevag Hanssian <[email protected]>"]
55
description = "jq for protobuf"
66
repository = "https://github.com/sevagh/pq"
@@ -17,9 +17,9 @@ erased_serde_json = { path = "erased-serde-json", version = "0.1.0" }
1717
serde_json = "1.0"
1818
serde-protobuf = "0.7"
1919
protobuf = "1.4"
20-
nix = "0.9"
2120
stream_delimit = { path = "stream-delimit", version = "0.5.0" }
2221
clap = "2"
22+
libc = "0.2"
2323

2424
[dev-dependencies]
2525
assert_cli = "0.5"

src/commands.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use stream_delimit::stream::*;
66
use stream_delimit::converter::Converter;
77
use std::io::{self, Write};
88
use clap::ArgMatches;
9-
use nix::unistd::isatty;
109
use std::path::PathBuf;
1110
use protobuf::descriptor::FileDescriptorSet;
11+
use libc;
1212

1313
pub struct CommandRunner {
1414
descriptors: Vec<FileDescriptorSet>,
@@ -46,13 +46,8 @@ impl CommandRunner {
4646
pub fn run_byte(self, matches: &ArgMatches) {
4747
let stdin = io::stdin();
4848
let mut stdin = stdin.lock();
49-
match isatty(0) {
50-
Ok(stdin_is_tty) => {
51-
if !stdin_is_tty {
52-
panic!("pq expects input piped from stdin")
53-
}
54-
}
55-
Err(e) => panic!("Error checking if stdin is tty: {}", e),
49+
if unsafe { libc::isatty(libc::STDIN_FILENO) != 0 } {
50+
panic!("pq expects input to be piped from stdin");
5651
}
5752
let stream_type = str_to_streamtype(matches.value_of("STREAM").unwrap_or("single"))
5853
.expect("Couldn't convert str to streamtype");
@@ -72,10 +67,7 @@ fn decode_or_convert<T: Iterator<Item = Vec<u8>>>(
7267
let count = value_t!(matches, "COUNT", i32).unwrap_or(-1);
7368

7469
let stdout = io::stdout();
75-
let out_is_tty = match isatty(1) {
76-
Ok(x) => x,
77-
Err(e) => panic!("Error checking if stdout is tty: {}", e),
78-
};
70+
let out_is_tty = unsafe { libc::isatty(libc::STDOUT_FILENO) != 0 };
7971

8072
if let Some(convert_type) = matches.value_of("CONVERT") {
8173
let converter = Converter::new(

src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#[macro_use]
44
extern crate clap;
55
extern crate erased_serde_json;
6-
extern crate nix;
6+
extern crate libc;
77
extern crate protobuf;
88
extern crate serde;
99
extern crate serde_json;

0 commit comments

Comments
 (0)