Commit 35aab820ee
Unsigned
Layout: unified · split
src/commands.rs +10 −9
| @@ -102,7 +102,7 @@ impl MatrixCommand { | ||
| 102 | 102 | )); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | fn list_servers(&self) { | |
| 105 | fn list_servers(&self, details: bool) { | |
| 106 | 106 | if self.servers.borrow().is_empty() { |
| 107 | 107 | return; |
| 108 | 108 | } |
| @@ -110,12 +110,8 @@ impl MatrixCommand { | ||
| 110 | 110 | Weechat::print("\nAll Matrix servers:"); |
| 111 | 111 | |
| 112 | 112 | // 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))); | |
| 119 | 115 | } |
| 120 | 116 | } |
| 121 | 117 | |
| @@ -123,8 +119,9 @@ impl MatrixCommand { | ||
| 123 | 119 | match args.subcommand() { |
| 124 | 120 | ("add", Some(subargs)) => self.add_server(subargs), |
| 125 | 121 | ("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), | |
| 128 | 125 | } |
| 129 | 126 | } |
| 130 | 127 | |
| @@ -211,6 +208,10 @@ impl CommandCallback for MatrixCommand { | ||
| 211 | 208 | .subcommand( |
| 212 | 209 | SubCommand::with_name("list") |
| 213 | 210 | .about("List the configured Matrix servers."), |
| 211 | ) | |
| 212 | .subcommand( | |
| 213 | SubCommand::with_name("listfull") | |
| 214 | .about("List detailed information about the configured Matrix servers."), | |
| 214 | 215 | ); |
| 215 | 216 | |
| 216 | 217 | let argparse = Argparse::new("matrix") |
src/server.rs +37
| @@ -686,6 +686,43 @@ impl MatrixServer { | ||
| 686 | 686 | }; |
| 687 | 687 | } |
| 688 | 688 | } |
| 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 | } | |
| 689 | 726 | } |
| 690 | 727 | |
| 691 | 728 | impl Drop for MatrixServer { |