mirror of
https://github.com/nushell/nushell.git
synced 2025-02-26 07:22:19 +01:00
* fix #4161 println! and friends will panic on BrokenPipe. The solution is to use writeln! instead, and ignore the error (or do we want to do something else?) * test that nu doesn't panic in case of BrokenPipe error * fixup! test that nu doesn't panic in case of BrokenPipe error * make do_not_panic_if_broken_pipe only run on UNIX systems
50 lines
1.3 KiB
Rust
50 lines
1.3 KiB
Rust
/// Outputs to standard out
|
|
///
|
|
/// Note: this exists to differentiate between intentional writing to stdout
|
|
/// and stray printlns left by accident
|
|
#[macro_export]
|
|
macro_rules! out {
|
|
($($tokens:tt)*) => {
|
|
use std::io::Write;
|
|
write!(std::io::stdout(), $($tokens)*).unwrap_or(());
|
|
let _ = std::io::stdout().flush();
|
|
}
|
|
}
|
|
|
|
/// Outputs to standard out with a newline added
|
|
///
|
|
/// Note: this exists to differentiate between intentional writing to stdout
|
|
/// and stray printlns left by accident
|
|
#[macro_export]
|
|
macro_rules! outln {
|
|
($($tokens:tt)*) => {
|
|
{
|
|
use std::io::Write;
|
|
writeln!(std::io::stdout(), $($tokens)*).unwrap_or(())
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Outputs to standard error
|
|
///
|
|
/// Note: this exists to differentiate between intentional writing to stdout
|
|
/// and stray printlns left by accident
|
|
#[macro_export]
|
|
macro_rules! errln {
|
|
($($tokens:tt)*) => {
|
|
{
|
|
use std::io::Write;
|
|
writeln!(std::io::stderr(), $($tokens)*).unwrap_or(())
|
|
}
|
|
}
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! row {
|
|
($( $key: expr => $val: expr ),*) => {{
|
|
let mut map = ::indexmap::IndexMap::new();
|
|
$( map.insert($key, $val); )*
|
|
::nu_protocol::UntaggedValue::row(map).into_untagged_value()
|
|
}}
|
|
}
|