Skip to content

Commit 52ff61e

Browse files
committed
detect the width of the terminal
1 parent 0efc796 commit 52ff61e

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "xcompress"
3-
version = "0.10.6"
3+
version = "0.10.7"
44
authors = ["Magic Len <[email protected]>"]
55
repository = "https://github.com/magiclen/xcompress"
66
homepage = "https://magiclen.org/xcompress"
@@ -19,6 +19,7 @@ panic = "abort"
1919
[dependencies]
2020
subprocess = "0.1.13"
2121
num_cpus = "1.8.0"
22+
terminal_size = "0.1"
2223
clap = "2.32.0"
2324
byte-unit = "2"
2425
path-absolutize = "1.1.1"

src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//! 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.
33
44
extern crate clap;
5+
extern crate terminal_size;
56
extern crate num_cpus;
67
extern crate subprocess;
78
extern crate byte_unit;
@@ -11,11 +12,13 @@ use std::io::{ErrorKind, Read, BufReader, BufWriter, Write};
1112
use std::path::{Path, PathBuf};
1213
use std::env;
1314
use std::fs;
15+
1416
use byte_unit::*;
1517
use path_absolutize::Absolutize;
1618

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

21+
use terminal_size::{Width, terminal_size};
1922
use clap::{App, Arg, SubCommand};
2023

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

148+
let terminal_width = if let Some((Width(width), _)) = terminal_size() {
149+
width as usize
150+
} else {
151+
0
152+
};
153+
145154
let matches = App::new(APP_NAME)
155+
.set_term_width(terminal_width)
146156
.version(CARGO_PKG_VERSION)
147157
.author(CARGO_PKG_AUTHORS)
148158
.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()

0 commit comments

Comments
 (0)