gitj 0.2.0

A gitk-style, Windows 3.1-flavored git repository browser and commit helper built on the Saudade toolkit
Documentation
//! gitj — a gitk-style git repository browser and commit helper.
//!
//! Usage: `gitj [PATH]`. With no argument it opens the repository
//! containing the current working directory; otherwise it discovers the
//! repository at (or above) PATH.

use std::process::ExitCode;
use std::rc::Rc;

use journey::backend::{Git2Backend, RepoBackend};
use journey::ui::GitClient;
use saudade::{App, Theme, WindowConfig};

const WINDOW_W: i32 = 900;
const WINDOW_H: i32 = 640;
/// Floor on the resizable window, so the panes never collapse past the point
/// where the narrow (third-width) commit/browse layout still works.
const MIN_WINDOW_W: i32 = 450;
const MIN_WINDOW_H: i32 = 320;

fn main() -> ExitCode {
    let path = std::env::args().nth(1).unwrap_or_else(|| ".".to_string());

    let backend: Rc<dyn RepoBackend> = match Git2Backend::open(&path) {
        Ok(backend) => Rc::new(backend),
        Err(err) => {
            eprintln!(
                "gitj: cannot open a git repository at {path:?}: {}",
                err.message()
            );
            return ExitCode::FAILURE;
        }
    };

    let title = format!("Git Journey — {}", backend.path());
    // File ▸ Reload re-discovers the repository at the same path.
    let reload_path = path.clone();
    let root = GitClient::new(backend).with_reopen(Box::new(move || {
        Git2Backend::open(&reload_path)
            .ok()
            .map(|b| Rc::new(b) as Rc<dyn RepoBackend>)
    }));

    App::new(
        WindowConfig::new(title, WINDOW_W, WINDOW_H)
            .resizable(true)
            .min_size(MIN_WINDOW_W, MIN_WINDOW_H),
        root,
    )
    .with_theme(Theme::windows_31())
    .run();

    ExitCode::SUCCESS
}