Colours in diff and change: separating concerns and dependencies

[?]
Jan 13, 2021, 6:27 PM
ZRUPLBBTT4S6S7A3LOAHG4ONYEGPA5CFO4L2XBCNFKK45MWX3BDAC

Dependencies

  • [2] OJZWJUF2 MUCH faster `pijul add -r`
  • [3] SLJ3OHD4 unrecord: show list of changes if none were given as arguments
  • [4] GLRGFBCW Checking the version of less we have
  • [5] Q4SVMHAE Removing --channel from the changes command
  • [6] CCLLB7OI Upgrading to Sanakirja 0.15 + version bump
  • [7] 5DVRL6MF Hard-unrecord
  • [8] VO5OQW4W Removing anyhow in libpijul
  • [9] SE4RJYBZ No pager on Windows (really not)
  • [10] 5YDI33C4 Fixing pager on OSX
  • [11] YDKNUL6B Add `diff --short` that lists changes without showing them
  • [12] SXEYMYF7 Fixing the bad changes in history (unfortunately, by rebooting).
  • [13] VIHXB7SG commands: set up pager for diff, change, and credit
  • [14] CIEUBH46 Fixing an index-out-of-bounds error when serialising bad changes
  • [15] CCFJ7VO3 Renaming "Record" to "Hunk" in the changes
  • [16] I52XSRUH Massive cleanup, and simplification
  • [17] 2K7JLB4Z No pager on Windows
  • [18] 73NW2X2M Returning a parse error instead of panicking when parsing a text change
  • [*] Q45QHPO4 Feedback on network stuff

