Download kernel/src/apps/file_manager.rs from Jaswanth-2008/AeroOS: direct link, hf CLI and curl.
- Browser
- Download file 4.84 kB
-
https://huggingface.co/Jaswanth-2008/AeroOS/resolve/main/kernel/src/apps/file_manager.rs
- Command line
-
hf download hf://Jaswanth-2008/AeroOS/kernel/src/apps/file_manager.rs
-
curl -L -o file_manager.rs https://huggingface.co/Jaswanth-2008/AeroOS/resolve/main/kernel/src/apps/file_manager.rs
4.84 kB
| extern crate alloc; | |
| use alloc::format; | |
| use alloc::string::String; | |
| use crate::fs::vfs::VFS; | |
| use crate::graphics::color::Color; | |
| use crate::graphics::icons::IconType; | |
| use crate::graphics::surface::Surface; | |
| pub struct FileManagerApp { | |
| pub current_path: String, | |
| pub preview_text: String, | |
| } | |
| impl FileManagerApp { | |
| pub fn new() -> Self { | |
| Self { | |
| current_path: String::from("/user"), | |
| preview_text: String::from("Select a file to preview its contents."), | |
| } | |
| } | |
| pub fn handle_click(&mut self, rel_x: i32, rel_y: i32) { | |
| // Sidebar navigation: rel_x < 120 | |
| if rel_x < 120 { | |
| if rel_y >= 50 && rel_y <= 70 { | |
| self.current_path = String::from("/"); | |
| } else if rel_y > 70 && rel_y <= 90 { | |
| self.current_path = String::from("/user"); | |
| } else if rel_y > 90 && rel_y <= 110 { | |
| self.current_path = String::from("/system"); | |
| } else if rel_y > 110 && rel_y <= 130 { | |
| self.current_path = String::from("/docs"); | |
| } | |
| } else { | |
| // File list click: load file preview | |
| if let Some(ref fs) = *VFS.lock() { | |
| if let Some(entries) = fs.list_dir(&self.current_path) { | |
| let clicked_row = (rel_y - 50) / 24; | |
| if clicked_row >= 0 && (clicked_row as usize) < entries.len() { | |
| let (name, is_dir, _) = &entries[clicked_row as usize]; | |
| if *is_dir { | |
| if self.current_path == "/" { | |
| self.current_path = format!("/{}", name); | |
| } else { | |
| self.current_path = format!("{}/{}", self.current_path, name); | |
| } | |
| } else { | |
| let file_path = if self.current_path == "/" { | |
| format!("/{}", name) | |
| } else { | |
| format!("{}/{}", self.current_path, name) | |
| }; | |
| if let Some(bytes) = fs.read_file(&file_path) { | |
| if let Ok(s) = core::str::from_utf8(&bytes) { | |
| self.preview_text = s.chars().take(80).collect(); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| pub fn render(&self, surface: &mut Surface, x: i32, y: i32, w: usize, h: usize) { | |
| surface.draw_rect(x, y, w, h, Color::rgb(28, 30, 40)); | |
| // Header bar | |
| surface.draw_rect(x, y, w, 36, Color::rgb(35, 38, 50)); | |
| surface.draw_icon_16(IconType::FileManager, x + 12, y + 10, Color::rgb(254, 188, 46)); | |
| let path_label = format!("Path: {}", self.current_path); | |
| surface.draw_text(&path_label, x + 36, y + 11, Color::WHITE); | |
| // Sidebar (macOS style translucent panel) | |
| let sidebar_w = 120; | |
| surface.draw_rect(x, y + 36, sidebar_w, h.saturating_sub(36), Color::rgb(22, 24, 32)); | |
| surface.draw_text("FAVORITES", x + 10, y + 46, Color::TEXT_MUTED); | |
| surface.draw_text("Root (/)", x + 16, y + 66, Color::TEXT_SECONDARY); | |
| surface.draw_text("User (/user)", x + 16, y + 86, Color::TEXT_SECONDARY); | |
| surface.draw_text("System", x + 16, y + 106, Color::TEXT_SECONDARY); | |
| surface.draw_text("Docs", x + 16, y + 126, Color::TEXT_SECONDARY); | |
| // Files listing | |
| let list_x = x + sidebar_w as i32 + 10; | |
| let mut list_y = y + 46; | |
| if let Some(ref fs) = *VFS.lock() { | |
| if let Some(entries) = fs.list_dir(&self.current_path) { | |
| for (name, is_dir, size) in entries { | |
| let icon_color = if is_dir { Color::rgb(254, 188, 46) } else { Color::ACCENT_CYAN }; | |
| let icon = if is_dir { IconType::FileManager } else { IconType::Editor }; | |
| surface.draw_icon_16(icon, list_x, list_y, icon_color); | |
| let entry_label = if is_dir { | |
| format!("{}/", name) | |
| } else { | |
| format!("{} ({} B)", name, size) | |
| }; | |
| surface.draw_text(&entry_label, list_x + 24, list_y + 1, Color::WHITE); | |
| list_y += 24; | |
| } | |
| } | |
| } | |
| // Preview box at bottom | |
| let prev_y = y + h as i32 - 40; | |
| surface.draw_rect(x + sidebar_w as i32, prev_y, w.saturating_sub(sidebar_w), 40, Color::rgb(20, 22, 30)); | |
| surface.draw_text("Preview:", list_x, prev_y + 6, Color::TEXT_MUTED); | |
| surface.draw_text(&self.preview_text, list_x, prev_y + 22, Color::TEXT_SECONDARY); | |
| } | |
| } | |