Feat: collapsible help

This commit is contained in:
2026-02-16 23:43:25 +01:00
parent 2d8abe4af9
commit f258358c8f
12 changed files with 597 additions and 119 deletions

View File

@@ -122,6 +122,53 @@ pub fn topic_count() -> usize {
DOCS.iter().filter(|e| matches!(e, Topic(_, _))).count()
}
pub fn section_count() -> usize {
DOCS.iter().filter(|e| matches!(e, Section(_))).count()
}
pub fn section_index_for_topic(topic_idx: usize) -> usize {
let mut section: usize = 0;
let mut topic: usize = 0;
for entry in DOCS.iter() {
match entry {
Section(_) => section += 1,
Topic(_, _) => {
if topic == topic_idx {
return section.saturating_sub(1);
}
topic += 1;
}
}
}
section.saturating_sub(1)
}
pub fn first_topic_in_section(section_idx: usize) -> Option<usize> {
let mut section: usize = 0;
let mut topic: usize = 0;
let mut in_target = false;
for entry in DOCS.iter() {
match entry {
Section(_) => {
if in_target {
return None;
}
if section == section_idx {
in_target = true;
}
section += 1;
}
Topic(_, _) => {
if in_target {
return Some(topic);
}
topic += 1;
}
}
}
None
}
pub fn get_topic(index: usize) -> Option<(&'static str, &'static str)> {
DOCS.iter()
.filter_map(|e| match e {