improve output formatting
This commit is contained in:
parent
b6af43feda
commit
700ab47f0e
@ -1,3 +1,4 @@
|
|||||||
|
use core::fmt;
|
||||||
use nom::{
|
use nom::{
|
||||||
IResult,
|
IResult,
|
||||||
branch::alt,
|
branch::alt,
|
||||||
@ -39,6 +40,27 @@ impl From<ParseIntegerError> for Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Error {
|
||||||
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||||
|
match self {
|
||||||
|
Error::Incomplete =>
|
||||||
|
"incomplete input".fmt(fmt),
|
||||||
|
Error::UnexpectedInput(c) => {
|
||||||
|
"unexpected input: ".fmt(fmt)?;
|
||||||
|
c.fmt(fmt)
|
||||||
|
}
|
||||||
|
Error::Parser(e) => {
|
||||||
|
"parser: ".fmt(fmt)?;
|
||||||
|
(e as &dyn core::fmt::Debug).fmt(fmt)
|
||||||
|
}
|
||||||
|
Error::ParseInteger(e) => {
|
||||||
|
"parsing number: ".fmt(fmt)?;
|
||||||
|
e.fmt(fmt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum ShowCommand {
|
pub enum ShowCommand {
|
||||||
ReportMode,
|
ReportMode,
|
||||||
|
@ -260,10 +260,10 @@ fn main() -> ! {
|
|||||||
Command::Quit =>
|
Command::Quit =>
|
||||||
socket.close(),
|
socket.close(),
|
||||||
Command::Report(mode) => {
|
Command::Report(mode) => {
|
||||||
let _ = writeln!(socket, "Report mode: {:?}", mode);
|
let _ = writeln!(socket, "Report mode: {}", mode);
|
||||||
}
|
}
|
||||||
Command::Show(ShowCommand::ReportMode) => {
|
Command::Show(ShowCommand::ReportMode) => {
|
||||||
let _ = writeln!(socket, "Report mode: {:?}", session.report_mode());
|
let _ = writeln!(socket, "Report mode: {}", session.report_mode());
|
||||||
}
|
}
|
||||||
Command::Show(ShowCommand::Pid) => {
|
Command::Show(ShowCommand::Pid) => {
|
||||||
let _ = writeln!(socket, "PID settings");
|
let _ = writeln!(socket, "PID settings");
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use core::ops::Deref;
|
use core::ops::Deref;
|
||||||
|
use core::fmt;
|
||||||
use super::command_parser::{Command, Error as ParserError};
|
use super::command_parser::{Command, Error as ParserError};
|
||||||
|
|
||||||
const MAX_LINE_LEN: usize = 64;
|
const MAX_LINE_LEN: usize = 64;
|
||||||
@ -60,6 +61,17 @@ pub enum ReportMode {
|
|||||||
Continuous,
|
Continuous,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for ReportMode {
|
||||||
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||||
|
match self {
|
||||||
|
ReportMode::Off => "off",
|
||||||
|
ReportMode::Once => "once",
|
||||||
|
ReportMode::Continuous => "continuous",
|
||||||
|
_ => "<INVALID>",
|
||||||
|
}.fmt(fmt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub enum SessionOutput {
|
pub enum SessionOutput {
|
||||||
Nothing,
|
Nothing,
|
||||||
Command(Command),
|
Command(Command),
|
||||||
|
Loading…
Reference in New Issue
Block a user