Skip to content

Commit

Permalink
fix: beautify output (#9)
Browse files Browse the repository at this point in the history
* build: add tasks.json for vscode

* fix: locale supports fallback of en

* test: process_inputs instead of process_input

* fix: output margins

* fix: error handling for is a directory
  • Loading branch information
guuzaa authored Sep 21, 2024
1 parent 5c36633 commit 3ccb193
Show file tree
Hide file tree
Showing 8 changed files with 448 additions and 166 deletions.
103 changes: 103 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "cargo build",
"type": "shell",
"command": "cargo build -r",
"group": {
"kind": "build",
"isDefault": false
},
"presentation": {
"echo": true,
"reveal": "always",
"close": false
}
},
{
"label": "cargo check",
"type": "shell",
"command": "cargo check",
"group": {
"kind": "build",
"isDefault": false
},
"presentation": {
"echo": true,
"reveal": "always",
"close": false
}
},
{
"label": "cargo clean",
"type": "shell",
"command": "cargo clean",
"group": {
"kind": "build",
"isDefault": false
},
"presentation": {
"echo": true,
"reveal": "always",
"close": false
}
},
{
"label": "cargo run",
"type": "shell",
"command": "cargo run",
"group": {
"kind": "build",
"isDefault": false
},
"presentation": {
"echo": true,
"reveal": "always",
"close": false
}
},
{
"label": "cargo test",
"type": "shell",
"command": "cargo test",
"group": {
"kind": "build",
"isDefault": false
},
"presentation": {
"echo": true,
"reveal": "always",
"close": false
}
},
{
"label": "cargo clippy",
"type": "shell",
"command": "cargo clippy -- -D warnings",
"group": {
"kind": "build",
"isDefault": false
},
"presentation": {
"echo": true,
"reveal": "always",
"close": false
}
},
{
"label": "cargo fmt",
"type": "shell",
"command": "cargo fmt -v",
"group": {
"kind": "build",
"isDefault": false
},
"presentation": {
"echo": true,
"reveal": "always",
"close": false
}
}
]
}
19 changes: 13 additions & 6 deletions locales/app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ error_writing_stdout:
kr: "tc: 표준 출력에 쓰기 중 오류가 발생했습니다"
de: "tc: Fehler beim Schreiben in die Standardausgabe"
error_reading_file:
en: "tc: %{filename}: Error reading file: %{error}"
ja: "tc: %{filename}: ファイルの読み込み中にエラーが発生しました: %{error}"
zh-CN: "tc: %{filename}: 读取文件时发生错误: %{error}"
zh-TW: "tc: %{filename}: 讀取文件時發生錯誤: %{error}"
kr: "tc: %{filename}: 파일 읽기 중 오류가 발생했습니다: %{error}"
de: "tc: %{filename}: Fehler beim Lesen der Datei: %{error}"
en: "tc: %{filename}: Error reading file"
ja: "tc: %{filename}: ファイルの読み込み中にエラーが発生しました"
zh-CN: "tc: %{filename}: 读取文件时发生错误"
zh-TW: "tc: %{filename}: 讀取文件時發生錯誤"
kr: "tc: %{filename}: 파일 읽기 중 오류가 발생했습니다"
de: "tc: %{filename}: Fehler beim Lesen der Datei"
error_opening_file:
en: "tc: %{filename}: Error opening file: %{error}"
ja: "tc: %{filename}: ファイルを開く際にエラーが発生しました: %{error}"
Expand All @@ -41,6 +41,13 @@ error_not_found:
zh-TW: "tc: %{filename}: 文件不存在"
kr: "tc: %{filename}: 파일이 없습니다"
de: "tc: %{filename}: Datei nicht gefunden"
error_is_a_directory:
en: "tc: %{filename}: Is a directory"
ja: "tc: %{filename}: ディレクトリです"
zh-CN: "tc: %{filename}: 是一个目录"
zh-TW: "tc: %{filename}: 是一個目錄"
kr: "tc: %{filename}: 디렉토리입니다"
de: "tc: %{filename}: Ist ein Verzeichnis"
total:
en: "total"
ja: "合計"
Expand Down
4 changes: 2 additions & 2 deletions src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl Cli {
let options = CountOptions {
show_lines: cli.lines,
show_words: cli.words,
show_bytes: cli.chars,
show_chars: cli.chars,
show_tokens: cli.tokens,
tokenizer_model: cli.model.unwrap_or(TokenizerModel::GPT3),
};
Expand All @@ -65,7 +65,7 @@ impl Cli {
CountOptions {
show_lines: true,
show_words: true,
show_bytes: true,
show_chars: true,
show_tokens: true,
tokenizer_model: options.tokenizer_model,
}
Expand Down
8 changes: 4 additions & 4 deletions src/counts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::cmd::TokenizerModel;
pub struct CountOptions {
pub show_lines: bool,
pub show_words: bool,
pub show_bytes: bool,
pub show_chars: bool,
pub show_tokens: bool,
pub tokenizer_model: TokenizerModel,
}
Expand All @@ -12,7 +12,7 @@ impl CountOptions {
pub fn count_enabled_options(&self) -> u8 {
self.show_lines as u8
+ self.show_words as u8
+ self.show_bytes as u8
+ self.show_chars as u8
+ self.show_tokens as u8
}
}
Expand All @@ -21,15 +21,15 @@ impl CountOptions {
pub struct InputCounts {
pub lines: usize,
pub words: usize,
pub bytes: usize,
pub chars: usize,
pub tokens: usize,
}

impl std::ops::AddAssign for InputCounts {
fn add_assign(&mut self, other: Self) {
self.lines += other.lines;
self.words += other.words;
self.bytes += other.bytes;
self.chars += other.chars;
self.tokens += other.tokens;
}
}
Loading

0 comments on commit 3ccb193

Please sign in to comment.