2025-11-09 03:00:20 +01:00
|
|
|
use anyhow::{bail, Result};
|
Initial commit: Piglet - Animated figlet wrapper
Add complete Rust implementation with:
- 20+ motion effects (fade, slide, scale, typewriter, wave, bounce, etc.)
- 18+ easing functions (linear, quad, cubic, elastic, back, bounce)
- Color support (CSS4 colors, hex codes, gradients)
- Figlet integration with custom fonts and options
- Cross-platform support (Linux, macOS, Windows)
- Comprehensive CI/CD workflows
- Full test suite with integration tests
- Documentation (README.md, CLAUDE.md)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-09 01:53:26 +01:00
|
|
|
use lazy_static::lazy_static;
|
2025-11-09 03:00:20 +01:00
|
|
|
use regex::Regex;
|
Initial commit: Piglet - Animated figlet wrapper
Add complete Rust implementation with:
- 20+ motion effects (fade, slide, scale, typewriter, wave, bounce, etc.)
- 18+ easing functions (linear, quad, cubic, elastic, back, bounce)
- Color support (CSS4 colors, hex codes, gradients)
- Figlet integration with custom fonts and options
- Cross-platform support (Linux, macOS, Windows)
- Comprehensive CI/CD workflows
- Full test suite with integration tests
- Documentation (README.md, CLAUDE.md)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-09 01:53:26 +01:00
|
|
|
|
|
|
|
|
lazy_static! {
|
2025-11-09 03:00:20 +01:00
|
|
|
static ref DURATION_REGEX: Regex = Regex::new(r"^(\d+(?:\.\d+)?)(ms|s|m|h)$").unwrap();
|
Initial commit: Piglet - Animated figlet wrapper
Add complete Rust implementation with:
- 20+ motion effects (fade, slide, scale, typewriter, wave, bounce, etc.)
- 18+ easing functions (linear, quad, cubic, elastic, back, bounce)
- Color support (CSS4 colors, hex codes, gradients)
- Figlet integration with custom fonts and options
- Cross-platform support (Linux, macOS, Windows)
- Comprehensive CI/CD workflows
- Full test suite with integration tests
- Documentation (README.md, CLAUDE.md)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-09 01:53:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Parse duration string to milliseconds
|
|
|
|
|
/// Supports: 3000ms, 0.3s, 5m, 0.5h
|
|
|
|
|
pub fn parse_duration(duration: &str) -> Result<u64> {
|
2025-11-09 03:00:20 +01:00
|
|
|
let caps = DURATION_REGEX
|
|
|
|
|
.captures(duration.trim())
|
Initial commit: Piglet - Animated figlet wrapper
Add complete Rust implementation with:
- 20+ motion effects (fade, slide, scale, typewriter, wave, bounce, etc.)
- 18+ easing functions (linear, quad, cubic, elastic, back, bounce)
- Color support (CSS4 colors, hex codes, gradients)
- Figlet integration with custom fonts and options
- Cross-platform support (Linux, macOS, Windows)
- Comprehensive CI/CD workflows
- Full test suite with integration tests
- Documentation (README.md, CLAUDE.md)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-09 01:53:26 +01:00
|
|
|
.ok_or_else(|| anyhow::anyhow!("Invalid duration format: {}", duration))?;
|
2025-11-09 03:00:20 +01:00
|
|
|
|
|
|
|
|
let value: f64 = caps[1]
|
|
|
|
|
.parse()
|
Initial commit: Piglet - Animated figlet wrapper
Add complete Rust implementation with:
- 20+ motion effects (fade, slide, scale, typewriter, wave, bounce, etc.)
- 18+ easing functions (linear, quad, cubic, elastic, back, bounce)
- Color support (CSS4 colors, hex codes, gradients)
- Figlet integration with custom fonts and options
- Cross-platform support (Linux, macOS, Windows)
- Comprehensive CI/CD workflows
- Full test suite with integration tests
- Documentation (README.md, CLAUDE.md)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-09 01:53:26 +01:00
|
|
|
.map_err(|_| anyhow::anyhow!("Invalid numeric value in duration"))?;
|
2025-11-09 03:00:20 +01:00
|
|
|
|
Initial commit: Piglet - Animated figlet wrapper
Add complete Rust implementation with:
- 20+ motion effects (fade, slide, scale, typewriter, wave, bounce, etc.)
- 18+ easing functions (linear, quad, cubic, elastic, back, bounce)
- Color support (CSS4 colors, hex codes, gradients)
- Figlet integration with custom fonts and options
- Cross-platform support (Linux, macOS, Windows)
- Comprehensive CI/CD workflows
- Full test suite with integration tests
- Documentation (README.md, CLAUDE.md)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-09 01:53:26 +01:00
|
|
|
let unit = &caps[2];
|
2025-11-09 03:00:20 +01:00
|
|
|
|
Initial commit: Piglet - Animated figlet wrapper
Add complete Rust implementation with:
- 20+ motion effects (fade, slide, scale, typewriter, wave, bounce, etc.)
- 18+ easing functions (linear, quad, cubic, elastic, back, bounce)
- Color support (CSS4 colors, hex codes, gradients)
- Figlet integration with custom fonts and options
- Cross-platform support (Linux, macOS, Windows)
- Comprehensive CI/CD workflows
- Full test suite with integration tests
- Documentation (README.md, CLAUDE.md)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-09 01:53:26 +01:00
|
|
|
let milliseconds = match unit {
|
|
|
|
|
"ms" => value,
|
|
|
|
|
"s" => value * 1000.0,
|
|
|
|
|
"m" => value * 60.0 * 1000.0,
|
|
|
|
|
"h" => value * 60.0 * 60.0 * 1000.0,
|
|
|
|
|
_ => bail!("Unknown time unit: {}", unit),
|
|
|
|
|
};
|
2025-11-09 03:00:20 +01:00
|
|
|
|
Initial commit: Piglet - Animated figlet wrapper
Add complete Rust implementation with:
- 20+ motion effects (fade, slide, scale, typewriter, wave, bounce, etc.)
- 18+ easing functions (linear, quad, cubic, elastic, back, bounce)
- Color support (CSS4 colors, hex codes, gradients)
- Figlet integration with custom fonts and options
- Cross-platform support (Linux, macOS, Windows)
- Comprehensive CI/CD workflows
- Full test suite with integration tests
- Documentation (README.md, CLAUDE.md)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-09 01:53:26 +01:00
|
|
|
if milliseconds < 0.0 {
|
|
|
|
|
bail!("Duration cannot be negative");
|
|
|
|
|
}
|
2025-11-09 03:00:20 +01:00
|
|
|
|
Initial commit: Piglet - Animated figlet wrapper
Add complete Rust implementation with:
- 20+ motion effects (fade, slide, scale, typewriter, wave, bounce, etc.)
- 18+ easing functions (linear, quad, cubic, elastic, back, bounce)
- Color support (CSS4 colors, hex codes, gradients)
- Figlet integration with custom fonts and options
- Cross-platform support (Linux, macOS, Windows)
- Comprehensive CI/CD workflows
- Full test suite with integration tests
- Documentation (README.md, CLAUDE.md)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-09 01:53:26 +01:00
|
|
|
Ok(milliseconds as u64)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
|
|
|
|
use super::*;
|
2025-11-09 03:00:20 +01:00
|
|
|
|
Initial commit: Piglet - Animated figlet wrapper
Add complete Rust implementation with:
- 20+ motion effects (fade, slide, scale, typewriter, wave, bounce, etc.)
- 18+ easing functions (linear, quad, cubic, elastic, back, bounce)
- Color support (CSS4 colors, hex codes, gradients)
- Figlet integration with custom fonts and options
- Cross-platform support (Linux, macOS, Windows)
- Comprehensive CI/CD workflows
- Full test suite with integration tests
- Documentation (README.md, CLAUDE.md)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-09 01:53:26 +01:00
|
|
|
#[test]
|
|
|
|
|
fn test_parse_milliseconds() {
|
|
|
|
|
assert_eq!(parse_duration("3000ms").unwrap(), 3000);
|
|
|
|
|
assert_eq!(parse_duration("500ms").unwrap(), 500);
|
|
|
|
|
}
|
2025-11-09 03:00:20 +01:00
|
|
|
|
Initial commit: Piglet - Animated figlet wrapper
Add complete Rust implementation with:
- 20+ motion effects (fade, slide, scale, typewriter, wave, bounce, etc.)
- 18+ easing functions (linear, quad, cubic, elastic, back, bounce)
- Color support (CSS4 colors, hex codes, gradients)
- Figlet integration with custom fonts and options
- Cross-platform support (Linux, macOS, Windows)
- Comprehensive CI/CD workflows
- Full test suite with integration tests
- Documentation (README.md, CLAUDE.md)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-09 01:53:26 +01:00
|
|
|
#[test]
|
|
|
|
|
fn test_parse_seconds() {
|
|
|
|
|
assert_eq!(parse_duration("3s").unwrap(), 3000);
|
|
|
|
|
assert_eq!(parse_duration("0.5s").unwrap(), 500);
|
|
|
|
|
assert_eq!(parse_duration("1.5s").unwrap(), 1500);
|
|
|
|
|
}
|
2025-11-09 03:00:20 +01:00
|
|
|
|
Initial commit: Piglet - Animated figlet wrapper
Add complete Rust implementation with:
- 20+ motion effects (fade, slide, scale, typewriter, wave, bounce, etc.)
- 18+ easing functions (linear, quad, cubic, elastic, back, bounce)
- Color support (CSS4 colors, hex codes, gradients)
- Figlet integration with custom fonts and options
- Cross-platform support (Linux, macOS, Windows)
- Comprehensive CI/CD workflows
- Full test suite with integration tests
- Documentation (README.md, CLAUDE.md)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-09 01:53:26 +01:00
|
|
|
#[test]
|
|
|
|
|
fn test_parse_minutes() {
|
|
|
|
|
assert_eq!(parse_duration("1m").unwrap(), 60000);
|
|
|
|
|
assert_eq!(parse_duration("0.5m").unwrap(), 30000);
|
|
|
|
|
}
|
2025-11-09 03:00:20 +01:00
|
|
|
|
Initial commit: Piglet - Animated figlet wrapper
Add complete Rust implementation with:
- 20+ motion effects (fade, slide, scale, typewriter, wave, bounce, etc.)
- 18+ easing functions (linear, quad, cubic, elastic, back, bounce)
- Color support (CSS4 colors, hex codes, gradients)
- Figlet integration with custom fonts and options
- Cross-platform support (Linux, macOS, Windows)
- Comprehensive CI/CD workflows
- Full test suite with integration tests
- Documentation (README.md, CLAUDE.md)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-09 01:53:26 +01:00
|
|
|
#[test]
|
|
|
|
|
fn test_parse_hours() {
|
|
|
|
|
assert_eq!(parse_duration("1h").unwrap(), 3600000);
|
|
|
|
|
assert_eq!(parse_duration("0.5h").unwrap(), 1800000);
|
|
|
|
|
}
|
2025-11-09 03:00:20 +01:00
|
|
|
|
Initial commit: Piglet - Animated figlet wrapper
Add complete Rust implementation with:
- 20+ motion effects (fade, slide, scale, typewriter, wave, bounce, etc.)
- 18+ easing functions (linear, quad, cubic, elastic, back, bounce)
- Color support (CSS4 colors, hex codes, gradients)
- Figlet integration with custom fonts and options
- Cross-platform support (Linux, macOS, Windows)
- Comprehensive CI/CD workflows
- Full test suite with integration tests
- Documentation (README.md, CLAUDE.md)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-09 01:53:26 +01:00
|
|
|
#[test]
|
|
|
|
|
fn test_invalid_format() {
|
|
|
|
|
assert!(parse_duration("invalid").is_err());
|
|
|
|
|
assert!(parse_duration("10").is_err());
|
|
|
|
|
assert!(parse_duration("10x").is_err());
|
|
|
|
|
}
|
2025-11-09 03:00:20 +01:00
|
|
|
}
|