Skip to content

Commit

Permalink
log update
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodesdev committed Aug 6, 2024
1 parent c19d663 commit f1e2b5f
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 4 deletions.
2 changes: 1 addition & 1 deletion 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
@@ -1,6 +1,6 @@
[package]
name = "clipcat"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
description = "A command line tool for copying the contents to clipboard of multiple files in one go."
repository = "https://github.com/dcodesdev/clipcat"
Expand Down
1 change: 0 additions & 1 deletion src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ fn read_directory_contents_recursive(
let mut file = fs::File::open(&path)?;

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

Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod cli;
mod clip;
mod fs;
mod num;
mod run;
mod tiktoken;

Expand Down
31 changes: 31 additions & 0 deletions src/num.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/// Adds comma every 3 digits
pub fn format_number(n: f64) -> String {
let n = n.to_string();
let mut result = String::new();
let mut count = 0;

for c in n.chars().rev() {
count += 1;
result.push(c);

if count % 3 == 0 && count != n.len() {
result.push(',');
}
}

result.chars().rev().collect()
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_format_number() {
assert_eq!(format_number(1000.0), "1,000");
assert_eq!(format_number(1000000.0), "1,000,000");
assert_eq!(format_number(1000000000.0), "1,000,000,000");
assert_eq!(format_number(1000000000000.0), "1,000,000,000,000");
assert_eq!(format_number(999999.0), "999,999");
}
}
9 changes: 8 additions & 1 deletion src/run.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use clap::Parser;
use std::path::Path;

use crate::{cli, clip::copy_to_clipboard, fs::read_directory_contents, tiktoken::count_tokens};
use crate::{
cli, clip::copy_to_clipboard, fs::read_directory_contents, num::format_number,
tiktoken::count_tokens,
};

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

copy_to_clipboard(&contents)?;

let char_count = format_number(contents.chars().count() as f64);

println!("✅ {} characters copied to clipboard.", char_count);

if token {
let tokens = count_tokens(&contents)?;
println!("{} GPT-4 tokens.", tokens);
Expand Down

0 comments on commit f1e2b5f

Please sign in to comment.