##// END OF EJS Templates
rhg: Colorize `rhg status` output when appropriate...
Simon Sapin -
r49585:3e2b4bb2 default
parent child Browse files
Show More
@@ -326,25 +326,25 b' pub fn run(invocation: &crate::CliInvoca'
326 326 },
327 327 };
328 328 if display_states.modified {
329 output.display(b"M", ds_status.modified)?;
329 output.display(b"M ", "status.modified", ds_status.modified)?;
330 330 }
331 331 if display_states.added {
332 output.display(b"A", ds_status.added)?;
332 output.display(b"A ", "status.added", ds_status.added)?;
333 333 }
334 334 if display_states.removed {
335 output.display(b"R", ds_status.removed)?;
335 output.display(b"R ", "status.removed", ds_status.removed)?;
336 336 }
337 337 if display_states.deleted {
338 output.display(b"!", ds_status.deleted)?;
338 output.display(b"! ", "status.deleted", ds_status.deleted)?;
339 339 }
340 340 if display_states.unknown {
341 output.display(b"?", ds_status.unknown)?;
341 output.display(b"? ", "status.unknown", ds_status.unknown)?;
342 342 }
343 343 if display_states.ignored {
344 output.display(b"I", ds_status.ignored)?;
344 output.display(b"I ", "status.ignored", ds_status.ignored)?;
345 345 }
346 346 if display_states.clean {
347 output.display(b"C", ds_status.clean)?;
347 output.display(b"C ", "status.clean", ds_status.clean)?;
348 348 }
349 349
350 350 let mut dirstate_write_needed = ds_status.dirty;
@@ -448,9 +448,11 b" impl DisplayStatusPaths<'_> {"
448 448 fn display(
449 449 &self,
450 450 status_prefix: &[u8],
451 label: &'static str,
451 452 mut paths: Vec<StatusPath<'_>>,
452 453 ) -> Result<(), CommandError> {
453 454 paths.sort_unstable();
455 // TODO: get the stdout lock once for the whole loop instead of in each write
454 456 for StatusPath { path, copy_source } in paths {
455 457 let relative;
456 458 let path = if let Some(relativize) = &self.relativize {
@@ -459,22 +461,20 b" impl DisplayStatusPaths<'_> {"
459 461 } else {
460 462 path.as_bytes()
461 463 };
462 // TODO optim, probably lots of unneeded copies here, especially
463 // if out stream is buffered
464 if self.no_status {
465 self.ui.write_stdout(&format_bytes!(b"{}\n", path))?
466 } else {
467 self.ui.write_stdout(&format_bytes!(
468 b"{} {}\n",
469 status_prefix,
470 path
471 ))?
464 // TODO: Add a way to use `write_bytes!` instead of `format_bytes!`
465 // in order to stream to stdout instead of allocating an
466 // itermediate `Vec<u8>`.
467 if !self.no_status {
468 self.ui.write_stdout_labelled(status_prefix, label)?
472 469 }
470 self.ui
471 .write_stdout_labelled(&format_bytes!(b"{}\n", path), label)?;
473 472 if let Some(source) = copy_source {
474 self.ui.write_stdout(&format_bytes!(
475 b" {}\n",
476 source.as_bytes()
477 ))?
473 let label = "status.copied";
474 self.ui.write_stdout_labelled(
475 &format_bytes!(b" {}\n", source.as_bytes()),
476 label,
477 )?
478 478 }
479 479 }
480 480 Ok(())
@@ -30,7 +30,7 b' fn main_with_result('
30 30 repo: Result<&Repo, &NoRepoInCwdError>,
31 31 config: &Config,
32 32 ) -> Result<(), CommandError> {
33 check_unsupported(config, repo, ui)?;
33 check_unsupported(config, repo)?;
34 34
35 35 let app = App::new("rhg")
36 36 .global_setting(AppSettings::AllowInvalidUtf8)
@@ -679,7 +679,6 b' fn check_extensions(config: &Config) -> '
679 679 fn check_unsupported(
680 680 config: &Config,
681 681 repo: Result<&Repo, &NoRepoInCwdError>,
682 ui: &ui::Ui,
683 682 ) -> Result<(), CommandError> {
684 683 check_extensions(config)?;
685 684
@@ -703,13 +702,5 b' fn check_unsupported('
703 702 Err(CommandError::unsupported("[decode] config"))?
704 703 }
705 704
706 if let Some(color) = config.get(b"ui", b"color") {
707 if (color == b"always" || color == b"debug")
708 && !ui.plain(Some("color"))
709 {
710 Err(CommandError::unsupported("colored output"))?
711 }
712 }
713
714 705 Ok(())
715 706 }
@@ -57,11 +57,6 b' impl Ui {'
57 57
58 58 /// Write bytes to stdout
59 59 pub fn write_stdout(&self, bytes: &[u8]) -> Result<(), UiError> {
60 // Hack to silence "unused" warnings
61 if false {
62 return self.write_stdout_labelled(bytes, "");
63 }
64
65 60 let mut stdout = self.stdout.lock();
66 61
67 62 stdout.write_all(bytes).or_else(handle_stdout_error)?;
@@ -311,9 +311,8 b' test unknown color'
311 311
312 312 $ hg --config color.status.modified=periwinkle status
313 313 ignoring unknown color/effect 'periwinkle' (configured in color.status.modified)
314 ignoring unknown color/effect 'periwinkle' (configured in color.status.modified)
315 ignoring unknown color/effect 'periwinkle' (configured in color.status.modified)
316 ignoring unknown color/effect 'periwinkle' (configured in color.status.modified) (rhg !)
314 ignoring unknown color/effect 'periwinkle' (configured in color.status.modified) (no-rhg !)
315 ignoring unknown color/effect 'periwinkle' (configured in color.status.modified) (no-rhg !)
317 316 M modified
318 317 \x1b[0;32;1mA \x1b[0m\x1b[0;32;1madded\x1b[0m (esc)
319 318 \x1b[0;32;1mA \x1b[0m\x1b[0;32;1mcopied\x1b[0m (esc)
General Comments 0
You need to be logged in to leave comments. Login now