Merge pull request #142 from kpcyrd/prompts

Use readline for prompts
This commit is contained in:
kpcyrd
2020-01-04 15:49:48 +01:00
committed by GitHub
7 changed files with 504 additions and 420 deletions

View File

@@ -37,10 +37,10 @@ matrix:
# rust: stable
# env:
# - BUILD_MODE="windows test"
- os: windows
rust: stable
env:
- BUILD_MODE="windows common"
#- os: windows
# rust: stable
# env:
# - BUILD_MODE="windows common"
before_install:
- ci/setup.sh "$TRAVIS_OS_NAME"

847
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -74,8 +74,8 @@ bytes = "0.4"
xml-rs = "0.8"
bytesize = "1.0"
ipnetwork = "0.15"
strum = "0.16"
strum_macros = "0.16"
strum = "0.17"
strum_macros = "0.17"
digest = "0.8.0"
bs58 = "0.3"
@@ -87,15 +87,15 @@ sha3 = "0.8.0"
hmac = "0.7"
image = "0.22"
kamadak-exif = "0.3.1"
kamadak-exif = "0.4"
walkdir = "2.2"
nude = "0.2"
[target.'cfg(target_os="linux")'.dependencies]
caps = "0.3"
#syscallz = { path="../syscallz-rs" }
syscallz = "0.11"
nix = "0.15"
syscallz = "0.12"
nix = "0.16"
[target.'cfg(target_os="openbsd")'.dependencies]
pledge = "0.3.1"

View File

@@ -47,8 +47,6 @@ Docker
Alpine
------
On alpine edge, with enabled testing repositories:
.. code-block:: bash
$ apk add sn0int
@@ -56,8 +54,6 @@ On alpine edge, with enabled testing repositories:
OpenBSD
-------
On -current:
.. code-block:: bash
$ pkg_add sn0int

View File

@@ -11,11 +11,12 @@ pub struct Location {
}
impl Location {
pub fn try_from(fields: &[exif::Field]) -> Result<Location> {
fn try_from_iter<'a, I: IntoIterator<Item=&'a exif::Field>>(iter: I) -> Result<Self> {
let mut builder = LocationBuilder::default();
fields.iter()
.map(|f| builder.add_one(f))
.collect::<Result<()>>()?;
for f in iter {
debug!("Exif field: {:?}", f.display_value().to_string());
builder.add_one(f)?;
}
builder.build()
}
}
@@ -63,9 +64,8 @@ pub fn gps(img: &[u8]) -> Result<Option<Location>> {
let mut buf = io::BufReader::new(img);
let reader = exif::Reader::new(&mut buf)?;
let fields = reader.fields();
debug!("Exif fields: {:?}", fields);
let location = Location::try_from(fields).ok();
let location = Location::try_from_iter(fields).ok();
Ok(location)
}
@@ -115,18 +115,18 @@ mod tests {
fn verify_exif_location() {
test_init();
let location = Location::try_from(&[
let location = Location::try_from_iter(&[
exif::Field {
tag: exif::Tag::GPSLatitudeRef,
thumbnail: false,
value: exif::Value::Ascii(vec![&[b'N']]),
ifd_num: exif::In::PRIMARY,
value: exif::Value::Ascii(vec![vec![b'N']]),
}, exif::Field {
tag: exif::Tag::GPSLongitudeRef,
thumbnail: false,
value: exif::Value::Ascii(vec![&[b'E']]),
ifd_num: exif::In::PRIMARY,
value: exif::Value::Ascii(vec![vec![b'E']]),
}, exif::Field {
tag: exif::Tag::GPSLatitude,
thumbnail: false,
ifd_num: exif::In::PRIMARY,
value: exif::Value::Rational(vec![exif::Rational {
num: 43,
denom: 1,
@@ -139,7 +139,7 @@ mod tests {
}]),
}, exif::Field {
tag: exif::Tag::GPSLongitude,
thumbnail: false,
ifd_num: exif::In::PRIMARY,
value: exif::Value::Rational(vec![exif::Rational {
num: 11,
denom: 1,

View File

@@ -129,7 +129,7 @@ pub struct PrintableNetblock {
impl fmt::Display for PrintableNetblock {
fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
write!(w, "{:?}", self.value) // TODO: cidr type
write!(w, "{}", self.value)
}
}

View File

@@ -1,21 +1,26 @@
use crate::errors::*;
use std::io::{self, Write};
use rustyline::error::ReadlineError;
use std::str::FromStr;
pub fn read_line() -> Result<String> {
let mut buf = String::new();
io::stdin().read_line(&mut buf)?;
let buf = buf.trim().to_string();
Ok(buf)
pub fn read_line(prompt: &str) -> Result<String> {
let mut rl = rustyline::Editor::<()>::new();
let mut line = rl.readline(prompt)
.map_err(|err| match err {
ReadlineError::Eof => format_err!("Failed to read line from input"),
ReadlineError::Interrupted => format_err!("Prompt has been canceled"),
err => err.into(),
})?;
if let Some(idx) = line.find('\n') {
line.truncate(idx);
}
info!("Read from prompt: {:?}", line);
Ok(line)
}
pub fn question(text: &str) -> Result<String> {
print!("\x1b[1m[\x1b[34m?\x1b[0;1m]\x1b[0m {}: ", text);
io::stdout().flush()?;
read_line()
let prompt = format!("\x1b[1m[\x1b[34m?\x1b[0;1m]\x1b[0m {}: ", text);
read_line(&prompt)
}
pub fn question_opt(text: &str) -> Result<Option<String>> {