Skip to content

Commit

Permalink
deps: Replace termsize with terminal_size, which is maintained (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikornaselur authored Sep 29, 2023
1 parent 47c7ba3 commit bfee3d5
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 93 deletions.
126 changes: 47 additions & 79 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ include = [
[dependencies]
textwrap = { version = "0.16", default-features = false, features = ["smawk"] }
clap = { version = "4", features = ["derive"] }
termsize = "0.1"
time = { version = "0.3", default-features = false, features = ["local-offset", "parsing"] }
anyhow = "1"
termcolor = "1.3.0"
terminal_size = "0.3.0"

[profile.release]
codegen-units = 1
Expand Down
6 changes: 3 additions & 3 deletions src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,18 @@ impl fmt::Display for Formatting {
impl Minute<'_> {
pub fn formatted(
&self,
width: usize,
width: u16,
main: &Formatting,
time: &Formatting,
author: &Formatting,
) -> Result<String> {
let quote = format!("{}\x00{}\x00{}", self.start, self.time, self.end);
let footer = format!("{} – {}", self.author, self.title);

let quote_options = Options::new(width)
let quote_options = Options::new(width.into())
.initial_indent(INITIAL_INDENT)
.subsequent_indent(SUBSEQUENT_INDENT);
let footer_options = Options::new(width)
let footer_options = Options::new(width.into())
.initial_indent(FOOTER_INDENT)
.subsequent_indent(FOOTER_INDENT);

Expand Down
20 changes: 10 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use anyhow::{bail, Result};
use clap::Parser;
use termcolor::Color;
use terminal_size::{terminal_size, Width};
use time::{format_description, OffsetDateTime, Time};

use litime::formatter::{Formatting, Style, FORMATTING_HELP};
use litime::minute::get_minute;

static MIN_WIDTH: usize = 20;
static MAX_WIDTH: usize = 120;
static DEFAULT_WIDTH: usize = 80; // If we fail to get terminal width
static MARGIN: usize = 5; // Margin on the right of the comment, only used when automatically detecting the terminal width
static MIN_WIDTH: u16 = 20;
static MAX_WIDTH: u16 = 120;
static DEFAULT_WIDTH: u16 = 80; // If we fail to get terminal width
static MARGIN: u16 = 5; // Margin on the right of the comment, only used when automatically detecting the terminal width

/// Hello
#[derive(Parser, Debug)]
Expand Down Expand Up @@ -64,11 +65,11 @@ struct Args {
///
/// If not set, then litime will try to detect the width of the terminal window, up to MAX_WIDTH (default 120 columns)
#[arg(short, long)]
width: Option<usize>,
width: Option<u16>,

/// The max width of the quote when not set by the WIDTH option
#[arg(long, default_value_t = MAX_WIDTH)]
max_width: usize,
max_width: u16,
}

fn main() -> Result<()> {
Expand All @@ -86,10 +87,9 @@ fn main() -> Result<()> {
let minute = get_minute(&timestamp, args.sfw)?;
let max_width = args.max_width;

let width: usize = args.width.unwrap_or_else(|| {
termsize::get()
.map(|size| std::cmp::min(size.cols as usize, max_width) - MARGIN)
.unwrap_or(DEFAULT_WIDTH)
let width = args.width.unwrap_or_else(|| match terminal_size() {
Some((Width(width), _)) => std::cmp::min(width, max_width) - MARGIN,
None => DEFAULT_WIDTH,
});

println!(
Expand Down

0 comments on commit bfee3d5

Please sign in to comment.