Commit 35aab820ee

35aab820ee40e5300d0a993d4c4f1c9668d413c6

parent: 9dd8781f26

Unsigned

Fredrik Lanker <fredrik.lanker@gmail.com> · 2020-07-19 21:45 UTC

Implement listfull command

Layout: unified · split

src/commands.rs +10 −9
@@ -102,7 +102,7 @@ impl MatrixCommand {
102102 ));
103103 }
104104
105 fn list_servers(&self) {
105 fn list_servers(&self, details: bool) {
106106 if self.servers.borrow().is_empty() {
107107 return;
108108 }
@@ -110,12 +110,8 @@ impl MatrixCommand {
110110 Weechat::print("\nAll Matrix servers:");
111111
112112 // TODO print out some stats if the server is connected.
113 for server in self.servers.borrow().keys() {
114 Weechat::print(&format!(
115 " {}{}",
116 Weechat::color("chat_server"),
117 server
118 ));
113 for server in self.servers.borrow().values() {
114 Weechat::print(&format!(" {}", server.get_info_str(details)));
119115 }
120116 }
121117
@@ -123,8 +119,9 @@ impl MatrixCommand {
123119 match args.subcommand() {
124120 ("add", Some(subargs)) => self.add_server(subargs),
125121 ("delete", Some(subargs)) => self.delete_server(subargs),
126 ("list", _) => self.list_servers(),
127 _ => self.list_servers(),
122 ("list", _) => self.list_servers(false),
123 ("listfull", _) => self.list_servers(true),
124 _ => self.list_servers(false),
128125 }
129126 }
130127
@@ -211,6 +208,10 @@ impl CommandCallback for MatrixCommand {
211208 .subcommand(
212209 SubCommand::with_name("list")
213210 .about("List the configured Matrix servers."),
211 )
212 .subcommand(
213 SubCommand::with_name("listfull")
214 .about("List detailed information about the configured Matrix servers."),
214215 );
215216
216217 let argparse = Argparse::new("matrix")
src/server.rs +37
@@ -686,6 +686,43 @@ impl MatrixServer {
686686 };
687687 }
688688 }
689
690 pub fn get_info_str(&self, details: bool) -> String {
691 let mut s = String::from(&format!(
692 "{}{}{} [{}]",
693 Weechat::color("chat_server"),
694 self.server_name.as_ref().to_owned(),
695 Weechat::color("reset"),
696 if self.connected() {
697 "connected"
698 } else {
699 "not connected"
700 }
701 ));
702
703 if !details {
704 return s;
705 }
706
707 let settings = &self.inner.borrow().settings;
708 s.push_str(&format!(
709 "\n\
710 {:indent$}homeserver: {}\n\
711 {:indent$}proxy: {}\n\
712 {:indent$}autoconnect: {}\n\
713 {:indent$}username: {}\n",
714 "",
715 settings.homeserver.as_ref().map_or("", |url| url.as_str()),
716 "",
717 settings.proxy.as_ref().map_or("", |url| url.as_str()),
718 "",
719 settings.autoconnect,
720 "",
721 settings.username,
722 indent = 8
723 ));
724 s
725 }
689726}
690727
691728impl Drop for MatrixServer {