Skip to content

Commit d0c5fb2

Browse files
committed
wip: massive refactor of collection storage and layout
1 parent 6b55b92 commit d0c5fb2

File tree

28 files changed

+2082
-1877
lines changed

28 files changed

+2082
-1877
lines changed

.rustfmt.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
edition = "2021"
2+
unstable_features = true
3+
use_field_init_shorthand = true
4+
imports_granularity = "Module"
5+
group_imports = "StdExternalCrate"
6+
format_code_in_doc_comments = true
7+
reorder_impl_items = true
8+
single_line_let_else_max_width = 100
9+
single_line_if_else_max_width = 100
10+
max_width = 120
11+

Cargo.lock

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
[workspace]
2-
members = ["hac-config", "hac-core", "hac-client", "hac-colors", "hac-cli"]
2+
members = [
3+
"hac-config",
4+
"hac-core",
5+
"hac-client",
6+
"hac-colors",
7+
"hac-cli",
8+
"hac-store",
9+
"hac-loader",
10+
]
311
default-members = ["hac-client"]
412
resolver = "2"
513

@@ -10,10 +18,12 @@ name = "hac"
1018
version = "0.2.0"
1119

1220
[workspace.dependencies]
21+
hac-store = { path = "hac-store" }
1322
hac-config = { path = "hac-config" }
1423
hac-core = { path = "hac-core" }
1524
hac-colors = { path = "hac-colors" }
1625
hac-cli = { path = "hac-cli" }
26+
hac-loader = { path = "hac-loader" }
1727

1828
anyhow = "1.0.81"
1929
crossterm = { version = "0.27.0", features = ["event-stream"] }

hac-client/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ hac-core.workspace = true
1818
hac-config.workspace = true
1919
hac-colors.workspace = true
2020
hac-cli.workspace = true
21+
hac-loader.workspace = true
22+
hac-store.workspace = true
2123

2224
anyhow.workspace = true
2325
crossterm.workspace = true

hac-client/src/app.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use hac_core::{collection::Collection, command::Command};
1+
use hac_core::command::Command;
2+
use hac_loader::collection_loader::CollectionMeta;
23

34
use crate::event_pool::{Event, EventPool};
45
use crate::pages::{Eventful, Renderable};
@@ -19,19 +20,13 @@ pub struct App<'app> {
1920
impl<'app> App<'app> {
2021
pub fn new(
2122
colors: &'app hac_colors::Colors,
22-
collections: Vec<Collection>,
23+
collections: Vec<CollectionMeta>,
2324
config: &'app hac_config::Config,
2425
dry_run: bool,
2526
) -> anyhow::Result<Self> {
2627
let terminal = Terminal::new(CrosstermBackend::new(std::io::stdout()))?;
2728
Ok(Self {
28-
screen_manager: ScreenManager::new(
29-
terminal.size()?,
30-
colors,
31-
collections,
32-
config,
33-
dry_run,
34-
)?,
29+
screen_manager: ScreenManager::new(terminal.size()?, colors, collections, config, dry_run)?,
3530
event_pool: EventPool::new(60f64, 30f64),
3631
should_quit: false,
3732
terminal,
@@ -46,8 +41,7 @@ impl<'app> App<'app> {
4641

4742
startup()?;
4843

49-
self.screen_manager
50-
.register_command_handler(command_tx.clone())?;
44+
self.screen_manager.register_command_handler(command_tx.clone())?;
5145

5246
loop {
5347
{
@@ -74,9 +68,7 @@ impl<'app> App<'app> {
7468
})?;
7569
}
7670
event => {
77-
if let Some(command) =
78-
self.screen_manager.handle_event(Some(event.clone()))?
79-
{
71+
if let Some(command) = self.screen_manager.handle_event(Some(event.clone()))? {
8072
command_tx
8173
.send(command)
8274
.expect("failed to send command through channel")

hac-client/src/main.rs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use hac_cli::RuntimeBehavior;
22
use hac_client::app;
3-
use hac_core::collection::collection;
3+
use hac_core::collection;
44

55
fn setup_tracing() -> anyhow::Result<tracing_appender::non_blocking::WorkerGuard> {
6-
let (data_dir, logfile) = hac_config::log_file();
6+
let logfile = hac_config::LOGFILE;
7+
let data_dir = hac_loader::data_dir();
78
let appender = tracing_appender::rolling::never(data_dir, logfile);
89
let (writer, guard) = tracing_appender::non_blocking(appender);
910
let subscriber = tracing_subscriber::FmtSubscriber::builder()
@@ -21,29 +22,30 @@ fn setup_tracing() -> anyhow::Result<tracing_appender::non_blocking::WorkerGuard
2122
async fn main() -> anyhow::Result<()> {
2223
let runtime_behavior = hac_cli::Cli::parse_args();
2324

24-
match runtime_behavior {
25-
RuntimeBehavior::PrintConfigPath => hac_cli::Cli::print_config_path(
26-
hac_config::get_config_dir_path(),
27-
hac_config::get_usual_path(),
28-
),
29-
RuntimeBehavior::PrintDataPath => {
30-
hac_cli::Cli::print_data_path(hac_config::get_collections_dir())
31-
}
32-
RuntimeBehavior::DumpDefaultConfig => {
33-
hac_cli::Cli::print_default_config(hac_config::default_as_str())
34-
}
35-
_ => {}
36-
}
25+
//match runtime_behavior {
26+
// RuntimeBehavior::PrintConfigPath => hac_cli::Cli::print_config_path(
27+
// hac_config::get_config_dir_path(),
28+
// hac_config::get_usual_path(),
29+
// ),
30+
// RuntimeBehavior::PrintDataPath => {
31+
// hac_cli::Cli::print_data_path(hac_config::get_collections_dir())
32+
// }
33+
// RuntimeBehavior::DumpDefaultConfig => {
34+
// hac_cli::Cli::print_default_config(hac_config::default_as_str())
35+
// }
36+
// _ => {}
37+
//}
3738

3839
let dry_run = runtime_behavior.eq(&RuntimeBehavior::DryRun);
3940

4041
let _guard = setup_tracing()?;
41-
hac_config::get_or_create_data_dir();
42-
let config = hac_config::load_config();
42+
hac_loader::get_or_create_data_dir();
43+
hac_loader::get_or_create_collections_dir();
4344

45+
let collections = hac_loader::collection_loader::collections_metadata()?;
4446
let colors = hac_colors::Colors::default();
45-
let mut collections = collection::get_collections_from_config()?;
46-
collections.sort_by_key(|key| key.info.name.clone());
47+
let config = hac_config::load_config();
48+
4749
let mut app = app::App::new(&colors, collections, &config, dry_run)?;
4850
app.run().await?;
4951

0 commit comments

Comments
 (0)