use std::collections::HashMap;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum DetailLevel {
Minimal,
Basic,
Standard,
Detailed,
Verbose,
}
impl std::fmt::Display for DetailLevel {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
DetailLevel::Minimal => write!(f, "Minimal"),
DetailLevel::Basic => write!(f, "Basic"),
DetailLevel::Standard => write!(f, "Standard"),
DetailLevel::Detailed => write!(f, "Detailed"),
DetailLevel::Verbose => write!(f, "Verbose"),
}
}
}
impl DetailLevel {
pub fn level(&self) -> u8 {
match self {
DetailLevel::Minimal => 1,
DetailLevel::Basic => 2,
DetailLevel::Standard => 3,
DetailLevel::Detailed => 4,
DetailLevel::Verbose => 5,
}
}
pub fn from_level(level: u8) -> Self {
match level {
0 | 1 => DetailLevel::Minimal,
2 => DetailLevel::Basic,
3 => DetailLevel::Standard,
4 => DetailLevel::Detailed,
_ => DetailLevel::Verbose,
}
}
pub fn more_detail(&self) -> Self {
DetailLevel::from_level(self.level() + 1)
}
pub fn less_detail(&self) -> Self {
DetailLevel::from_level(self.level().saturating_sub(1))
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum FocusArea {
CurrentFile,
CurrentFunction,
CurrentTask,
ErrorsOnly,
TestsOnly,
GitChanges,
Custom,
}
impl std::fmt::Display for FocusArea {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
FocusArea::CurrentFile => write!(f, "Current File"),
FocusArea::CurrentFunction => write!(f, "Current Function"),
FocusArea::CurrentTask => write!(f, "Current Task"),
FocusArea::ErrorsOnly => write!(f, "Errors Only"),
FocusArea::TestsOnly => write!(f, "Tests Only"),
FocusArea::GitChanges => write!(f, "Git Changes"),
FocusArea::Custom => write!(f, "Custom"),
}
}
}
#[derive(Debug, Clone)]
pub struct ProgressiveContent {
levels: HashMap<DetailLevel, String>,
tags: Vec<String>,
priority: u8,
}
impl ProgressiveContent {
pub fn new(minimal: impl Into<String>) -> Self {
let mut levels = HashMap::new();
levels.insert(DetailLevel::Minimal, minimal.into());
Self {
levels,
tags: Vec::new(),
priority: 5,
}
}
pub fn with_level(mut self, level: DetailLevel, content: impl Into<String>) -> Self {
self.levels.insert(level, content.into());
self
}
pub fn with_tag(mut self, tag: impl Into<String>) -> Self {
self.tags.push(tag.into());
self
}
pub fn with_priority(mut self, priority: u8) -> Self {
self.priority = priority.min(10);
self
}
pub fn get(&self, level: DetailLevel) -> &str {
if let Some(content) = self.levels.get(&level) {
return content;
}
for l in (1..=level.level()).rev() {
if let Some(content) = self.levels.get(&DetailLevel::from_level(l)) {
return content;
}
}
self.levels
.get(&DetailLevel::Minimal)
.map(|s| s.as_str())
.unwrap_or("")
}
pub fn has_tag(&self, tag: &str) -> bool {
self.tags.iter().any(|t| t == tag)
}
}
#[derive(Debug, Clone)]
pub struct ContextSummary {
pub headline: String,
pub key_points: Vec<String>,
pub details: HashMap<String, String>,
pub related: Vec<String>,
pub actions: Vec<SuggestedAction>,
}
impl ContextSummary {
pub fn new(headline: impl Into<String>) -> Self {
Self {
headline: headline.into(),
key_points: Vec::new(),
details: HashMap::new(),
related: Vec::new(),
actions: Vec::new(),
}
}
pub fn with_point(mut self, point: impl Into<String>) -> Self {
self.key_points.push(point.into());
self
}
pub fn with_detail(mut self, title: impl Into<String>, content: impl Into<String>) -> Self {
self.details.insert(title.into(), content.into());
self
}
pub fn with_related(mut self, item: impl Into<String>) -> Self {
self.related.push(item.into());
self
}
pub fn with_action(mut self, action: SuggestedAction) -> Self {
self.actions.push(action);
self
}
pub fn render(&self, level: DetailLevel) -> String {
let mut output = String::new();
output.push_str(&self.headline);
output.push('\n');
if level >= DetailLevel::Basic && !self.key_points.is_empty() {
output.push('\n');
for point in &self.key_points {
output.push_str(&format!("- {}\n", point));
}
}
if level >= DetailLevel::Detailed && !self.details.is_empty() {
output.push('\n');
for (title, content) in &self.details {
output.push_str(&format!("## {}\n{}\n\n", title, content));
}
}
if level >= DetailLevel::Verbose && !self.related.is_empty() {
output.push_str("\nRelated: ");
output.push_str(&self.related.join(", "));
output.push('\n');
}
if level >= DetailLevel::Basic && !self.actions.is_empty() {
output.push_str("\nSuggested actions:\n");
for action in &self.actions {
output.push_str(&format!("- {}\n", action.label));
}
}
output
}
}
#[derive(Debug, Clone)]
pub struct SuggestedAction {
pub label: String,
pub description: String,
pub command: Option<String>,
pub priority: Priority,
}
impl SuggestedAction {
pub fn new(label: impl Into<String>) -> Self {
Self {
label: label.into(),
description: String::new(),
command: None,
priority: Priority::Normal,
}
}
pub fn with_description(mut self, desc: impl Into<String>) -> Self {
self.description = desc.into();
self
}
pub fn with_command(mut self, cmd: impl Into<String>) -> Self {
self.command = Some(cmd.into());
self
}
pub fn with_priority(mut self, priority: Priority) -> Self {
self.priority = priority;
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum Priority {
Low,
Normal,
High,
Urgent,
}
impl std::fmt::Display for Priority {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Priority::Low => write!(f, "Low"),
Priority::Normal => write!(f, "Normal"),
Priority::High => write!(f, "High"),
Priority::Urgent => write!(f, "Urgent"),
}
}
}
#[derive(Debug, Clone)]
pub struct SimplifiedView {
pub name: String,
pub detail_level: DetailLevel,
pub hide_patterns: Vec<String>,
pub show_only: Vec<String>,
pub max_items: Option<usize>,
pub group_similar: bool,
pub collapse_repeated: bool,
}
impl SimplifiedView {
pub fn new(name: impl Into<String>) -> Self {
Self {
name: name.into(),
detail_level: DetailLevel::Standard,
hide_patterns: Vec::new(),
show_only: Vec::new(),
max_items: None,
group_similar: false,
collapse_repeated: false,
}
}
pub fn with_detail_level(mut self, level: DetailLevel) -> Self {
self.detail_level = level;
self
}
pub fn hide(mut self, pattern: impl Into<String>) -> Self {
self.hide_patterns.push(pattern.into());
self
}
pub fn show_only(mut self, pattern: impl Into<String>) -> Self {
self.show_only.push(pattern.into());
self
}
pub fn with_max_items(mut self, max: usize) -> Self {
self.max_items = Some(max);
self
}
pub fn group_similar(mut self) -> Self {
self.group_similar = true;
self
}
pub fn collapse_repeated(mut self) -> Self {
self.collapse_repeated = true;
self
}
pub fn minimal() -> Self {
Self::new("Minimal")
.with_detail_level(DetailLevel::Minimal)
.with_max_items(5)
.group_similar()
.collapse_repeated()
}
pub fn errors_only() -> Self {
Self::new("Errors Only")
.with_detail_level(DetailLevel::Basic)
.show_only("error")
.show_only("Error")
.show_only("ERROR")
}
pub fn summary() -> Self {
Self::new("Summary")
.with_detail_level(DetailLevel::Basic)
.with_max_items(10)
.group_similar()
}
}
#[derive(Debug, Clone)]
pub struct FocusMode {
pub active: bool,
pub focus_area: FocusArea,
pub filters: Vec<FocusFilter>,
pub hide_distractions: bool,
pub mute_notifications: bool,
pub time_limit: Option<u32>,
}
impl Default for FocusMode {
fn default() -> Self {
Self::new()
}
}
impl FocusMode {
pub fn new() -> Self {
Self {
active: false,
focus_area: FocusArea::CurrentTask,
filters: Vec::new(),
hide_distractions: true,
mute_notifications: false,
time_limit: None,
}
}
pub fn activate(mut self) -> Self {
self.active = true;
self
}
pub fn with_area(mut self, area: FocusArea) -> Self {
self.focus_area = area;
self
}
pub fn with_filter(mut self, filter: FocusFilter) -> Self {
self.filters.push(filter);
self
}
pub fn hide_distractions(mut self) -> Self {
self.hide_distractions = true;
self
}
pub fn mute_notifications(mut self) -> Self {
self.mute_notifications = true;
self
}
pub fn with_time_limit(mut self, minutes: u32) -> Self {
self.time_limit = Some(minutes);
self
}
pub fn should_show(&self, item: &FocusItem) -> bool {
if !self.active {
return true;
}
let matches_area = match self.focus_area {
FocusArea::ErrorsOnly => item.is_error,
FocusArea::TestsOnly => item.is_test_related,
FocusArea::CurrentFile => item
.file
.as_ref()
.is_some_and(|f| f == &item.current_file.clone().unwrap_or_default()),
FocusArea::GitChanges => item.is_git_change,
_ => true,
};
if !matches_area {
return false;
}
for filter in &self.filters {
if !filter.matches(item) {
return false;
}
}
true
}
}
#[derive(Debug, Clone)]
pub struct FocusFilter {
pub filter_type: FilterType,
pub pattern: String,
pub include: bool,
}
impl FocusFilter {
pub fn include(filter_type: FilterType, pattern: impl Into<String>) -> Self {
Self {
filter_type,
pattern: pattern.into(),
include: true,
}
}
pub fn exclude(filter_type: FilterType, pattern: impl Into<String>) -> Self {
Self {
filter_type,
pattern: pattern.into(),
include: false,
}
}
pub fn matches(&self, item: &FocusItem) -> bool {
let matches = match self.filter_type {
FilterType::Tag => item.tags.iter().any(|t| t.contains(&self.pattern)),
FilterType::File => item
.file
.as_ref()
.is_some_and(|f| f.contains(&self.pattern)),
FilterType::Content => item.content.contains(&self.pattern),
FilterType::Priority => item.priority.to_string() == self.pattern,
};
if self.include {
matches
} else {
!matches
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FilterType {
Tag,
File,
Content,
Priority,
}
#[derive(Debug, Clone)]
pub struct FocusItem {
pub content: String,
pub tags: Vec<String>,
pub file: Option<String>,
pub current_file: Option<String>,
pub priority: Priority,
pub is_error: bool,
pub is_test_related: bool,
pub is_git_change: bool,
}
impl FocusItem {
pub fn new(content: impl Into<String>) -> Self {
Self {
content: content.into(),
tags: Vec::new(),
file: None,
current_file: None,
priority: Priority::Normal,
is_error: false,
is_test_related: false,
is_git_change: false,
}
}
pub fn with_file(mut self, file: impl Into<String>) -> Self {
self.file = Some(file.into());
self
}
pub fn with_current_file(mut self, file: impl Into<String>) -> Self {
self.current_file = Some(file.into());
self
}
pub fn with_tag(mut self, tag: impl Into<String>) -> Self {
self.tags.push(tag.into());
self
}
pub fn as_error(mut self) -> Self {
self.is_error = true;
self
}
pub fn as_test(mut self) -> Self {
self.is_test_related = true;
self
}
pub fn as_git_change(mut self) -> Self {
self.is_git_change = true;
self
}
}
#[derive(Debug)]
pub struct CognitiveLoadReducer {
detail_level: DetailLevel,
active_view: SimplifiedView,
focus_mode: FocusMode,
_content_cache: Vec<String>,
repetition_threshold: usize,
}
impl Default for CognitiveLoadReducer {
fn default() -> Self {
Self::new()
}
}
impl CognitiveLoadReducer {
pub fn new() -> Self {
Self {
detail_level: DetailLevel::Standard,
active_view: SimplifiedView::new("Default"),
focus_mode: FocusMode::new(),
_content_cache: Vec::new(),
repetition_threshold: 3,
}
}
pub fn set_detail_level(&mut self, level: DetailLevel) {
self.detail_level = level;
self.active_view.detail_level = level;
}
pub fn detail_level(&self) -> DetailLevel {
self.detail_level
}
pub fn set_view(&mut self, view: SimplifiedView) {
self.active_view = view;
}
pub fn view(&self) -> &SimplifiedView {
&self.active_view
}
pub fn enable_focus(&mut self, area: FocusArea) {
self.focus_mode = FocusMode::new().activate().with_area(area);
}
pub fn disable_focus(&mut self) {
self.focus_mode.active = false;
}
pub fn is_focused(&self) -> bool {
self.focus_mode.active
}
pub fn focus_mode(&self) -> &FocusMode {
&self.focus_mode
}
pub fn set_focus_mode(&mut self, mode: FocusMode) {
self.focus_mode = mode;
}
pub fn should_show(&self, item: &FocusItem) -> bool {
self.focus_mode.should_show(item)
}
pub fn simplify_output(&mut self, lines: &[String]) -> Vec<String> {
let mut result = Vec::new();
let mut seen_patterns: HashMap<String, usize> = HashMap::new();
for line in lines {
if self
.active_view
.hide_patterns
.iter()
.any(|p| line.contains(p))
{
continue;
}
if !self.active_view.show_only.is_empty()
&& !self.active_view.show_only.iter().any(|p| line.contains(p))
{
continue;
}
if self.active_view.collapse_repeated {
let pattern = self.extract_pattern(line);
let count = seen_patterns.entry(pattern.clone()).or_insert(0);
*count += 1;
if *count > self.repetition_threshold {
continue; }
}
result.push(line.clone());
if let Some(max) = self.active_view.max_items {
if result.len() >= max {
result.push(format!("... and {} more lines", lines.len() - max));
break;
}
}
}
result
}
fn extract_pattern(&self, line: &str) -> String {
let mut pattern = String::new();
let mut in_number = false;
for c in line.chars() {
if c.is_ascii_digit() {
if !in_number {
pattern.push('#');
in_number = true;
}
} else {
in_number = false;
pattern.push(c);
}
}
pattern
}
pub fn summarize(&self, items: &[String], category: &str) -> ContextSummary {
let count = items.len();
let headline = if count == 0 {
format!("No {} to show", category)
} else if count == 1 {
format!("1 {}", category)
} else {
format!("{} {}", count, category)
};
let mut summary = ContextSummary::new(headline);
let max_points = match self.detail_level {
DetailLevel::Minimal => 1,
DetailLevel::Basic => 3,
DetailLevel::Standard => 5,
DetailLevel::Detailed => 10,
DetailLevel::Verbose => items.len(),
};
for (i, item) in items.iter().take(max_points).enumerate() {
let truncated = if item.len() > 80 {
let safe_truncate: String = item.chars().take(77).collect();
format!("{}...", safe_truncate)
} else {
item.clone()
};
summary.key_points.push(truncated);
if i == max_points - 1 && items.len() > max_points {
summary
.key_points
.push(format!("... and {} more", items.len() - max_points));
break;
}
}
summary
}
pub fn preset_minimal(&mut self) {
self.detail_level = DetailLevel::Minimal;
self.active_view = SimplifiedView::minimal();
}
pub fn preset_errors_only(&mut self) {
self.detail_level = DetailLevel::Basic;
self.active_view = SimplifiedView::errors_only();
self.focus_mode = FocusMode::new().activate().with_area(FocusArea::ErrorsOnly);
}
pub fn preset_deep_work(&mut self) {
self.detail_level = DetailLevel::Standard;
self.active_view = SimplifiedView::new("Deep Work")
.with_max_items(10)
.collapse_repeated();
self.focus_mode = FocusMode::new()
.activate()
.with_area(FocusArea::CurrentTask)
.hide_distractions()
.mute_notifications();
}
pub fn more_detail(&mut self) {
self.detail_level = self.detail_level.more_detail();
self.active_view.detail_level = self.detail_level;
}
pub fn less_detail(&mut self) {
self.detail_level = self.detail_level.less_detail();
self.active_view.detail_level = self.detail_level;
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Distraction {
StatusUpdates,
ProgressIndicators,
VerboseLogs,
Suggestions,
Tips,
Marketing,
News,
}
impl std::fmt::Display for Distraction {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Distraction::StatusUpdates => write!(f, "Status Updates"),
Distraction::ProgressIndicators => write!(f, "Progress Indicators"),
Distraction::VerboseLogs => write!(f, "Verbose Logs"),
Distraction::Suggestions => write!(f, "Suggestions"),
Distraction::Tips => write!(f, "Tips"),
Distraction::Marketing => write!(f, "Marketing"),
Distraction::News => write!(f, "News"),
}
}
}
#[derive(Debug)]
pub struct DistractionFilter {
hidden: std::collections::HashSet<Distraction>,
}
impl Default for DistractionFilter {
fn default() -> Self {
Self::new()
}
}
impl DistractionFilter {
pub fn new() -> Self {
Self {
hidden: std::collections::HashSet::new(),
}
}
pub fn hide(&mut self, distraction: Distraction) {
self.hidden.insert(distraction);
}
pub fn show(&mut self, distraction: Distraction) {
self.hidden.remove(&distraction);
}
pub fn is_hidden(&self, distraction: Distraction) -> bool {
self.hidden.contains(&distraction)
}
pub fn hide_all(&mut self) {
use Distraction::*;
for d in [
StatusUpdates,
ProgressIndicators,
VerboseLogs,
Suggestions,
Tips,
Marketing,
News,
] {
self.hidden.insert(d);
}
}
pub fn show_all(&mut self) {
self.hidden.clear();
}
pub fn focus_mode() -> Self {
let mut filter = Self::new();
filter.hide(Distraction::Marketing);
filter.hide(Distraction::News);
filter.hide(Distraction::Tips);
filter.hide(Distraction::VerboseLogs);
filter
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_detail_level_ordering() {
assert!(DetailLevel::Minimal < DetailLevel::Basic);
assert!(DetailLevel::Basic < DetailLevel::Standard);
assert!(DetailLevel::Standard < DetailLevel::Detailed);
assert!(DetailLevel::Detailed < DetailLevel::Verbose);
}
#[test]
fn test_detail_level_conversion() {
assert_eq!(DetailLevel::from_level(1), DetailLevel::Minimal);
assert_eq!(DetailLevel::from_level(3), DetailLevel::Standard);
assert_eq!(DetailLevel::from_level(5), DetailLevel::Verbose);
}
#[test]
fn test_detail_level_more_less() {
let level = DetailLevel::Standard;
assert_eq!(level.more_detail(), DetailLevel::Detailed);
assert_eq!(level.less_detail(), DetailLevel::Basic);
}
#[test]
fn test_detail_level_bounds() {
let minimal = DetailLevel::Minimal;
assert_eq!(minimal.less_detail(), DetailLevel::Minimal);
let verbose = DetailLevel::Verbose;
assert_eq!(verbose.more_detail(), DetailLevel::Verbose);
}
#[test]
fn test_focus_area_display() {
assert_eq!(format!("{}", FocusArea::CurrentFile), "Current File");
assert_eq!(format!("{}", FocusArea::ErrorsOnly), "Errors Only");
}
#[test]
fn test_progressive_content_creation() {
let content = ProgressiveContent::new("Brief version")
.with_level(DetailLevel::Detailed, "Detailed version")
.with_tag("important");
assert_eq!(content.get(DetailLevel::Minimal), "Brief version");
assert_eq!(content.get(DetailLevel::Detailed), "Detailed version");
assert!(content.has_tag("important"));
}
#[test]
fn test_progressive_content_fallback() {
let content = ProgressiveContent::new("Only minimal");
assert_eq!(content.get(DetailLevel::Verbose), "Only minimal");
}
#[test]
fn test_context_summary_creation() {
let summary = ContextSummary::new("Test headline")
.with_point("Point 1")
.with_point("Point 2")
.with_detail("Section", "Content");
assert_eq!(summary.headline, "Test headline");
assert_eq!(summary.key_points.len(), 2);
assert!(summary.details.contains_key("Section"));
}
#[test]
fn test_context_summary_render() {
let summary = ContextSummary::new("Headline").with_point("Point 1");
let minimal = summary.render(DetailLevel::Minimal);
let basic = summary.render(DetailLevel::Basic);
assert!(minimal.contains("Headline"));
assert!(!minimal.contains("Point 1"));
assert!(basic.contains("Point 1"));
}
#[test]
fn test_suggested_action() {
let action = SuggestedAction::new("Run tests")
.with_command("cargo test")
.with_priority(Priority::High);
assert_eq!(action.label, "Run tests");
assert_eq!(action.command, Some("cargo test".to_string()));
assert_eq!(action.priority, Priority::High);
}
#[test]
fn test_simplified_view_creation() {
let view = SimplifiedView::new("Test")
.with_detail_level(DetailLevel::Basic)
.hide("debug")
.with_max_items(10);
assert_eq!(view.name, "Test");
assert_eq!(view.detail_level, DetailLevel::Basic);
assert!(view.hide_patterns.contains(&"debug".to_string()));
assert_eq!(view.max_items, Some(10));
}
#[test]
fn test_simplified_view_presets() {
let minimal = SimplifiedView::minimal();
assert_eq!(minimal.detail_level, DetailLevel::Minimal);
assert!(minimal.group_similar);
let errors = SimplifiedView::errors_only();
assert!(!errors.show_only.is_empty());
}
#[test]
fn test_focus_mode_creation() {
let mode = FocusMode::new()
.activate()
.with_area(FocusArea::ErrorsOnly)
.mute_notifications();
assert!(mode.active);
assert_eq!(mode.focus_area, FocusArea::ErrorsOnly);
assert!(mode.mute_notifications);
}
#[test]
fn test_focus_mode_should_show_errors() {
let mode = FocusMode::new().activate().with_area(FocusArea::ErrorsOnly);
let error_item = FocusItem::new("Error message").as_error();
let normal_item = FocusItem::new("Normal message");
assert!(mode.should_show(&error_item));
assert!(!mode.should_show(&normal_item));
}
#[test]
fn test_focus_mode_inactive() {
let mode = FocusMode::new();
let item = FocusItem::new("Anything");
assert!(mode.should_show(&item));
}
#[test]
fn test_focus_filter_include() {
let filter = FocusFilter::include(FilterType::Tag, "important");
let matches = FocusItem::new("Test").with_tag("important");
let no_match = FocusItem::new("Test").with_tag("other");
assert!(filter.matches(&matches));
assert!(!filter.matches(&no_match));
}
#[test]
fn test_focus_filter_exclude() {
let filter = FocusFilter::exclude(FilterType::Content, "debug");
let excluded = FocusItem::new("debug message");
let included = FocusItem::new("normal message");
assert!(!filter.matches(&excluded));
assert!(filter.matches(&included));
}
#[test]
fn test_focus_item_creation() {
let item = FocusItem::new("Content")
.with_file("src/lib.rs")
.with_tag("test")
.as_error();
assert!(item.is_error);
assert!(item.file.is_some());
assert!(item.tags.contains(&"test".to_string()));
}
#[test]
fn test_cognitive_load_reducer_creation() {
let reducer = CognitiveLoadReducer::new();
assert_eq!(reducer.detail_level(), DetailLevel::Standard);
assert!(!reducer.is_focused());
}
#[test]
fn test_cognitive_load_reducer_detail_level() {
let mut reducer = CognitiveLoadReducer::new();
reducer.set_detail_level(DetailLevel::Minimal);
assert_eq!(reducer.detail_level(), DetailLevel::Minimal);
reducer.more_detail();
assert_eq!(reducer.detail_level(), DetailLevel::Basic);
reducer.less_detail();
assert_eq!(reducer.detail_level(), DetailLevel::Minimal);
}
#[test]
fn test_cognitive_load_reducer_focus() {
let mut reducer = CognitiveLoadReducer::new();
reducer.enable_focus(FocusArea::ErrorsOnly);
assert!(reducer.is_focused());
reducer.disable_focus();
assert!(!reducer.is_focused());
}
#[test]
fn test_cognitive_load_reducer_simplify_output() {
let mut reducer = CognitiveLoadReducer::new();
reducer.set_view(SimplifiedView::new("Test").with_max_items(2));
let lines: Vec<String> = vec![
"Line 1".to_string(),
"Line 2".to_string(),
"Line 3".to_string(),
"Line 4".to_string(),
];
let result = reducer.simplify_output(&lines);
assert!(result.len() <= 3); }
#[test]
fn test_cognitive_load_reducer_simplify_hide() {
let mut reducer = CognitiveLoadReducer::new();
reducer.set_view(SimplifiedView::new("Test").hide("DEBUG"));
let lines: Vec<String> = vec![
"DEBUG: something".to_string(),
"INFO: important".to_string(),
];
let result = reducer.simplify_output(&lines);
assert_eq!(result.len(), 1);
assert!(result[0].contains("INFO"));
}
#[test]
fn test_cognitive_load_reducer_summarize() {
let reducer = CognitiveLoadReducer::new();
let items = vec![
"Item 1".to_string(),
"Item 2".to_string(),
"Item 3".to_string(),
];
let summary = reducer.summarize(&items, "items");
assert!(summary.headline.contains("3"));
assert!(!summary.key_points.is_empty());
}
#[test]
fn test_cognitive_load_reducer_presets() {
let mut reducer = CognitiveLoadReducer::new();
reducer.preset_minimal();
assert_eq!(reducer.detail_level(), DetailLevel::Minimal);
reducer.preset_errors_only();
assert!(reducer.is_focused());
reducer.preset_deep_work();
assert!(reducer.focus_mode().hide_distractions);
}
#[test]
fn test_distraction_filter_creation() {
let mut filter = DistractionFilter::new();
filter.hide(Distraction::Marketing);
assert!(filter.is_hidden(Distraction::Marketing));
assert!(!filter.is_hidden(Distraction::Tips));
filter.show(Distraction::Marketing);
assert!(!filter.is_hidden(Distraction::Marketing));
}
#[test]
fn test_distraction_filter_hide_all() {
let mut filter = DistractionFilter::new();
filter.hide_all();
assert!(filter.is_hidden(Distraction::Marketing));
assert!(filter.is_hidden(Distraction::News));
assert!(filter.is_hidden(Distraction::Tips));
}
#[test]
fn test_distraction_filter_show_all() {
let mut filter = DistractionFilter::new();
filter.hide_all();
filter.show_all();
assert!(!filter.is_hidden(Distraction::Marketing));
}
#[test]
fn test_distraction_filter_focus_mode() {
let filter = DistractionFilter::focus_mode();
assert!(filter.is_hidden(Distraction::Marketing));
assert!(filter.is_hidden(Distraction::News));
assert!(!filter.is_hidden(Distraction::StatusUpdates));
}
#[test]
fn test_distraction_display() {
assert_eq!(format!("{}", Distraction::VerboseLogs), "Verbose Logs");
assert_eq!(format!("{}", Distraction::Marketing), "Marketing");
}
#[test]
fn test_priority_ordering() {
assert!(Priority::Low < Priority::Normal);
assert!(Priority::Normal < Priority::High);
assert!(Priority::High < Priority::Urgent);
}
#[test]
fn test_context_summary_with_action() {
let action = SuggestedAction::new("Fix error");
let summary = ContextSummary::new("Test").with_action(action);
assert_eq!(summary.actions.len(), 1);
}
#[test]
fn test_progressive_content_priority() {
let content = ProgressiveContent::new("Test").with_priority(8);
assert_eq!(content.priority, 8);
}
#[test]
fn test_simplified_view_group_collapse() {
let view = SimplifiedView::new("Test")
.group_similar()
.collapse_repeated();
assert!(view.group_similar);
assert!(view.collapse_repeated);
}
#[test]
fn test_focus_mode_with_time_limit() {
let mode = FocusMode::new().with_time_limit(25);
assert_eq!(mode.time_limit, Some(25));
}
#[test]
fn test_focus_item_test_and_git() {
let item = FocusItem::new("test").as_test().as_git_change();
assert!(item.is_test_related);
assert!(item.is_git_change);
}
}