treeline-0.1.0/.gitignore01006440000765000002400000000027130420432020013513 0ustar0000000000000000target Cargo.lock *.bk treeline-0.1.0/.travis.yml01006440000765000002400000002603130422753140013651 0ustar0000000000000000sudo: false language: rust matrix: fast_finish: true include: - rust: nightly - rust: beta - rust: stable allow_failures: - rust: nightly script: - RUSTFLAGS="$RUSTFLAGS -C link-dead-code" cargo test cache: cargo: true apt: true directories: - target/debug/deps - target/debug/build addons: apt: packages: - libcurl4-openssl-dev - libelf-dev - libdw-dev - cmake - gcc - binutils-dev # required for `kcov --verify` after_success: | [ $TRAVIS_RUST_VERSION = stable ] && [ $TRAVIS_BRANCH = master ] && [ $TRAVIS_PULL_REQUEST = false ] && wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz && tar xzf master.tar.gz && mkdir kcov-master/build && cd kcov-master/build && cmake .. && make && make install DESTDIR=../tmp && cd ../.. && ls target/debug && for file in target/debug/treeline-*; do mkdir -p "target/cov/$(basename $file)"; ./kcov-master/tmp/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file"; done && echo "covered" && cargo doc --no-deps && echo "" > target/doc/index.html && pip install --user ghp-import && /home/travis/.local/bin/ghp-import -n target/doc && git push -fq https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git gh-pages && echo "documented" treeline-0.1.0/Cargo.toml.orig01006440000765000002400000000536130422423750014433 0ustar0000000000000000[package] name = "treeline" version = "0.1.0" authors = ["softprops "] description = "a library for visualizing tree structured data" documentation = "https://softprops.github.io/treeline" homepage = "https://github.com/softprops/treeline" repository = "https://github.com/softprops/treeline" keywords = ["tree"] license = "MIT" treeline-0.1.0/Cargo.toml0000644000000015520007661 0ustar00# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g. crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] name = "treeline" version = "0.1.0" authors = ["softprops "] description = "a library for visualizing tree structured data" homepage = "https://github.com/softprops/treeline" documentation = "https://softprops.github.io/treeline" keywords = ["tree"] license = "MIT" repository = "https://github.com/softprops/treeline" treeline-0.1.0/CHANGELOG.md01006440000765000002400000000033130422424150013340 0ustar0000000000000000# 0.1.0 * initial release treeline-0.1.0/examples/tree.rs01006440000765000002400000001624130422415730014665 0ustar0000000000000000extern crate treeline; use treeline::Tree; use std::{env, io, fs}; use std::path::Path; fn label>(p: P) -> String { p.as_ref().file_name().unwrap().to_str().unwrap().to_owned() } fn tree>(p: P) -> io::Result> { let result = fs::read_dir(&p)? .into_iter() .filter_map(|e| e.ok()) .fold(Tree::root(label(p.as_ref().canonicalize()?)), |mut root, entry| { let dir = entry.metadata().unwrap(); if dir.is_dir() { root.push(tree(entry.path()).unwrap()); } else { root.push(Tree::root(label(entry.path()))); } root }); Ok(result) } fn main() { let dir = env::args().nth(1).unwrap_or(String::from(".")); match tree(dir) { Ok(tree) => println!("{}", tree), Err(err) => println!("error: {}", err) } } treeline-0.1.0/LICENSE01006440000765000002400000002040130422770170012542 0ustar0000000000000000Copyright (c) 2017 Doug Tangren Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. treeline-0.1.0/README.md01006440000765000002400000002615130422770050013021 0ustar0000000000000000# treeline [![Build Status](https://travis-ci.org/softprops/treeline.svg?branch=master)](https://travis-ci.org/softprops/treeline) [![Coverage Status](https://coveralls.io/repos/github/softprops/treeline/badge.svg)](https://coveralls.io/github/softprops/treeline) > a rust library for visualizing tree like data [API documentation](https://softprops.github.com/treeline) ## install ... ## usage an example program is provided under the "examples" directory to mimic the `tree(1)` linux program ```bash $ cargo run --example tree target Finished debug [unoptimized + debuginfo] target(s) in 0.0 secs Running `target/debug/examples/tree target` target └── debug ├── .cargo-lock ├── .fingerprint | └── treeline-21a5bdbd42e0b6da | ├── dep-example-tree | ├── dep-lib-treeline | ├── example-tree | ├── example-tree.json | ├── lib-treeline | └── lib-treeline.json ├── build ├── deps | └── libtreeline.rlib ├── examples | ├── tree | └── tree.dSYM | └── Contents | ├── Info.plist | └── Resources | └── DWARF | └── tree ├── libtreeline.rlib └── native ``` Doug Tangren (softprops) 2017 treeline-0.1.0/src/lib.rs01006440000765000002400000004172130422432040013437 0ustar0000000000000000use std::fmt::{self, Display}; /// a simple recursive type which is able to render its /// components in a tree-like format #[derive(Debug)] pub struct Tree(D, Vec>); impl Tree { pub fn new(root: D, leaves: Vec>) -> Tree { Tree(root, leaves) } pub fn root(root: D) -> Tree { Tree(root, Vec::new()) } pub fn push(&mut self, leaf: Tree) -> &mut Self { self.1.push(leaf); self } fn display_leaves(f: &mut fmt::Formatter, leaves: &Vec>, spaces: Vec) -> fmt::Result { for (i, leaf) in leaves.iter().enumerate() { let last = i >= leaves.len() - 1; let mut clone = spaces.clone(); // print single line for s in &spaces { if *s { let _ = write!(f, " "); } else { let _ = write!(f, "| "); } } if last { let _ = writeln!(f, "└── {}", leaf.0); } else { let _ = writeln!(f, "├── {}", leaf.0); } // recurse if !leaf.1.is_empty() { clone.push(last); let _ = Self::display_leaves(f, &leaf.1, clone); } } write!(f, "") } } impl Display for Tree { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let _ = writeln!(f, "{}", self.0); Self::display_leaves(f, &self.1, Vec::new()) } } #[cfg(test)] mod tests { use super::Tree; #[test] fn render_tree_root() { let tree = Tree::root("foo"); assert_eq!(format!("{}", tree), "foo\n") } #[test] fn render_tree_with_leaves() { let tree = Tree::new( "foo", vec![ Tree::new( "bar", vec![ Tree::root("baz") ] ) ] ); assert_eq!(format!("{}", tree), r#"foo └── bar └── baz "#) } }