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