~rootmos/turn

8026ec7fa7ac0266bab99ca20ba70261b0f3f4ed — Gustav Behm 2 years ago 290c5e6
Pretty-print splits
3 files changed, 31 insertions(+), 1 deletions(-)

M Cargo.lock
M Cargo.toml
M src/main.rs
M Cargo.lock => Cargo.lock +18 -0
@@ 245,6 245,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41"

[[package]]
name = "libxml"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0f71e821b82fe8ad377edf23ed7a66328df62a49be11377f21230e3955ea1f7"
dependencies = [
 "libc",
 "pkg-config",
 "vcpkg",
]

[[package]]
name = "livesplit-core"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 987,6 998,7 @@ dependencies = [
name = "turn"
version = "0.1.0"
dependencies = [
 "libxml",
 "livesplit-core",
 "termion",
 "tokio",


@@ 1026,6 1038,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"

[[package]]
name = "vcpkg"
version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cbdbff6266a24120518560b5dc983096efb98462e51d0d68169895b237be3e5d"

[[package]]
name = "version_check"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"

M Cargo.toml => Cargo.toml +1 -0
@@ 8,6 8,7 @@ edition = "2018"
termion = "1.5.6"
livesplit-core = "0.11.0"
tokio = { version = "1", features = ["rt", "time", "signal", "sync", "macros", "net"] }
libxml = "0.2.16"

[[bin]]
name = "turn"

M src/main.rs => src/main.rs +12 -1
@@ 1,6 1,6 @@
use std::fs::File;
use std::io::{Write, BufReader, BufWriter};
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::borrow::Borrow;

fn render_time<T: Borrow<livesplit_core::TimeSpan>>(t: T, always_display_sign: bool) -> String {


@@ 397,6 397,16 @@ async fn run<W: Write>(st: &mut State, out: &mut W) -> bool {
    save
}

fn xml_pretty_print<P: AsRef<Path>>(path: P) {
    let raw = std::fs::read_to_string(path.as_ref()).unwrap();
    let parser = libxml::parser::Parser::default();
    let doc = parser.parse_string(raw).unwrap();
    let raw = doc.to_string_with_options(libxml::tree::SaveOptions {
        format: true,
        .. libxml::tree::SaveOptions::default()
    });
    std::fs::write(path, raw).unwrap();
}

#[tokio::main(flavor = "current_thread")]
async fn main() {


@@ 430,5 440,6 @@ async fn main() {
    if save {
        let f = BufWriter::new(File::create(&p).expect("file not found"));
        livesplit_core::run::saver::livesplit::save_timer(&st.timer, f).expect("unable to write splits");
        xml_pretty_print(p);
    }
}