mirror of
https://github.com/nushell/nushell.git
synced 2025-04-01 03:36:53 +02:00
After the previous commit, nushell uses PrettyDebug and PrettyDebugWithSource for our pretty-printed display output. PrettyDebug produces a structured `pretty.rs` document rather than writing directly into a fmt::Formatter, and types that implement `PrettyDebug` have a convenience `display` method that produces a string (to be used in situations where `Display` is needed for compatibility with other traits, or where simple rendering is appropriate).
33 lines
800 B
Rust
33 lines
800 B
Rust
use crate::parser::{hir::Expression, Operator};
|
|
use crate::prelude::*;
|
|
|
|
use derive_new::new;
|
|
use getset::Getters;
|
|
use nu_source::Spanned;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(
|
|
Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Getters, Serialize, Deserialize, new,
|
|
)]
|
|
#[get = "pub(crate)"]
|
|
pub struct Binary {
|
|
left: Expression,
|
|
op: Spanned<Operator>,
|
|
right: Expression,
|
|
}
|
|
|
|
impl PrettyDebugWithSource for Binary {
|
|
fn pretty_debug(&self, source: &str) -> DebugDocBuilder {
|
|
b::delimit(
|
|
"<",
|
|
self.left.pretty_debug(source)
|
|
+ b::space()
|
|
+ b::keyword(self.op.span.slice(source))
|
|
+ b::space()
|
|
+ self.right.pretty_debug(source),
|
|
">",
|
|
)
|
|
.group()
|
|
}
|
|
}
|