Skip to content

Commit f1e2b5f

Browse files
committed
log update
1 parent c19d663 commit f1e2b5f

File tree

6 files changed

+42
-4
lines changed

6 files changed

+42
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clipcat"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
edition = "2021"
55
description = "A command line tool for copying the contents to clipboard of multiple files in one go."
66
repository = "https://github.com/dcodesdev/clipcat"

src/fs.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ fn read_directory_contents_recursive(
3939
let mut file = fs::File::open(&path)?;
4040

4141
if let Err(_) = file.read_to_string(&mut file_content) {
42-
println!("Skipping non UTF-8 file: {}", relative_path);
4342
return Ok(());
4443
}
4544

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
mod cli;
22
mod clip;
33
mod fs;
4+
mod num;
45
mod run;
56
mod tiktoken;
67

src/num.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/// Adds comma every 3 digits
2+
pub fn format_number(n: f64) -> String {
3+
let n = n.to_string();
4+
let mut result = String::new();
5+
let mut count = 0;
6+
7+
for c in n.chars().rev() {
8+
count += 1;
9+
result.push(c);
10+
11+
if count % 3 == 0 && count != n.len() {
12+
result.push(',');
13+
}
14+
}
15+
16+
result.chars().rev().collect()
17+
}
18+
19+
#[cfg(test)]
20+
mod tests {
21+
use super::*;
22+
23+
#[test]
24+
fn test_format_number() {
25+
assert_eq!(format_number(1000.0), "1,000");
26+
assert_eq!(format_number(1000000.0), "1,000,000");
27+
assert_eq!(format_number(1000000000.0), "1,000,000,000");
28+
assert_eq!(format_number(1000000000000.0), "1,000,000,000,000");
29+
assert_eq!(format_number(999999.0), "999,999");
30+
}
31+
}

src/run.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use clap::Parser;
22
use std::path::Path;
33

4-
use crate::{cli, clip::copy_to_clipboard, fs::read_directory_contents, tiktoken::count_tokens};
4+
use crate::{
5+
cli, clip::copy_to_clipboard, fs::read_directory_contents, num::format_number,
6+
tiktoken::count_tokens,
7+
};
58

69
pub fn run() -> anyhow::Result<()> {
710
let opts = cli::Opts::parse();
@@ -12,6 +15,10 @@ pub fn run() -> anyhow::Result<()> {
1215

1316
copy_to_clipboard(&contents)?;
1417

18+
let char_count = format_number(contents.chars().count() as f64);
19+
20+
println!("✅ {} characters copied to clipboard.", char_count);
21+
1522
if token {
1623
let tokens = count_tokens(&contents)?;
1724
println!("{} GPT-4 tokens.", tokens);

0 commit comments

Comments
 (0)