feat(02-03): wire main.rs with highlighter init, vault loading, and renderer
- Add highlighter::init_highlighter() call before render_markdown() - Load index.md via vault::load_document() with proper VaultDocument matching - Query terminal size before terminal init for initial render width - Render markdown via renderer::render_markdown() passing content and width - Pass raw content string to App::new() for resize re-rendering - Update App::new() call with all 4 arguments (is_login_shell, config, doc, raw) - All 7 modules declared: app, config, highlighter, renderer, signals, terminal, vault
This commit is contained in:
+32
-3
@@ -27,6 +27,35 @@ fn main() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 3a. Initialize syntax highlighting (one-time, loads embedded syntax definitions)
|
||||||
|
// Must be called before render_markdown() — highlighter uses OnceLock statics.
|
||||||
|
highlighter::init_highlighter();
|
||||||
|
|
||||||
|
// 3b. Load initial document (index.md from vault) and render it.
|
||||||
|
// We query the terminal size here for initial render width.
|
||||||
|
// On resize, the event loop re-renders with the updated width.
|
||||||
|
let initial_width = ratatui::crossterm::terminal::size()
|
||||||
|
.map(|(w, _)| w)
|
||||||
|
.unwrap_or(80);
|
||||||
|
|
||||||
|
let (initial_doc, raw_content) = match vault::load_document(&app_config.vault_path, "index.md") {
|
||||||
|
vault::VaultDocument::Loaded { path, content } => {
|
||||||
|
let filename = path
|
||||||
|
.file_name()
|
||||||
|
.map(|n| n.to_string_lossy().to_string())
|
||||||
|
.unwrap_or_else(|| "index.md".to_string());
|
||||||
|
let lines = renderer::render_markdown(&content, initial_width);
|
||||||
|
let doc = app::DocumentState::Loaded { filename, lines };
|
||||||
|
(doc, Some(content))
|
||||||
|
}
|
||||||
|
vault::VaultDocument::Missing { path } => {
|
||||||
|
(app::DocumentState::Missing { path }, None)
|
||||||
|
}
|
||||||
|
vault::VaultDocument::ReadError { path, reason } => {
|
||||||
|
(app::DocumentState::Error { path, reason }, None)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// ── TERMINAL PHASE ────────────────────────────────────────────────────────
|
// ── TERMINAL PHASE ────────────────────────────────────────────────────────
|
||||||
// Install safety envelope BEFORE terminal init so panics during init are caught.
|
// Install safety envelope BEFORE terminal init so panics during init are caught.
|
||||||
|
|
||||||
@@ -54,9 +83,9 @@ fn main() {
|
|||||||
|
|
||||||
// ── EVENT LOOP PHASE ──────────────────────────────────────────────────────
|
// ── EVENT LOOP PHASE ──────────────────────────────────────────────────────
|
||||||
|
|
||||||
// 7. Create app state and run the event loop
|
// 7. Create app state and run the event loop.
|
||||||
// app_config is stored in App for Phase 2+ use (vault_path, theme).
|
// raw_content is passed so the event loop can re-render on terminal resize.
|
||||||
let mut app_state = app::App::new(is_login_shell, app_config);
|
let mut app_state = app::App::new(is_login_shell, app_config, initial_doc, raw_content);
|
||||||
let shutdown_reason = app_state.run_event_loop(&mut term, &signal_flags);
|
let shutdown_reason = app_state.run_event_loop(&mut term, &signal_flags);
|
||||||
|
|
||||||
// ── SHUTDOWN PHASE ────────────────────────────────────────────────────────
|
// ── SHUTDOWN PHASE ────────────────────────────────────────────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user