Compare commits
4 Commits
49de6d3fd4
...
master
Author | SHA1 | Date | |
---|---|---|---|
1000e3b0e8 | |||
87b316fb20 | |||
8b125ac5e7 | |||
42c0dad3b1 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
/target
|
||||
/dbus-prettifier.1.gz
|
||||
|
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -4,4 +4,4 @@ version = 4
|
||||
|
||||
[[package]]
|
||||
name = "dbus-prettifier"
|
||||
version = "1.2.0"
|
||||
version = "1.2.1"
|
||||
|
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "dbus-prettifier"
|
||||
version = "1.2.0"
|
||||
version = "1.2.1"
|
||||
edition = "2024"
|
||||
authors = [ "Nicolás A. Ortega Froysa <nicolas@ortegas.org>" ]
|
||||
description = "A tool to prettify the output of qdbus."
|
||||
|
@@ -1,4 +1,4 @@
|
||||
.TH dbus-prettifier "1" "October 2025" "dbus-prettifier 1.2.0" "User Commands"
|
||||
.TH dbus-prettifier "1" "October 2025" "dbus-prettifier 1.2.1" "User Commands"
|
||||
.SH "NAME"
|
||||
dbus-prettifier - A tool to prettify the output of qdbus.
|
||||
.SH "SYNOPSIS"
|
||||
|
@@ -27,6 +27,8 @@ use std::fs;
|
||||
use std::io::Read;
|
||||
use std::boxed::Box;
|
||||
|
||||
static MAX_WRITE_BUF_SIZE:usize = 1024;
|
||||
|
||||
pub fn work(in_path:Option<&str>, out_path:Option<&str>) -> Result<(), String> {
|
||||
let in_reader:Box<dyn io::Read> = match in_path {
|
||||
Some(path) => {
|
||||
@@ -56,33 +58,43 @@ pub fn work(in_path:Option<&str>, out_path:Option<&str>) -> Result<(), String>
|
||||
|
||||
let mut last_ch = '\0';
|
||||
let mut tab_num = 0;
|
||||
let mut in_paren = false;
|
||||
let mut write_buf = String::new();
|
||||
|
||||
for i in in_reader.bytes() {
|
||||
let ch = i.unwrap() as char;
|
||||
match ch {
|
||||
'[' | '{' => {
|
||||
tab_num += 1;
|
||||
out_writer.write(format!("{ch}\n").as_bytes()).unwrap();
|
||||
//write_buf += format!("{ch}\n").as_str();
|
||||
write_buf.push(ch);
|
||||
if !in_paren {
|
||||
write_buf.push('\n');
|
||||
for _ in 0..tab_num {
|
||||
out_writer.write(b" ").unwrap();
|
||||
write_buf += " ";
|
||||
}
|
||||
last_ch = ' ';
|
||||
} else {
|
||||
last_ch = ch;
|
||||
}
|
||||
},
|
||||
']' | '}' => {
|
||||
tab_num -= 1;
|
||||
out_writer.write(b"\n").unwrap();
|
||||
if !in_paren {
|
||||
write_buf += "\n";
|
||||
for _ in 0..tab_num {
|
||||
out_writer.write(b" ").unwrap();
|
||||
write_buf += " ";
|
||||
}
|
||||
out_writer.write(format!("{ch}").as_bytes()).unwrap();
|
||||
}
|
||||
write_buf.push(ch);
|
||||
last_ch = ch;
|
||||
},
|
||||
',' => {
|
||||
out_writer.write(format!("{ch}").as_bytes()).unwrap();
|
||||
write_buf.push(ch);
|
||||
if last_ch == '}' || last_ch == ']' {
|
||||
out_writer.write(b"\n").unwrap();
|
||||
write_buf.push('\n');
|
||||
for _ in 0..tab_num {
|
||||
out_writer.write(b" ").unwrap();
|
||||
write_buf += " ";
|
||||
}
|
||||
last_ch = ' ';
|
||||
} else {
|
||||
@@ -91,11 +103,25 @@ pub fn work(in_path:Option<&str>, out_path:Option<&str>) -> Result<(), String>
|
||||
},
|
||||
_ => {
|
||||
if ch != ' ' || last_ch != ' ' {
|
||||
out_writer.write(format!("{ch}").as_bytes()).unwrap();
|
||||
if ch == '(' {
|
||||
in_paren = true;
|
||||
} else if ch == ')' {
|
||||
in_paren = false;
|
||||
}
|
||||
write_buf.push(ch);
|
||||
last_ch = ch;
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
if write_buf.len() >= MAX_WRITE_BUF_SIZE {
|
||||
out_writer.write_all(write_buf.as_bytes()).unwrap();
|
||||
write_buf.clear();
|
||||
}
|
||||
}
|
||||
|
||||
if write_buf.len() > 0 {
|
||||
out_writer.write_all(write_buf.as_bytes()).unwrap();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
Reference in New Issue
Block a user