aboutsummaryrefslogtreecommitdiff
path: root/src/output.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/output.rs')
-rw-r--r--src/output.rs31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/output.rs b/src/output.rs
index d181d0f..d7ab74e 100644
--- a/src/output.rs
+++ b/src/output.rs
@@ -1,4 +1,5 @@
use colored::*;
+use colored_json::prelude::*;
use jsonformat::{format_json, Indentation};
use std::fmt::Display;
@@ -13,11 +14,21 @@ pub struct BarbOutput {
impl BarbOutput {
fn _print_header<T, I>(&self, name: T, value: I)
- where T: Display, I: Display{
+ where
+ T: Display,
+ I: Display,
+ {
println!("{}: {}", name, value);
}
- pub fn new(request: bool, req_headers: bool, headers: bool, body: bool, raw_body: bool, color: bool) -> BarbOutput {
+ pub fn new(
+ request: bool,
+ req_headers: bool,
+ headers: bool,
+ body: bool,
+ raw_body: bool,
+ color: bool,
+ ) -> BarbOutput {
BarbOutput {
request,
req_headers,
@@ -88,16 +99,28 @@ impl BarbOutput {
}
}
+ fn _format_body(&self, body: String) -> String {
+ if self.raw_body {
+ return body;
+ }
+
+ let formatted = format_json(body.as_str(), Indentation::Default);
+ match self.color {
+ true => formatted.to_colored_json_auto().unwrap_or(formatted),
+ _ => formatted,
+ }
+ }
+
pub fn body(&self, body: String) {
if !self.body {
return;
}
-
+
println!(
"{}",
match self.raw_body {
true => body,
- false => format_json(body.as_str(), Indentation::Default),
+ _ => self._format_body(body),
}
);
}