Skip to content

Commit

Permalink
detect the width of the terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
magiclen committed Apr 30, 2019
1 parent 0efc796 commit 52ff61e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xcompress"
version = "0.10.6"
version = "0.10.7"
authors = ["Magic Len <[email protected]>"]
repository = "https://github.com/magiclen/xcompress"
homepage = "https://magiclen.org/xcompress"
Expand All @@ -19,6 +19,7 @@ panic = "abort"
[dependencies]
subprocess = "0.1.13"
num_cpus = "1.8.0"
terminal_size = "0.1"
clap = "2.32.0"
byte-unit = "2"
path-absolutize = "1.1.1"
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! XCompress is a free file archiver utility on Linux, providing multi-format archiving to and extracting from ZIP, Z, GZIP, BZIP2, LZ, XZ, LZMA, 7ZIP, TAR, RAR ans ZSTD.
extern crate clap;
extern crate terminal_size;
extern crate num_cpus;
extern crate subprocess;
extern crate byte_unit;
Expand All @@ -11,11 +12,13 @@ use std::io::{ErrorKind, Read, BufReader, BufWriter, Write};
use std::path::{Path, PathBuf};
use std::env;
use std::fs;

use byte_unit::*;
use path_absolutize::Absolutize;

use subprocess::{Exec, ExitStatus, PopenError, Pipeline, NullFile};

use terminal_size::{Width, terminal_size};
use clap::{App, Arg, SubCommand};

// TODO -----Config START-----
Expand Down Expand Up @@ -142,7 +145,14 @@ impl Config {
"x -p password foo.rar # Extracts foo.rar with a password into current working directory"
];

let terminal_width = if let Some((Width(width), _)) = terminal_size() {
width as usize
} else {
0
};

let matches = App::new(APP_NAME)
.set_term_width(terminal_width)
.version(CARGO_PKG_VERSION)
.author(CARGO_PKG_AUTHORS)
.about(format!("XCompress is a free file archiver utility on Linux, providing multi-format archiving to and extracting from ZIP, Z, GZIP, BZIP2, LZ, XZ, LZMA, 7ZIP, TAR and RAR.\n\nEXAMPLES:\n{}", examples.iter()
Expand Down

0 comments on commit 52ff61e

Please sign in to comment.