From d740d78b0b18543928355a7183ba770a6cc0368a Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Sat, 17 Oct 2020 15:47:50 +0200 Subject: add pretty print for channel list --- mumctl/src/main.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'mumctl') diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs index 97dba53..592bd6b 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -1,10 +1,10 @@ use clap::{App, AppSettings, Arg, Shell, SubCommand}; use ipc_channel::ipc::{self, IpcSender}; -use log::*; use mumlib::command::{Command, CommandResponse}; use mumlib::setup_logger; -use std::{fs, io}; +use std::{fs, io, iter}; use colored::Colorize; +use mumlib::state::Channel; macro_rules! err_print { ($func:expr) => { @@ -16,7 +16,6 @@ macro_rules! err_print { fn main() { setup_logger(); - debug!("Logger up!"); let mut app = App::new("mumctl") .setting(AppSettings::ArgRequiredElseHelp) @@ -68,7 +67,12 @@ fn main() { if let Some(_matches) = matches.subcommand_matches("list") { match send_command(Command::ChannelList) { Ok(res) => { - println!("{:#?}", res.unwrap()); + match res { + Some(CommandResponse::ChannelList { channels }) => { + print_channel(&channels, 0); + } + _ => unreachable!(), + } } Err(e) => println!("{} {}", "error:".red(), e), } @@ -115,3 +119,17 @@ fn send_command(command: Command) -> mumlib::error::Result(), channel.name.bold(), if channel.max_users != 0 { + format!(" {}/{}", channel.users.len(), channel.max_users) + } else { + "".to_string() + }); + for user in &channel.users { + println!("{}-{}", iter::repeat(" ").take(depth + 1).collect::(), user.name); + } + for child in &channel.children { + print_channel(child, depth + 1); + } +} \ No newline at end of file -- cgit v1.2.1