2015-12-24 06:11:00 +00:00
|
|
|
//! stdio convenience fns
|
|
|
|
|
|
|
|
use std::io::{stderr, stdout, Write};
|
|
|
|
use std::env;
|
|
|
|
|
2018-09-04 12:33:36 +00:00
|
|
|
pub const EXIT_OK: i32 = 0;
|
|
|
|
pub const EXIT_ERR: i32 = 1;
|
2015-12-24 06:11:00 +00:00
|
|
|
|
2016-02-15 05:47:02 +00:00
|
|
|
pub fn err_msg(msg: &str) {
|
2015-12-24 06:11:00 +00:00
|
|
|
let exe_path = match env::current_exe() {
|
|
|
|
Ok(p) => p.to_string_lossy().into_owned(),
|
2016-02-15 05:47:02 +00:00
|
|
|
_ => String::from(""),
|
2015-12-24 06:11:00 +00:00
|
|
|
};
|
2016-02-15 05:47:02 +00:00
|
|
|
writeln!(&mut stderr(), "{}: {}", exe_path, msg).unwrap();
|
2015-12-24 06:11:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// by default stdout only flushes
|
|
|
|
// to console when a newline is passed.
|
|
|
|
#[allow(unused_must_use)]
|
|
|
|
pub fn flush_char(c: &char) {
|
|
|
|
print!("{}", c);
|
|
|
|
stdout().flush();
|
|
|
|
}
|
|
|
|
#[allow(unused_must_use)]
|
|
|
|
pub fn flush_str(s: &str) {
|
|
|
|
print!("{}", s);
|
|
|
|
stdout().flush();
|
|
|
|
}
|
|
|
|
#[allow(unused_must_use)]
|
|
|
|
pub fn flush_bytes(bslice: &[u8]) {
|
|
|
|
stdout().write(bslice);
|
|
|
|
stdout().flush();
|
|
|
|
}
|