use std::sync::Arc; use std::thread; use super::editor::{TextEditor, TextProcessingResult}; impl TextEditor { pub fn start_text_processing_thread(&mut self) { let _processing_result = Arc::clone(&self.text_processing_result); let handle = thread::Builder::new() .name("TextProcessor".to_string()) .spawn(move || { // Set thread priority to high (platform-specific) #[cfg(target_os = "linux")] { unsafe { let thread_id = libc::pthread_self(); let mut param: libc::sched_param = std::mem::zeroed(); param.sched_priority = 50; let _ = libc::pthread_setschedparam(thread_id, libc::SCHED_OTHER, ¶m); } } }); match handle { Ok(h) => self.processing_thread_handle = Some(h), Err(e) => eprintln!("Failed to start text processing thread: {}", e), } } pub fn process_text_for_rendering( &mut self, content: &str, available_width: f32, ) { let line_count = content.lines().count().max(1); let visual_line_mapping = if self.word_wrap { // For now, simplified mapping - this could be moved to background thread (1..=line_count).map(Some).collect() } else { (1..=line_count).map(Some).collect() }; let result = TextProcessingResult { line_count, visual_line_mapping, max_line_length: available_width, _processed_content: content.to_string(), }; if let Ok(mut processing_result) = self.text_processing_result.lock() { *processing_result = result; } } pub fn get_text_processing_result(&self) -> TextProcessingResult { self.text_processing_result .lock() .map(|result| result.clone()) .unwrap_or_default() } }