Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 63 additions & 1 deletion Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fastcommit"
version = "0.3.0"
version = "0.4.0"
description = "AI-based command line tool to quickly generate standardized commit messages."
edition = "2021"
authors = ["longjin <fslongjin@vip.qq.com>"]
Expand All @@ -22,4 +22,6 @@ reqwest = { version = "0.12.9", features = ["json"] }
serde = { version = "1.0.218", features = ["derive"] }
serde_json = "1.0.134"
tokio = { version = "1.43.0", features = ["full"] }
rand = "0.8.5"
indicatif = "0.17.8"
toml = "0.8.20"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ You can install `fastcommit` using the following method:

```bash
# Install using cargo
cargo install --git https://github.com/fslongjin/fastcommit --tag v0.3.0
cargo install --git https://github.com/fslongjin/fastcommit --tag v0.4.0
```

## Usage
Expand Down
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

```bash
# 使用 cargo 安装
cargo install --git https://github.com/fslongjin/fastcommit --tag v0.3.0
cargo install --git https://github.com/fslongjin/fastcommit --tag v0.4.0
```

## 使用
Expand Down
69 changes: 69 additions & 0 deletions src/animation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use indicatif::{ProgressBar, ProgressStyle};
use rand::seq::SliceRandom;
use std::time::Duration;

const RANDOM_PHRASES: &[&str] = &[
"🤔 正在思考如何优雅地描述这次变更...",
"✨ 魔法正在发生,请稍候...",
"🚀 加速代码提交中...",
"🧠 AI大脑正在疯狂运转...",
"🌈 生成彩虹般绚丽的提交信息...",
"⚡ 闪电般快速分析代码...",
"🎨 为你的代码添加艺术气息...",
"🕺 Gee Kee Tai May! Oh Baby! ",
"💃 Gee Kee 实在是太美! ",
"🎪 代码马戏团表演中...",
"🍵 喝杯茶,马上就好...",
"🎸 为代码变更谱写乐章...",
"🏎️ 极速代码分析中...",
"🎭 戏剧化地描述你的变更...",
"🌌 在代码宇宙中探索ing...",
];

pub struct Spinner {
pb: ProgressBar,
}

impl Spinner {
pub fn new() -> Self {
let pb = ProgressBar::new_spinner();
pb.set_style(
ProgressStyle::default_spinner()
.tick_strings(&["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"])
.template("{spinner:.cyan} {msg:.dim}")
.unwrap(),
);
pb.enable_steady_tick(Duration::from_millis(100));

Self { pb }
}

pub async fn start_with_random_messages(&self) {
let pb = self.pb.clone();
tokio::spawn(async move {
let mut interval = tokio::time::interval(Duration::from_secs(2));
loop {
interval.tick().await;
let mut rng = rand::thread_rng();
if let Some(phrase) = RANDOM_PHRASES.choose(&mut rng) {
pb.set_message(phrase.to_string());
}
}
});
}

#[allow(dead_code)]
pub fn finish_with_message(&self, message: &str) {
self.pb.finish_with_message(message.to_string());
}

pub fn finish(&self) {
self.pb.finish_and_clear();
}
}

impl Drop for Spinner {
fn drop(&mut self) {
self.finish();
}
}
13 changes: 13 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use clap::Parser;
use log::error;

mod animation;
mod cli;
mod config;
mod constants;
Expand All @@ -12,6 +13,11 @@ mod update_checker;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
env_logger::init();

// 启动spinner动画
let spinner = animation::Spinner::new();
spinner.start_with_random_messages().await;

let args = cli::Args::parse();
let mut config = config::load_config().await?;

Expand All @@ -36,16 +42,23 @@ async fn main() -> anyhow::Result<()> {
// 1. --gb --m 同时:生成分支名 + 提交信息
// 2. 仅 --gb:只生成分支名
// 3. 默认(无 --gb 或仅 --m):生成提交信息

if args.generate_branch && args.generate_message {
let (branch_name, msg) = generate::generate_both(&args, &config).await?;
// 停止spinner动画
spinner.finish();
println!("Generated branch name: {}", branch_name);
println!("{}", msg);
} else if args.generate_branch {
let branch_name = generate::generate_branch(&args, &config).await?;
// 停止spinner动画
spinner.finish();
println!("Generated branch name: {}", branch_name);
} else {
// 包括:无参数 或 仅 --m
let msg = generate::generate(&args, &config).await?;
// 停止spinner动画
spinner.finish();
println!("{}", msg);
}
Ok(())
Expand Down