Giter Club home page Giter Club logo

tabwriter's Issues

approaching 1.0

This crate has a small API and is not widely used. With no obvious uptick in usage on the horizon, I suggest we cut a 1.0 release.

Example in README doesn't work

Attempting to compile the "Simple example" section of the README gives the following errors:

error[E0599]: no method named `write_str` found for type `tabwriter::TabWriter<std::vec::Vec<u8>>` in the current scope
  --> src/main.rs:10:4
   |
10 | tw.write_str("
   |    ^^^^^^^^^

error[E0599]: no method named `as_slice` found for type `std::string::String` in the current scope
  --> src/main.rs:20:20
   |
20 | assert_eq!(written.as_slice(), "
   |                    ^^^^^^^^

padding(0) gives one space of padding

It looks like the minimum padding is one space, with padding(n) giving n+1 spaces of padding? The documentation says otherwise, so I'm a little confused.

use std::io::{Write, stdout};

use tabwriter::TabWriter;

fn main() {
    let mut tw = TabWriter::new(stdout()).padding(0);
    writeln!(tw, "{}\t{}", 1, 2).unwrap();
    tw.flush().unwrap();
}

Outputs "1 2"

Right alignment of last column

Right alignment of the last column only works when there is a trailing tab on the line. Otherwise the last column is left-aligned which looks strange.
If this is a known restriction and not a bug it could possibly be documented.

Formatting broken when using ansi colours

I am trying to combine tabwriter and ansi_term crate to format some text output but tabwriter doesn't seem to handle the ANSI escape code and the formatting fails. I have no idea how this works in detail so I cannot probably provide a fix.

The code:

extern crate tabwriter;
extern crate ansi_term;
use ansi_term::Colour::Red;
use tabwriter::TabWriter;
use std::io::Write;

fn tabify(mut tw: TabWriter<Vec<u8>>, s: &str) -> String {
    write!(&mut tw, "{}", s).unwrap();
    tw.flush().unwrap();
    String::from_utf8(tw.unwrap()).unwrap()
}

fn main() {
    let output = format!("Title1\tTitle2\tTitle3\n{}\t{}\t{}",
                               Red.paint("value1"), Red.paint("value2"), Red.paint("value3"));

    let tw = TabWriter::new(Vec::<u8>::new());
    println!("{}", tabify(tw, &output[..]));
}

The output when running the code above:

Title1         Title2         Title3
value1  value2  value3

Relicense under dual MIT/Apache-2.0

Why?

The MIT license requires reproducing countless copies of the same copyright
header with different names in the copyright field, for every MIT library in
use. The Apache license does not have this drawback, and has protections from
patent trolls and an explicit contribution licensing clause. However, the
Apache license is incompatible with GPLv2. This is why Rust is dual-licensed as
MIT/Apache (the "primary" license being Apache, MIT only for GPLv2 compat), and
doing so would be wise for this project. This also makes this crate suitable
for inclusion in the Rust standard distribution and other project using dual
MIT/Apache.

How?

To do this, get explicit approval from each contributor of copyrightable work
(as not all contributions qualify for copyright) and then add the following to
your README:

## License

Licensed under either of
 * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
 * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
at your option.

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you shall be dual licensed as above, without any
additional terms or conditions.

and in your license headers, use the following boilerplate (based on that used in Rust):

// Copyright (c) 2015 t developers
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT
// license <LICENSE-MIT or http://opensource.org/licenses/MIT>,
// at your option. All files in the project carrying such
// notice may not be copied, modified, or distributed except
// according to those terms.

And don't forget to update the license metadata in your Cargo.toml!

Contributor checkoff

move binary to src

I don't know what the motivation for having the binary in its own directory with its own Cargo.toml is, but I think it makes more sense to just move main.rs to src and delete the other files.

MemWriter has been deprecated

error[E0433]: failed to resolve. Could not find `MemWriter` in `io`                                      
   --> src/cmds.rs:111:25                           
    |                     
111 |     let mw = ::std::io::MemWriter::new();     
    |                         ^^^^^^^^^ Could not find `MemWriter` in `io` 

Awkwardness with std::fmt::Display?

I'm trying to use tabwriter inside an impl of std::fmt::Display, and it seems really complex and inefficient. I'm currently doing it like this. Any suggestions on how to clean things up? Ideally I'd like to just write the table directly to the Formatter.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.