Skip to content

Commit

Permalink
feat: ✨ main committing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-labs committed Sep 24, 2024
1 parent 9c4170d commit 7f4ce1e
Show file tree
Hide file tree
Showing 35 changed files with 1,153 additions and 793 deletions.
155 changes: 25 additions & 130 deletions Cargo.lock

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

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ debug-assertions = false

[workspace.dependencies]
indoc = "2.0.5"
matetui = "0.3.2"
eyre = { version = "0.6.12", default-features = false, features = [
"auto-install",
] }
lool = { git = "https://github.com/lucodear/lool", version = "0.9.0", features = [
"cli.stylize",
"cli.tui",
"cli.tui.widgets"
"cli.stylize"
] }
strum = { version = "0.26.1", features = ["derive"] }
serde = { version = "1.0.210", features = ["derive"] }
Expand Down
1 change: 1 addition & 0 deletions coco/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ tokio = { workspace = true }
indoc = { workspace = true }
strum = { workspace = true, features = ["derive"] }
serde = { workspace = true, features = ["derive"] }
matetui = { workspace = true }
tui = { path = "../tui" }
cc-core = { path = "../core" }
pico-args = "0.5.0"
Expand Down
78 changes: 42 additions & 36 deletions coco/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ mod cli;
mod view;

use {
cc_core::git,
cli::{
action::{get_action, Action},
helpver::{help, version},
},
eyre::Result,
lool::{
components, s,
tui::{Action as TuiAction, App, Kb},
matetui::{
components, kb, ratatui::crossterm::style::Stylize, Action as MatetuiAction, App,
ComponentAccessors,
},
view::main_component::MainComponent,
};
Expand All @@ -20,40 +21,47 @@ async fn main() -> Result<()> {

match action {
Action::Help | Action::Version => handle_cli_action(action)?,
_ => {
let main = MainComponent::new();
_ => match git::list_staged(Some("./")) {
Ok(staged) => {
if staged.is_empty() {
println!(
"{}",
"Nothing to commit! Stage your changes first ('git add .')".red()
);
return Ok(());
}

let mut app = App::new(
Kb::from([
("<ctrl-c>", TuiAction::Quit.to_string()),
// ("<q>", TuiAction::Quit.to_string()),
// ("<esc>", TuiAction::Quit.to_string()),
("<up>", s!("kb:up")),
("<down>", s!("kb:down")),
("<left>", s!("kb:left")),
("<right>", s!("kb:right")),
// ("<ctrl-left>", s!("kb:prev")),
// ("<ctrl-right>", s!("builder:next")),
// ("<i>", s!("kb:i")),
// ("<backspace>", s!("kb:backspace")),
("<home>", s!("kb:home")),
("<end>", s!("kb:end")),
("<enter>", s!("kb:enter")),
("<pageup>", s!("kb:pageup")),
("<pagedown>", s!("kb:pagedown")),
("<space>", s!("kb:space")),
// ("<shift-g>", s!("kb:shift-g")),
]),
components![main],
)?;
let mut app = App::default()
.with_frame_rate(32)
.with_tick_rate(32)
.with_keybindings(kb! {
"<ctrl-c>" => MatetuiAction::Quit,
"<up>" => "kb:up",
"<down>" => "kb:down",
"<left>" => "kb:left",
"<right>" => "kb:right",
"<home>" => "kb:home",
"<end>" => "kb:end",
"<enter>" => "kb:enter",
"<pageup>" => "kb:pageup",
"<pagedown>" => "kb:pagedown",
"<space>" => "kb:space",
"<f2>" => "kb:f2",
})
.with_components(components![MainComponent::new().as_active()]);

app.tick_rate = 32.into();
app.frame_rate = 32.into();
app.run().await?;

app.run().await?;

println!("\n\n{{ }} Chau!\n");
}
// TODO: Show the final commit message before quitting
// When we have succesfully committed the changes, we should show the final
// commit information to the user before quitting the app.
// To do this, we will need access to the `AppState` from the `main` function.
// This means that we will need to actually create the `AppState` there and
// pass it down to the `MainComponent`.
println!("\n\n{{ }} Chau!\n");
}
Err(e) => println!("{}: {}", "Error listing staged files".red(), e),
},
}

Ok(())
Expand All @@ -64,7 +72,5 @@ fn handle_cli_action(action: Action) -> Result<()> {
Action::Help => help(),
Action::Version => version(),
_ => Ok(()),
// Action::Default => seeker::collect(None),
// Action::DefaultWithDir(dir) => seeker::collect(Some(dir)),
}
}
Loading

0 comments on commit 7f4ce1e

Please sign in to comment.