Render the remote view listing.
(&self, views: &[RemoteViewInfo])
| 167 | |
| 168 | /// Render the remote view listing. |
| 169 | fn print_remote_views(&self, views: &[RemoteViewInfo]) { |
| 170 | if views.is_empty() { |
| 171 | println!("{}", hint("No views found on the remote.")); |
| 172 | return; |
| 173 | } |
| 174 | |
| 175 | let mut sorted: Vec<&RemoteViewInfo> = views.iter().collect(); |
| 176 | sorted.sort_by(|a, b| a.name.cmp(&b.name)); |
| 177 | |
| 178 | if self.short { |
| 179 | for view in sorted { |
| 180 | println!(" {}", style_view(&view.name)); |
| 181 | } |
| 182 | return; |
| 183 | } |
| 184 | |
| 185 | let max_name_len = sorted.iter().map(|v| v.name.len()).max().unwrap_or(0); |
| 186 | |
| 187 | for view in sorted { |
| 188 | let kind_tag = if view.is_draft() { |
| 189 | "[draft]" |
| 190 | } else { |
| 191 | "[shared]" |
| 192 | }; |
| 193 | let change_display = if view.change_count == 1 { |
| 194 | "(1 change)".to_string() |
| 195 | } else { |
| 196 | format!("({} changes)", view.change_count) |
| 197 | }; |
| 198 | let parent_info = match &view.parent { |
| 199 | Some(p) => format!(" parent: {}", style_view(p)), |
| 200 | None => String::new(), |
| 201 | }; |
| 202 | let state_display = view |
| 203 | .state |
| 204 | .as_deref() |
| 205 | .map(|s| &s[..12.min(s.len())]) |
| 206 | .unwrap_or("-"); |
| 207 | println!( |
| 208 | " {:<width$} {:<10} {} state: {}{}", |
| 209 | style_view(&view.name), |
| 210 | kind_tag, |
| 211 | change_display, |
| 212 | state_display, |
| 213 | parent_info, |
| 214 | width = max_name_len |
| 215 | ); |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | impl Command for List { |