Change contents

  • replacement in pijul/src/commands/mod.rs at line 100
    [5.28][5.16:29](),[4.13][5.16:29](),[5.16][5.16:29]()
    fn pager() {
    [4.13]
    [4.14]
    fn pager() -> bool {
  • replacement in pijul/src/commands/mod.rs at line 113
    [4.424][4.424:485]()
    pager::Pager::with_pager("less -RF").setup()
    [4.424]
    [4.485]
    pager::Pager::with_pager("less -RF").setup();
    return true;
  • replacement in pijul/src/commands/mod.rs at line 116
    [4.506][4.506:550]()
    pager::Pager::new().setup()
    [4.506]
    [4.550]
    pager::Pager::new().setup();
  • edit in pijul/src/commands/mod.rs at line 120
    [4.580]
    [5.2909]
    false
  • replacement in pijul/src/commands/mod.rs at line 124
    [5.62][5.0:14](),[4.599][5.0:14](),[5.98][5.0:14]()
    fn pager() {}
    [4.599]
    [3.2970]
    fn pager() -> bool {
    false
    }
  • replacement in pijul/src/commands/diff.rs at line 90
    [5.175777][5.188:212]()
    super::pager();
    [5.175777]
    [5.175777]
    let pager_is_colored = super::pager();
  • replacement in pijul/src/commands/diff.rs at line 161
    [5.177283][5.177283:177323]()
    &mut std::io::stdout(),
    [5.177283]
    [5.177323]
    Colored {
    w: termcolor::StandardStream::stdout(termcolor::ColorChoice::Auto),
    colors: atty::is(atty::Stream::Stdout) || pager_is_colored,
    },
  • edit in pijul/src/commands/diff.rs at line 185
    [5.177744]
    [5.177744]
    }
    pub struct Colored<W> {
    pub w: W,
    pub colors: bool,
    }
    impl<W: std::io::Write> std::io::Write for Colored<W> {
    fn write(&mut self, s: &[u8]) -> Result<usize, std::io::Error> {
    self.w.write(s)
    }
    fn flush(&mut self) -> Result<(), std::io::Error> {
    self.w.flush()
    }
    }
    use termcolor::*;
    impl<W: termcolor::WriteColor> libpijul::change::WriteChangeLine for Colored<W> {
    fn write_change_line(&mut self, pref: &str, contents: &str) -> Result<(), std::io::Error> {
    if self.colors {
    let col = if pref == "+" {
    Color::Green
    } else {
    Color::Red
    };
    self.w.set_color(ColorSpec::new().set_fg(Some(col)))?;
    write!(self.w, "{} {}", pref, contents)?;
    self.w.reset()
    } else {
    write!(self.w, "{} {}", pref, contents)
    }
    }
    fn write_change_line_binary(
    &mut self,
    pref: &str,
    contents: &[u8],
    ) -> Result<(), std::io::Error> {
    if self.colors {
    let col = if pref == "+" {
    Color::Green
    } else {
    Color::Red
    };
    self.w.set_color(ColorSpec::new().set_fg(Some(col)))?;
    write!(
    self.w,
    "{}b{}",
    pref,
    data_encoding::BASE64.encode(contents)
    )?;
    self.w.reset()
    } else {
    write!(
    self.w,
    "{}b{}",
    pref,
    data_encoding::BASE64.encode(contents)
    )
    }
    }
  • replacement in pijul/src/commands/change.rs at line 44
    [5.419][5.190911:190976](),[5.190911][5.190911:190976](),[5.190976][5.238:262](),[5.244][5.190976:191046](),[5.262][5.190976:191046](),[5.190976][5.190976:191046]()
    let o = std::io::stdout();
    let mut o = o.lock();
    super::pager();
    change.write(&changes, Some(hash), file_name, true, &mut o)?;
    [5.419]
    [5.191046]
    let pager_is_colored = super::pager();
    change.write(
    &changes,
    Some(hash),
    file_name,
    true,
    super::diff::Colored {
    w: termcolor::StandardStream::stdout(termcolor::ColorChoice::Auto),
    colors: atty::is(atty::Stream::Stdout) || pager_is_colored,
    },
    )?;
  • edit in pijul/Cargo.toml at line 78
    [20.2859]
    [2.355]
    termcolor = "1.1"
    atty = "0.2"
  • edit in libpijul/src/change.rs at line 10
    [5.36136]
    [5.36136]
    pub use text_changes::WriteChangeLine;
  • replacement in libpijul/src/change/text_changes.rs at line 86
    [5.40602][5.40602:40698]()
    pub fn write<W: Write, C: ChangeStore, F: FnMut(&Local, Position<Option<Hash>>) -> String>(
    [5.40602]
    [5.40698]
    pub fn write<W: WriteChangeLine, C: ChangeStore, F: FnMut(&Local, Position<Option<Hash>>) -> String>(
  • replacement in libpijul/src/change/text_changes.rs at line 306
    [5.48493][5.48493:48520]()
    W: std::io::Write,
    [5.48493]
    [5.48520]
    W: WriteChangeLine,
  • replacement in libpijul/src/change/text_changes.rs at line 315
    [5.48744][5.48744:48762]()
    mut w: W,
    [5.48744]
    [5.48762]
    mut w: &mut W,
  • replacement in libpijul/src/change/text_changes.rs at line 367
    [5.50865][5.50865:50953]()
    print_change_contents(&mut w, changes, contents, change_contents)?;
    [5.50865]
    [5.50953]
    print_change_contents(w, changes, contents, change_contents)?;
  • replacement in libpijul/src/change/text_changes.rs at line 384
    [5.51484][5.51484:51572]()
    print_change_contents(&mut w, changes, contents, change_contents)?;
    [5.51484]
    [5.51572]
    print_change_contents(w, changes, contents, change_contents)?;
  • replacement in libpijul/src/change/text_changes.rs at line 426
    [5.53215][5.53215:53268]()
    print_contents(&mut w, "+", c)?;
    [5.53215]
    [5.53268]
    print_contents(w, "+", c)?;
  • replacement in libpijul/src/change/text_changes.rs at line 438
    [5.53680][5.53680:53762]()
    print_change_contents(&mut w, changes, change, change_contents)?;
    [5.53680]
    [5.53762]
    print_change_contents(w, changes, change, change_contents)?;
  • replacement in libpijul/src/change/text_changes.rs at line 451
    [5.54193][5.54193:54362]()
    print_change_contents(&mut w, changes, change, change_contents)?;
    print_change_contents(&mut w, changes, replacement, change_contents)?;
    [5.54193]
    [5.54362]
    print_change_contents(w, changes, change, change_contents)?;
    print_change_contents(w, changes, replacement, change_contents)?;
  • replacement in libpijul/src/change/text_changes.rs at line 480
    [5.55518][5.55518:55600]()
    print_change_contents(&mut w, changes, change, change_contents)?;
    [5.55518]
    [5.55600]
    print_change_contents(w, changes, change, change_contents)?;
  • replacement in libpijul/src/change/text_changes.rs at line 492
    [5.56002][5.56002:56084]()
    print_change_contents(&mut w, changes, change, change_contents)?;
    [5.56002]
    [5.56084]
    print_change_contents(w, changes, change, change_contents)?;
  • replacement in libpijul/src/change/text_changes.rs at line 504
    [5.56473][5.56473:56555]()
    print_change_contents(&mut w, changes, change, change_contents)?;
    [5.56473]
    [5.56555]
    print_change_contents(w, changes, change, change_contents)?;
  • replacement in libpijul/src/change/text_changes.rs at line 1186
    [5.84600][5.84600:84642]()
    pub fn print_contents<W: std::io::Write>(
    [5.84600]
    [5.84642]
    pub trait WriteChangeLine: std::io::Write {
    fn write_change_line(&mut self, pref: &str, contents: &str) -> Result<(), std::io::Error> {
    write!(self, "{} {}", pref, contents)
    }
    fn write_change_line_binary(&mut self, pref: &str, contents: &[u8]) -> Result<(), std::io::Error> {
    write!(self, "{}b{}", pref, data_encoding::BASE64.encode(contents))
    }
    }
    impl WriteChangeLine for &mut Vec<u8> {}
    pub fn print_contents<W: WriteChangeLine>(
  • replacement in libpijul/src/change/text_changes.rs at line 1206
    [5.84951][5.84951:84993]()
    write!(w, "{} {}", pref, a)?;
    [5.84951]
    [5.84993]
    w.write_change_line(pref, a)?
  • replacement in libpijul/src/change/text_changes.rs at line 1209
    [5.85037][5.85037:85088]()
    writeln!(w, "{} {}", pref, contents)?;
    [5.85037]
    [5.85088]
    w.write_change_line(pref, contents)?
  • replacement in libpijul/src/change/text_changes.rs at line 1217
    [5.85207][5.85207:85272]()
    pub fn print_change_contents<W: std::io::Write, C: ChangeStore>(
    [5.85207]
    [5.85272]
    pub fn print_change_contents<W: WriteChangeLine, C: ChangeStore>(