cargo-tuwui 0.1.0

A TUI for editing cargo manifest (Cargo.toml) files
#![warn(clippy::pedantic)]
#![warn(clippy::nursery)]

use displaydoc::Display;
use error_stack::{FutureExt, Report, ResultExt};
use thiserror::Error;

use crate::app::App;

mod app;
mod config;
mod errors;
mod event;
mod features;
mod keybinds;
mod logging;
mod manifest;
mod ui;
mod updater;

#[derive(Debug, Error, Display)]
/// An error occurred while running the application
pub enum Error {
    /// An error occurred while initializing the application.
    Init,
    /// An error occurred while running the TUI.
    Run,
}

#[tokio::main]
async fn main() -> Result<(), Report<Error>> {
    errors::init();
    let config = config::Config::new()?;

    logging::init(&config)?;

    let terminal = ratatui::init();

    let current_dir = std::env::current_dir()
        .attach("Failed to get current directory")
        .change_context(Error::Init)?;

    let manifest_path = current_dir.join("Cargo.toml");

    let app = App::new(manifest_path)
        .attach("Failed to initialize application")
        .change_context(Error::Init)?;

    app.queue_check_for_updates()
        .attach("Failed to queue check for updates")
        .change_context(Error::Init)?;

    let result = app.run(terminal).change_context(Error::Run).await;

    ratatui::restore();

    result
}