track current column position when writing

korrat
Sep 29, 2022, 4:38 PM
ND7GASJ45SLCZWNTZVAEQOWRF4HQ4GQ7TQLQZ4CUTW2IW3JN776QC

Dependencies

  • [2] ONRIF4V7 add basic snapshot test for pretty printer
  • [3] QRIJE4AQ add a simple pretty printer for beancount directives
  • [*] I2P2FTLE add basic parser for german decimals
  • [*] YDK6X6PP add a library of important types for beancount

Change contents

  • edit in common/beancount-pretty-printer/src/lib.rs at line 7
    [3.274]
    [3.274]
    use bstr::ByteSlice as _;
  • replacement in common/beancount-pretty-printer/src/lib.rs at line 21
    [3.553][3.553:567]()
    inner: W,
    [3.553]
    [3.567]
    inner: TrackingWriter<W>,
  • edit in common/beancount-pretty-printer/src/lib.rs at line 30
    [3.790]
    [3.790]
    let inner = TrackingWriter::new(inner);
  • edit in common/beancount-pretty-printer/src/lib.rs at line 180
    [3.5021]
    [3.5021]
    }
    struct TrackingWriter<W> {
    column: usize,
    inner: W,
  • edit in common/beancount-pretty-printer/src/lib.rs at line 187
    [3.5023]
    impl<W> TrackingWriter<W>
    where
    W: Write,
    {
    fn new(inner: W) -> Self {
    Self { column: 0, inner }
    }
    }
    impl<W> Write for TrackingWriter<W>
    where
    W: Write,
    {
    fn write(&mut self, buf: &[u8]) -> Result<usize> {
    let written = self.inner.write(buf)?;
    let buffer = &buf[..written];
    // Extract the last line written to the inner writer
    let line = buffer.rsplit_once_str(b"\n").map_or(buffer, |(_, line)| {
    // Since we encountered a line separator, reset the column
    self.column = 0;
    line
    });
    self.column += line.graphemes().count();
    Ok(written)
    }
    fn flush(&mut self) -> Result<()> {
    self.inner.flush()
    }
    }
  • replacement in common/beancount-pretty-printer/Cargo.toml at line 9
    [3.5259][2.2189:2219]()
    rust_decimal.workspace = true
    [3.5259]
    [3.5283]
    # Workspace dependencies
    beancount-types.path = "../beancount-types"
  • replacement in common/beancount-pretty-printer/Cargo.toml at line 12
    [3.5284][3.5284:5343]()
    [dependencies.beancount-types]
    path = "../beancount-types"
    [3.5284]
    [2.2220]
    # Inherited dependencies
    bstr.workspace = true
    rust_decimal.workspace = true
  • edit in Cargo.toml at line 10
    [2.2350]
    [2.2350]
    bstr = "1.0.1"
  • edit in Cargo.lock at line 61
    [3.5565]
    [2.2495]
    "bstr",
  • edit in Cargo.lock at line 123
    [6.27381]
    [6.27381]
    name = "bstr"
    version = "1.0.1"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "fca0852af221f458706eb0725c03e4ed6c46af9ac98e6a689d5e634215d594dd"
    dependencies = [
    "memchr",
    "once_cell",
    "regex-automata",
    "serde",
    ]
    [[package]]
  • edit in Cargo.lock at line 701
    [6.34740]
    [6.34740]
    name = "regex-automata"
    version = "0.1.10"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
    [[package]]