New themes

This commit is contained in:
2026-02-06 00:19:16 +01:00
parent 51f52be4ce
commit 6ec3a86568
11 changed files with 1178 additions and 46 deletions

View File

@@ -4,7 +4,9 @@ use rand::rngs::StdRng;
use rand::SeedableRng;
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;
use std::sync::{Arc, LazyLock};
use cagire_ratatui::CompletionCandidate;
use crossbeam_channel::Sender;
@@ -25,6 +27,18 @@ use crate::state::{
const STEPS_PER_PAGE: usize = 32;
static COMPLETION_CANDIDATES: LazyLock<Vec<CompletionCandidate>> = LazyLock::new(|| {
model::WORDS
.iter()
.map(|w| CompletionCandidate {
name: w.name.to_string(),
signature: w.stack.to_string(),
description: w.desc.to_string(),
example: w.example.to_string(),
})
.collect()
});
pub struct App {
pub project_state: ProjectState,
pub ui: UiState,
@@ -310,16 +324,7 @@ impl App {
script.lines().map(String::from).collect()
};
self.editor_ctx.editor.set_content(lines);
let candidates = model::WORDS
.iter()
.map(|w| cagire_ratatui::CompletionCandidate {
name: w.name.to_string(),
signature: w.stack.to_string(),
description: w.desc.to_string(),
example: w.example.to_string(),
})
.collect();
self.editor_ctx.editor.set_candidates(candidates);
self.editor_ctx.editor.set_candidates(COMPLETION_CANDIDATES.clone());
self.editor_ctx
.editor
.set_completion_enabled(self.ui.show_completion);
@@ -350,16 +355,7 @@ impl App {
prelude.lines().map(String::from).collect()
};
self.editor_ctx.editor.set_content(lines);
let candidates = model::WORDS
.iter()
.map(|w| cagire_ratatui::CompletionCandidate {
name: w.name.to_string(),
signature: w.stack.to_string(),
description: w.desc.to_string(),
example: w.example.to_string(),
})
.collect();
self.editor_ctx.editor.set_candidates(candidates);
self.editor_ctx.editor.set_candidates(COMPLETION_CANDIDATES.clone());
self.editor_ctx
.editor
.set_completion_enabled(self.ui.show_completion);

View File

@@ -7,6 +7,7 @@ pub struct ProjectState {
pub project: Project,
pub file_path: Option<PathBuf>,
dirty_patterns: [[bool; MAX_PATTERNS]; MAX_BANKS],
dirty_count: usize,
}
impl Default for ProjectState {
@@ -15,6 +16,7 @@ impl Default for ProjectState {
project: Project::default(),
file_path: None,
dirty_patterns: [[false; MAX_PATTERNS]; MAX_BANKS],
dirty_count: 0,
};
state.mark_all_dirty();
state
@@ -23,15 +25,22 @@ impl Default for ProjectState {
impl ProjectState {
pub fn mark_dirty(&mut self, bank: usize, pattern: usize) {
self.dirty_patterns[bank][pattern] = true;
if !self.dirty_patterns[bank][pattern] {
self.dirty_patterns[bank][pattern] = true;
self.dirty_count += 1;
}
}
pub fn mark_all_dirty(&mut self) {
self.dirty_patterns = [[true; MAX_PATTERNS]; MAX_BANKS];
self.dirty_count = MAX_BANKS * MAX_PATTERNS;
}
pub fn take_dirty(&mut self) -> Vec<(usize, usize)> {
let mut result = Vec::new();
if self.dirty_count == 0 {
return Vec::new();
}
let mut result = Vec::with_capacity(self.dirty_count);
for (bank, patterns) in self.dirty_patterns.iter_mut().enumerate() {
for (pattern, dirty) in patterns.iter_mut().enumerate() {
if *dirty {
@@ -40,6 +49,7 @@ impl ProjectState {
}
}
}
self.dirty_count = 0;
result
}
}

View File

@@ -3,7 +3,7 @@ use std::time::{Duration, Instant};
use ratatui::layout::{Alignment, Constraint, Layout, Rect};
use ratatui::style::{Modifier, Style};
use ratatui::text::{Line, Span};
use ratatui::widgets::{Block, Borders, Cell, Padding, Paragraph, Row, Table};
use ratatui::widgets::{Block, Borders, Cell, Clear, Padding, Paragraph, Row, Table};
use ratatui::Frame;
use crate::app::App;
@@ -50,12 +50,8 @@ pub fn render(frame: &mut Frame, app: &App, link: &LinkState, snapshot: &Sequenc
let theme = theme::get();
let bg_color = theme.ui.bg;
let blank = " ".repeat(term.width as usize);
let lines: Vec<Line> = (0..term.height).map(|_| Line::raw(&blank)).collect();
frame.render_widget(
Paragraph::new(lines).style(Style::default().bg(bg_color)),
term,
);
frame.render_widget(Clear, term);
frame.render_widget(Block::new().style(Style::default().bg(bg_color)), term);
if app.ui.show_title {
title_view::render(frame, term, &app.ui);