aboutsummaryrefslogtreecommitdiffstats
path: root/mumctl/src
diff options
context:
space:
mode:
authorEskil Queseth <eskilq@kth.se>2020-10-17 15:47:50 +0200
committerEskil Queseth <eskilq@kth.se>2020-10-17 15:47:50 +0200
commitd740d78b0b18543928355a7183ba770a6cc0368a (patch)
tree137ec9a815f0b7eaa7c4008c1d17314642cb1e22 /mumctl/src
parent8213d5769c771641f906611aeb427a93f25e2e95 (diff)
downloadmum-d740d78b0b18543928355a7183ba770a6cc0368a.tar.gz
add pretty print for channel list
Diffstat (limited to 'mumctl/src')
-rw-r--r--mumctl/src/main.rs26
1 files changed, 22 insertions, 4 deletions
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<Option<CommandRespons
rx_client.recv().unwrap()
}
+
+fn print_channel(channel: &Channel, depth: usize) {
+ println!("{}{}{}", iter::repeat(" ").take(depth).collect::<String>(), 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::<String>(), user.name);
+ }
+ for child in &channel.children {
+ print_channel(child, depth + 1);
+ }
+} \ No newline at end of file