-
Notifications
You must be signed in to change notification settings - Fork 0
API Reference
This document describes the public API types and functions in Forge.
Represents a development task or module.
pub struct Module {
pub id: String,
pub name: String,
pub description: String,
pub owner_id: Option<String>,
pub status: ModuleStatus,
pub progress: u8,
}
pub enum ModuleStatus {
Pending,
Current,
Completed,
}Methods:
-
new(name: String) -> Self— Create a new module -
load_from_file(path: &str) -> Result<Vec<Module>>— Load modules from.forgefile -
save_to_file(&self, path: &str) -> Result<()>— Save modules to file
Example:
let mut module = Module::new("Implement auth".to_string());
module.progress = 50;
module.status = ModuleStatus::Current;Represents a team member.
pub struct Developer {
pub id: String,
pub name: String,
pub email: String,
}Methods:
-
new(name: String, email: String) -> Self— Create a new developer -
load_from_file(path: &str) -> Result<Vec<Developer>>— Load developers from file -
save_to_file(&self, path: &str) -> Result<()>— Save developers to file
Example:
let dev = Developer::new("Alice".to_string(), "alice@example.com".to_string());Represents a project with associated modules and developers.
pub struct Project {
pub id: String,
pub name: String,
pub path: String,
pub modules: Vec<Module>,
pub developers: Vec<Developer>,
}Wrapper around git2::Repository for common Git operations.
pub struct GitRepository {
repo: git2::Repository,
}Methods:
Open a Git repository at the specified path.
let repo = GitRepository::open(Path::new("."))?;Get current file status.
let status = repo.get_status()?;
// Returns files: modified, staged, added, deletedGet diff for a specific file.
let diff = repo.get_diff("src/main.rs")?;Get commit history (last N commits).
let commits = repo.get_history(50)?;List all local branches.
let branches = repo.list_branches()?;Create a new branch.
repo.create_branch("feature/my-feature")?;Switch to an existing branch.
repo.switch_branch("main")?;Delete a branch.
repo.delete_branch("feature/old-feature")?;Get the name of the current branch.
let branch = repo.get_current_branch()?;Create a commit with staged files.
repo.commit("Add authentication", &["src/auth.rs", "src/main.rs"])?;All UI screens implement the Screen trait:
pub trait Screen {
fn handle_key(&mut self, key: KeyEvent) -> Result<()>;
fn render(&self, f: &mut Frame);
fn on_enter(&mut self) -> Result<()>;
fn on_exit(&mut self) -> Result<()>;
}Methods:
Process keyboard input for this screen.
Render this screen to the terminal frame.
Called when screen becomes active. Use for initialization.
Called when screen is deactivated. Use for cleanup.
Example:
struct MyScreen {
state: String,
}
impl Screen for MyScreen {
fn handle_key(&mut self, key: KeyEvent) -> Result<()> {
match key.code {
KeyCode::Char('q') => {
// handle quit
}
_ => {}
}
Ok(())
}
fn render(&self, f: &mut Frame) {
// render to frame
}
fn on_enter(&mut self) -> Result<()> {
// initialize
Ok(())
}
fn on_exit(&mut self) -> Result<()> {
// cleanup
Ok(())
}
}Manages UI state and rendering context.
pub struct RenderContext {
pub current_screen: Screen,
pub focus: Focus,
pub theme: Theme,
pub is_search_active: bool,
pub search_query: String,
}Methods:
-
new() -> Self— Create a new render context -
switch_screen(&mut self, screen: Box<dyn Screen>)— Switch to a new screen -
set_focus(&mut self, focus: Focus)— Set which pane has focus -
set_theme(&mut self, theme: Theme)— Change the theme
All fallible operations return color_eyre::Result<T>:
use color_eyre::Result;
fn risky_operation() -> Result<String> {
let value = get_something()
.context("Failed to get something")?;
Ok(value)
}Complete example using core APIs:
use forge::{GitRepository, Module, Developer};
use std::path::Path;
fn main() -> color_eyre::Result<()> {
// Open repository
let repo = GitRepository::open(Path::new("."))?;
// Get current branch
let branch = repo.get_current_branch()?;
println!("On branch: {}", branch);
// Get file status
let status = repo.get_status()?;
println!("Modified files: {}", status.len());
// Get diff for a file
if let Some(file) = status.first() {
let diff = repo.get_diff(&file.path)?;
println!("Diff:\n{}", diff);
}
// Load existing modules
let modules = Module::load_from_file(".forge")?;
println!("Modules: {}", modules.len());
Ok(())
}None currently. The API is still evolving and may change between versions.
- Architecture — Detailed system design
- Development — Contributing guidelines