##// 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 if display_states.modified {
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 if display_states.added {
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 if display_states.removed {
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 if display_states.deleted {
337 if display_states.deleted {
338 output.display(b"!", ds_status.deleted)?;
338 output.display(b"! ", "status.deleted", ds_status.deleted)?;
339 }
339 }
340 if display_states.unknown {
340 if display_states.unknown {
341 output.display(b"?", ds_status.unknown)?;
341 output.display(b"? ", "status.unknown", ds_status.unknown)?;
342 }
342 }
343 if display_states.ignored {
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 if display_states.clean {
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 let mut dirstate_write_needed = ds_status.dirty;
350 let mut dirstate_write_needed = ds_status.dirty;
@@ -448,9 +448,11 b" impl DisplayStatusPaths<'_> {"
448 fn display(
448 fn display(
449 &self,
449 &self,
450 status_prefix: &[u8],
450 status_prefix: &[u8],
451 label: &'static str,
451 mut paths: Vec<StatusPath<'_>>,
452 mut paths: Vec<StatusPath<'_>>,
452 ) -> Result<(), CommandError> {
453 ) -> Result<(), CommandError> {
453 paths.sort_unstable();
454 paths.sort_unstable();
455 // TODO: get the stdout lock once for the whole loop instead of in each write
454 for StatusPath { path, copy_source } in paths {
456 for StatusPath { path, copy_source } in paths {
455 let relative;
457 let relative;
456 let path = if let Some(relativize) = &self.relativize {
458 let path = if let Some(relativize) = &self.relativize {
@@ -459,22 +461,20 b" impl DisplayStatusPaths<'_> {"
459 } else {
461 } else {
460 path.as_bytes()
462 path.as_bytes()
461 };
463 };
462 // TODO optim, probably lots of unneeded copies here, especially
464 // TODO: Add a way to use `write_bytes!` instead of `format_bytes!`
463 // if out stream is buffered
465 // in order to stream to stdout instead of allocating an
464 if self.no_status {
466 // itermediate `Vec<u8>`.
465 self.ui.write_stdout(&format_bytes!(b"{}\n", path))?
467 if !self.no_status {
466 } else {
468 self.ui.write_stdout_labelled(status_prefix, label)?
467 self.ui.write_stdout(&format_bytes!(
468 b"{} {}\n",
469 status_prefix,
470 path
471 ))?
472 }
469 }
470 self.ui
471 .write_stdout_labelled(&format_bytes!(b"{}\n", path), label)?;
473 if let Some(source) = copy_source {
472 if let Some(source) = copy_source {
474 self.ui.write_stdout(&format_bytes!(
473 let label = "status.copied";
475 b" {}\n",
474 self.ui.write_stdout_labelled(
476 source.as_bytes()
475 &format_bytes!(b" {}\n", source.as_bytes()),
477 ))?
476 label,
477 )?
478 }
478 }
479 }
479 }
480 Ok(())
480 Ok(())
@@ -30,7 +30,7 b' fn main_with_result('
30 repo: Result<&Repo, &NoRepoInCwdError>,
30 repo: Result<&Repo, &NoRepoInCwdError>,
31 config: &Config,
31 config: &Config,
32 ) -> Result<(), CommandError> {
32 ) -> Result<(), CommandError> {
33 check_unsupported(config, repo, ui)?;
33 check_unsupported(config, repo)?;
34
34
35 let app = App::new("rhg")
35 let app = App::new("rhg")
36 .global_setting(AppSettings::AllowInvalidUtf8)
36 .global_setting(AppSettings::AllowInvalidUtf8)
@@ -679,7 +679,6 b' fn check_extensions(config: &Config) -> '
679 fn check_unsupported(
679 fn check_unsupported(
680 config: &Config,
680 config: &Config,
681 repo: Result<&Repo, &NoRepoInCwdError>,
681 repo: Result<&Repo, &NoRepoInCwdError>,
682 ui: &ui::Ui,
683 ) -> Result<(), CommandError> {
682 ) -> Result<(), CommandError> {
684 check_extensions(config)?;
683 check_extensions(config)?;
685
684
@@ -703,13 +702,5 b' fn check_unsupported('
703 Err(CommandError::unsupported("[decode] config"))?
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 Ok(())
705 Ok(())
715 }
706 }
@@ -57,11 +57,6 b' impl Ui {'
57
57
58 /// Write bytes to stdout
58 /// Write bytes to stdout
59 pub fn write_stdout(&self, bytes: &[u8]) -> Result<(), UiError> {
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 let mut stdout = self.stdout.lock();
60 let mut stdout = self.stdout.lock();
66
61
67 stdout.write_all(bytes).or_else(handle_stdout_error)?;
62 stdout.write_all(bytes).or_else(handle_stdout_error)?;
@@ -311,9 +311,8 b' test unknown color'
311
311
312 $ hg --config color.status.modified=periwinkle status
312 $ hg --config color.status.modified=periwinkle status
313 ignoring unknown color/effect 'periwinkle' (configured in color.status.modified)
313 ignoring unknown color/effect 'periwinkle' (configured in color.status.modified)
314 ignoring unknown color/effect 'periwinkle' (configured in color.status.modified)
314 ignoring unknown color/effect 'periwinkle' (configured in color.status.modified) (no-rhg !)
315 ignoring unknown color/effect 'periwinkle' (configured in color.status.modified)
315 ignoring unknown color/effect 'periwinkle' (configured in color.status.modified) (no-rhg !)
316 ignoring unknown color/effect 'periwinkle' (configured in color.status.modified) (rhg !)
317 M modified
316 M modified
318 \x1b[0;32;1mA \x1b[0m\x1b[0;32;1madded\x1b[0m (esc)
317 \x1b[0;32;1mA \x1b[0m\x1b[0;32;1madded\x1b[0m (esc)
319 \x1b[0;32;1mA \x1b[0m\x1b[0;32;1mcopied\x1b[0m (esc)
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