AeroOS / kernel /src /apps /terminal.rs
Jaswanth-2008's picture
Upload AeroOS complete Rust source code
dcbeeb2 verified
Raw History Blame Contribute Delete
37.3 kB
extern crate alloc;
use alloc::format;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use pc_keyboard::DecodedKey;
use crate::fs::vfs::VFS;
use crate::graphics::color::Color;
use crate::graphics::surface::Surface;
use crate::net::stack;
use smoltcp::wire::Ipv4Address;
fn parse_ipv4_addr(s: &str) -> Option<Ipv4Address> {
let parts: Vec<&str> = s.split('.').collect();
if parts.len() == 4 {
if let (Ok(a), Ok(b), Ok(c), Ok(d)) = (
parts[0].parse::<u8>(),
parts[1].parse::<u8>(),
parts[2].parse::<u8>(),
parts[3].parse::<u8>(),
) {
return Some(Ipv4Address::new(a, b, c, d));
}
}
None
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum TerminalPromptMode {
Normal,
WifiSelectNetwork,
WifiPasswordPrompt { ssid: String },
}
pub struct TerminalApp {
pub lines: Vec<String>,
pub input_buffer: String,
pub max_lines: usize,
pub scroll_offset: usize,
pub prompt_mode: TerminalPromptMode,
}
impl TerminalApp {
pub fn new() -> Self {
let mut term = Self {
lines: Vec::new(),
input_buffer: String::new(),
max_lines: 500,
scroll_offset: 0,
prompt_mode: TerminalPromptMode::Normal,
};
term.lines.push(String::from("=================================================="));
term.lines.push(String::from(" AeroOS Interactive Shell (AeroShell v1.0) "));
term.lines.push(String::from(" Windows 11 Fluent UI + macOS Hybrid Environment "));
term.lines.push(String::from("=================================================="));
term.lines.push(String::from("[+] Architecture : x86_64 Bare-Metal (UEFI GOP 800x600)"));
term.lines.push(String::from("[+] Network : VirtIO-Net (LAN 10.0.2.15) + WiFi"));
term.lines.push(String::from("[+] Packages : APT (Debian) + Snap Store (Ubuntu)"));
term.lines.push(String::from("[+] Hardware : Laptop Power, Battery (98%), Fan ACPI"));
term.lines.push(String::from("[+] Input : PS/2 Keyboard + IntelliMouse Wheel"));
term.lines.push(String::from(""));
term.lines.push(String::from("Available Commands:"));
term.lines.push(String::from(" systemd-analyze : Show boot time breakdown"));
term.lines.push(String::from(" snapstore : Open Software Center GUI"));
term.lines.push(String::from(" netcenter : Open Network Management GUI"));
term.lines.push(String::from(" apt list : List Debian software packages"));
term.lines.push(String::from(" snap list : List Canonical Snap packages"));
term.lines.push(String::from(" battery, ping, ifconfig, date, neofetch, clear"));
term.lines.push(String::from(""));
term.lines.push(String::from("[*] Tip: Use Mouse Wheel or PageUp/PageDown to scroll!"));
term.lines.push(String::from(""));
term
}
pub fn handle_scroll(&mut self, delta: i32) {
let visible_lines = 14;
let max_scroll = self.lines.len().saturating_sub(visible_lines);
let step = (delta.abs() as usize).max(1) * 2;
if delta > 0 {
// Scroll UP (view older history)
self.scroll_offset = (self.scroll_offset + step).min(max_scroll);
} else if delta < 0 {
// Scroll DOWN (towards recent commands/prompt)
self.scroll_offset = self.scroll_offset.saturating_sub(step);
}
}
pub fn handle_key(&mut self, key: DecodedKey) {
match key {
DecodedKey::RawKey(pc_keyboard::KeyCode::PageUp) => {
self.handle_scroll(5);
return;
}
DecodedKey::RawKey(pc_keyboard::KeyCode::PageDown) => {
self.handle_scroll(-5);
return;
}
DecodedKey::RawKey(pc_keyboard::KeyCode::ArrowUp) if self.input_buffer.is_empty() => {
self.handle_scroll(1);
return;
}
DecodedKey::RawKey(pc_keyboard::KeyCode::ArrowDown) if self.input_buffer.is_empty() => {
self.handle_scroll(-1);
return;
}
DecodedKey::Unicode('\u{1b}') | DecodedKey::RawKey(pc_keyboard::KeyCode::Escape) => {
if self.prompt_mode != TerminalPromptMode::Normal {
self.lines.push(String::from("^C"));
self.prompt_mode = TerminalPromptMode::Normal;
self.input_buffer.clear();
return;
}
}
DecodedKey::Unicode('\n') => {
let input = self.input_buffer.trim().to_string();
self.input_buffer.clear();
self.scroll_offset = 0; // Reset scroll to bottom on new command
self.lines.push(format!("aero@kernel:~$ {}", input));
self.execute_command(&input);
}
DecodedKey::Unicode('\u{08}') => {
self.input_buffer.pop();
}
DecodedKey::Unicode(c) => {
if self.input_buffer.len() < 64 && c >= ' ' && c <= '~' {
self.input_buffer.push(c);
self.scroll_offset = 0; // Jump to prompt when typing
}
}
DecodedKey::RawKey(_) => {}
}
if self.lines.len() > self.max_lines {
let overflow = self.lines.len() - self.max_lines;
self.lines.drain(0..overflow);
}
}
fn execute_command(&mut self, cmd: &str) {
if cmd.is_empty() {
return;
}
let parts: Vec<&str> = cmd.split_whitespace().collect();
match parts[0] {
"help" => {
self.lines.push(String::from("AeroShell Built-in Commands:"));
self.lines.push(String::from(" whoami - Print current logged-in username (aero)"));
self.lines.push(String::from(" wifi [cmd] - Wi-Fi management (connect/scan/list/status)"));
self.lines.push(String::from(" apt [cmd] - Debian package manager (install/update/list)"));
self.lines.push(String::from(" aptitude - Debian aptitude interface alias"));
self.lines.push(String::from(" snap [cmd] - Canonical Snap Store client (install/list)"));
self.lines.push(String::from(" ifconfig - Show LAN & Wi-Fi interface IP addresses"));
self.lines.push(String::from(" ping <host> - Ping network gateway (ICMP echo test)"));
self.lines.push(String::from(" battery - Laptop ACPI battery & power supply status"));
self.lines.push(String::from(" brightness - Display backlight brightness (10..100)"));
self.lines.push(String::from(" powerprofile- Laptop power governor (perf/balanced/save)"));
self.lines.push(String::from(" systemd-analyze - Display component boot time benchmarks"));
self.lines.push(String::from(" ls, cat, touch, echo, date, neofetch, clear, reboot"));
}
"whoami" => {
if parts.len() > 1 && (parts[1] == "-v" || parts[1] == "--version" || parts[1] == "--help") {
self.lines.push(String::from("aero (UID 1000, GID 1000, AeroOS Desktop User)"));
self.lines.push(String::from("Privileges: Standard User with sudo/wheel elevation rights"));
} else {
self.lines.push(String::from("aero"));
}
}
"id" => {
self.lines.push(String::from("uid=1000(aero) gid=1000(aero) groups=1000(aero),27(sudo),4(adm),100(users)"));
}
"users" | "who" => {
self.lines.push(String::from("aero tty1 Nov 19 (active GUI console session)"));
}
"apt" | "aptitude" => {
let sub_args = if parts.len() > 1 { &parts[1..] } else { &[] as &[&str] };
let output = crate::apps::apt::run_apt(sub_args);
for line in output {
self.lines.push(line);
}
}
"snap" => {
if parts.len() > 1 && (parts[1] == "store" || parts[1] == "gui") {
crate::apps::queue_app_launch(crate::apps::AppType::SnapStore);
self.lines.push(String::from("[+] Launching Snap Store Graphical Software Center..."));
} else {
let sub_args = if parts.len() > 1 { &parts[1..] } else { &[] as &[&str] };
let output = crate::apps::snapstore::run_snap_cli(sub_args);
for line in output {
self.lines.push(line);
}
}
}
"wifi" => {
if parts.len() < 2 || parts[1] == "status" {
let st = crate::net::wifi::get_status();
let rssi = -100 + (st.signal_percent as i32 / 2);
self.lines.push(format!("Wi-Fi Adapter : {}", st.adapter_name));
self.lines.push(format!(" PHY Mode : {}", st.phy_mode));
self.lines.push(format!(" Power State : {}", if st.enabled { "Enabled" } else { "Disabled" }));
self.lines.push(format!(" Connected : {}", if st.connected { st.connected_ssid } else { "None" }));
self.lines.push(format!(" IPv4 Address: {}.{}.{}.{}", st.ip_address[0], st.ip_address[1], st.ip_address[2], st.ip_address[3]));
self.lines.push(format!(" Subnet Mask : {}.{}.{}.{}", st.subnet_mask[0], st.subnet_mask[1], st.subnet_mask[2], st.subnet_mask[3]));
self.lines.push(format!(" Gateway : {}.{}.{}.{}", st.gateway_ip[0], st.gateway_ip[1], st.gateway_ip[2], st.gateway_ip[3]));
self.lines.push(format!(" Link Speed : {} Mbps (5 GHz Channel {})", st.link_speed_mbps, st.channel));
self.lines.push(format!(" Signal : {}% ({} dBm, WPA2/WPA3 Personal)", st.signal_percent, rssi));
self.lines.push(String::new());
self.lines.push(String::from("Available Wireless Networks (Host Laptop System):"));
let aps = crate::net::wifi::scan_networks();
for ap in aps.iter() {
let is_active = st.connected && st.connected_ssid == ap.ssid;
let active_mark = if is_active { " [Connected]" } else { "" };
let sec = match ap.security {
crate::net::wifi::WifiSecurity::Open => "Open",
crate::net::wifi::WifiSecurity::Wpa2Personal => "WPA2-PSK",
crate::net::wifi::WifiSecurity::Wpa3Personal => "WPA3-SAE",
crate::net::wifi::WifiSecurity::Wpa2Enterprise => "WPA2-Enterprise",
};
self.lines.push(format!(" * {:<18} Signal: {:>3}% Ch: {:<2} Sec: {:<10}{}",
ap.ssid, ap.signal_percent, ap.channel, sec, active_mark));
}
self.lines.push(String::new());
self.lines.push(String::from("Commands:"));
self.lines.push(String::from(" wifi connect <SSID> [password] - Connect to Wi-Fi network"));
self.lines.push(String::from(" wifi disconnect - Disconnect from Wi-Fi"));
self.lines.push(String::from(" wifi gui - Open Wi-Fi Manager window"));
} else if parts[1] == "scan" || parts[1] == "list" {
self.lines.push(String::from("Available Wireless Networks (Host Laptop System):"));
let aps = crate::net::wifi::scan_networks();
let current_ssid = crate::net::wifi::get_status().connected_ssid;
let is_connected = crate::net::wifi::get_status().connected;
for ap in aps.iter() {
let sec = match ap.security {
crate::net::wifi::WifiSecurity::Open => "Open",
crate::net::wifi::WifiSecurity::Wpa2Personal => "WPA2-PSK",
crate::net::wifi::WifiSecurity::Wpa3Personal => "WPA3-SAE",
crate::net::wifi::WifiSecurity::Wpa2Enterprise => "WPA2-Enterprise",
};
let active_mark = if is_connected && current_ssid == ap.ssid {
" [Connected]"
} else {
""
};
self.lines.push(format!(" * {:<18} Signal: {:>3}% Ch: {:<2} Sec: {:<10}{}",
ap.ssid, ap.signal_percent, ap.channel, sec, active_mark));
}
} else if parts[1] == "connect" {
if parts.len() < 3 {
self.lines.push(String::from("Usage: wifi connect <SSID> [password]"));
self.lines.push(String::from("Example: wifi connect \"vivo V40e\""));
self.lines.push(String::from("Type 'wifi' or 'wifi list' to view available networks."));
} else {
let target = parts[2];
let password = if parts.len() >= 4 { parts[3] } else { "" };
if let Some(ap) = crate::net::wifi::find_ap(target) {
self.lines.push(format!("[*] Connecting to '{}'...", ap.ssid));
self.lines.push(String::from("[+] WPA pre-shared key verified. Handshake completed."));
crate::net::wifi::connect_ap(&ap, password);
let st = crate::net::wifi::get_status();
self.lines.push(format!("[+] DHCP IP lease acquired on wlan0: {}.{}.{}.{}",
st.ip_address[0], st.ip_address[1], st.ip_address[2], st.ip_address[3]));
self.lines.push(format!("[+] Gateway: {}.{}.{}.{} | Link Speed: {} Mbps",
st.gateway_ip[0], st.gateway_ip[1], st.gateway_ip[2], st.gateway_ip[3], st.link_speed_mbps));
self.lines.push(format!("[+] Successfully connected to '{}'!", ap.ssid));
} else {
self.lines.push(format!("wifi: Network '{}' not found in available networks.", target));
self.lines.push(String::from("Type 'wifi list' to see available networks."));
}
}
} else if parts[1] == "disconnect" {
crate::net::wifi::disconnect();
self.lines.push(String::from("[+] Wi-Fi disconnected from network. Interface wlan0 down."));
} else if parts[1] == "gui" || parts[1] == "window" {
crate::apps::queue_app_launch(crate::apps::AppType::WifiManager);
self.lines.push(String::from("[+] Launching dedicated Wi-Fi Settings window..."));
} else {
self.lines.push(String::from("Usage: wifi [status|scan|list|connect <SSID> [pass]|disconnect|gui]"));
}
}
"wifi-gui" | "wlan" => {
crate::apps::queue_app_launch(crate::apps::AppType::WifiManager);
self.lines.push(String::from("[+] Launching dedicated Wi-Fi Settings window..."));
}
"battery" | "power" => {
let hw = crate::drivers::laptop::get_hardware();
let status_str = match hw.battery_status {
crate::drivers::laptop::BatteryStatus::Charging => "Charging (AC Adapter Connected)",
crate::drivers::laptop::BatteryStatus::Discharging => "Discharging (Battery Power)",
crate::drivers::laptop::BatteryStatus::Full => "Full (AC Connected)",
};
self.lines.push(String::from("================ Laptop ACPI Power Subsystem ================"));
self.lines.push(format!("Battery Level: {}%", hw.battery_percent));
self.lines.push(format!("Power State: {}", status_str));
self.lines.push(format!("Battery Health: {}% (Design Capacity: 5100 mAh)", hw.battery_health));
self.lines.push(format!("Est. Runtime: {}h {}m remaining", hw.estimated_minutes / 60, hw.estimated_minutes % 60));
self.lines.push(format!("Power Governor: {:?}", hw.power_profile));
self.lines.push(String::from("============================================================="));
}
"brightness" => {
if parts.len() > 1 {
if let Ok(val) = parts[1].parse::<u8>() {
let set_to = crate::drivers::laptop::set_brightness(val);
self.lines.push(format!("Display backlight brightness set to {}%.", set_to));
} else {
self.lines.push(String::from("Usage: brightness [10..100]"));
}
} else {
let hw = crate::drivers::laptop::get_hardware();
self.lines.push(format!("Current display backlight brightness: {}%", hw.brightness_percent));
}
}
"powerprofile" => {
if parts.len() > 1 {
match parts[1] {
"perf" | "performance" => {
crate::drivers::laptop::set_power_profile(crate::drivers::laptop::PowerProfile::Performance);
self.lines.push(String::from("Power profile set to: Performance (Max Clocks)."));
}
"balanced" => {
crate::drivers::laptop::set_power_profile(crate::drivers::laptop::PowerProfile::Balanced);
self.lines.push(String::from("Power profile set to: Balanced (Dynamic Frequency Scaling)."));
}
"save" | "powersave" => {
crate::drivers::laptop::set_power_profile(crate::drivers::laptop::PowerProfile::BatterySaver);
self.lines.push(String::from("Power profile set to: Battery Saver (Low Power Mode)."));
}
_ => {
self.lines.push(String::from("Usage: powerprofile [performance|balanced|powersave]"));
}
}
} else {
let hw = crate::drivers::laptop::get_hardware();
self.lines.push(format!("Current power profile: {:?}", hw.power_profile));
}
}
"sensors" => {
let hw = crate::drivers::laptop::get_hardware();
self.lines.push(String::from("Laptop Thermal Sensors:"));
self.lines.push(format!(" CPU Core 0: {}°C", hw.cpu_temp_celsius));
self.lines.push(format!(" CPU Core 1: {}°C", hw.cpu_temp_celsius.saturating_sub(2)));
self.lines.push(format!(" Cooling Fan: {} RPM", hw.fan_speed_rpm));
self.lines.push(format!(" Thermal State: Normal (Passive Cooling Capable)"));
}
"systemd-analyze" | "bootchart" => {
let total = crate::arch::boot_timer::get_total_boot_time_ms();
self.lines.push(format!("Startup finished in {}ms (kernel + userspace compositor)", total));
self.lines.push(String::from("Component Boot Times:"));
for opt_stage in crate::arch::boot_timer::get_stages().iter() {
if let Some(st) = opt_stage {
self.lines.push(format!(" {:<6}ms {}", st.duration_ms, st.name));
}
}
}
"snapstore" | "snap-store" | "store" | "software" | "appstore" => {
crate::apps::queue_app_launch(crate::apps::AppType::SnapStore);
self.lines.push(String::from("[+] Launching Snap Store Graphical Software Center..."));
}
"netcenter" | "network-gui" => {
crate::apps::queue_app_launch(crate::apps::AppType::NetManager);
self.lines.push(String::from("[+] Launching Network Center GUI..."));
}
"explorer" | "files" => {
crate::apps::queue_app_launch(crate::apps::AppType::FileManager);
self.lines.push(String::from("[+] Launching File Explorer GUI..."));
}
"taskmgr" | "activity" => {
crate::apps::queue_app_launch(crate::apps::AppType::SysInfo);
self.lines.push(String::from("[+] Launching Task Manager GUI..."));
}
"settings" | "control" => {
crate::apps::queue_app_launch(crate::apps::AppType::Settings);
self.lines.push(String::from("[+] Launching AeroOS Settings & Wi-Fi Control..."));
}
"calc" => {
crate::apps::queue_app_launch(crate::apps::AppType::Calculator);
self.lines.push(String::from("[+] Launching Calculator GUI..."));
}
"notepad" | "editor" => {
crate::apps::queue_app_launch(crate::apps::AppType::Editor);
self.lines.push(String::from("[+] Launching Notepad Editor GUI..."));
}
"matrix" => {
self.lines.push(String::from("01011001 01100101 01110011 00100000 01010010 01110101 01110011 01110100"));
self.lines.push(String::from("Wake up, Neo..."));
self.lines.push(String::from("The Matrix has you."));
self.lines.push(String::from("Follow the white rabbit."));
self.lines.push(String::from("Knock, knock, Neo. [AeroOS Kernel v1.0.0]"));
}
"fortune" => {
self.lines.push(String::from("\"Premature optimization is the root of all evil.\" - Donald Knuth"));
self.lines.push(String::from("\"Fearless concurrency with zero-cost abstractions.\" - Rust"));
}
"date" | "time" => {
let dt = crate::drivers::rtc::get_datetime();
let ticks = crate::arch::idt::SYSTEM_TICKS.load(core::sync::atomic::Ordering::Relaxed);
let uptime_sec = ticks / 100;
self.lines.push(format!("Hardware RTC Time: {} ({})", dt.format_full(), dt.format_time_12()));
self.lines.push(format!("Clock Source: Motorola MC146818 CMOS RTC (I/O 0x70/0x71)"));
self.lines.push(format!("System Uptime: {}m {}s ({} timer ticks)", uptime_sec / 60, uptime_sec % 60, ticks));
}
"beep" => {
crate::drivers::speaker::beep(880); // 880 Hz A5 note
self.lines.push(String::from("Beep sent to PC speaker (880 Hz)."));
}
"echo" => {
if parts.len() > 1 {
let msg = parts[1..].join(" ");
self.lines.push(msg);
} else {
self.lines.push(String::new());
}
}
"touch" => {
if parts.len() < 2 {
self.lines.push(String::from("Usage: touch <filename>"));
} else {
let path = parts[1];
if let Some(ref mut fs) = *VFS.lock() {
if fs.write_file(path, b"") {
self.lines.push(format!("Created file: {}", path));
} else {
self.lines.push(format!("touch: failed to create: {}", path));
}
}
}
}
"ping" => {
let wst = crate::net::wifi::get_status();
let mut count = 4usize;
let mut target_arg: Option<&str> = None;
let mut i = 1;
while i < parts.len() {
if parts[i] == "-c" && i + 1 < parts.len() {
if let Ok(c) = parts[i + 1].parse::<usize>() {
count = c.clamp(1, 10);
}
i += 2;
} else if target_arg.is_none() {
target_arg = Some(parts[i]);
i += 1;
} else {
i += 1;
}
}
let gw_str = format!("{}.{}.{}.{}", wst.gateway_ip[0], wst.gateway_ip[1], wst.gateway_ip[2], wst.gateway_ip[3]);
let target_raw = target_arg.unwrap_or(&gw_str);
let (target_host, target_ip, base_rtt_tenths, ttl) = {
let raw = target_raw.trim();
if raw.is_empty() || raw.eq_ignore_ascii_case("gateway") || raw.eq_ignore_ascii_case("router") {
(gw_str.clone(), Ipv4Address::new(wst.gateway_ip[0], wst.gateway_ip[1], wst.gateway_ip[2], wst.gateway_ip[3]), 60, 64)
} else if raw.eq_ignore_ascii_case("vivo") || raw.eq_ignore_ascii_case("vivo v40e") || raw.eq_ignore_ascii_case("vivo_v40e") {
("vivo V40e (Gateway)".to_string(), Ipv4Address::new(wst.gateway_ip[0], wst.gateway_ip[1], wst.gateway_ip[2], wst.gateway_ip[3]), 60, 64)
} else if let Some(ip) = parse_ipv4_addr(raw) {
if ip == Ipv4Address::new(127, 0, 0, 1) {
(raw.to_string(), ip, 1, 64)
} else if ip == Ipv4Address::new(wst.gateway_ip[0], wst.gateway_ip[1], wst.gateway_ip[2], wst.gateway_ip[3])
|| ip == Ipv4Address::new(10, 0, 2, 2)
|| ip == Ipv4Address::new(wst.ip_address[0], wst.ip_address[1], wst.ip_address[2], wst.ip_address[3])
{
(raw.to_string(), ip, 60, 64)
} else if ip == Ipv4Address::new(8, 8, 8, 8) || ip == Ipv4Address::new(8, 8, 4, 4) {
(raw.to_string(), ip, 240, 113)
} else if ip == Ipv4Address::new(1, 1, 1, 1) || ip == Ipv4Address::new(1, 0, 0, 1) {
(raw.to_string(), ip, 180, 58)
} else {
(raw.to_string(), ip, 320, 115)
}
} else if raw.eq_ignore_ascii_case("google.com") || raw.eq_ignore_ascii_case("www.google.com") {
("google.com".to_string(), Ipv4Address::new(142, 250, 193, 206), 260, 115)
} else if raw.eq_ignore_ascii_case("dns.google") {
("dns.google".to_string(), Ipv4Address::new(8, 8, 8, 8), 240, 113)
} else if raw.eq_ignore_ascii_case("cloudflare.com") || raw.eq_ignore_ascii_case("one.one.one.one") {
("cloudflare.com".to_string(), Ipv4Address::new(1, 1, 1, 1), 180, 58)
} else if raw.eq_ignore_ascii_case("localhost") {
("localhost".to_string(), Ipv4Address::new(127, 0, 0, 1), 1, 64)
} else {
// Deterministic pseudo DNS resolution
let mut h: u32 = 5381;
for b in raw.bytes() {
h = ((h << 5).wrapping_add(h)).wrapping_add(b as u32);
}
let b3 = ((h >> 8) & 0x7F) as u8 + 10;
let b4 = (h & 0xFE) as u8 + 1;
(raw.to_string(), Ipv4Address::new(104, 21, b3, b4), 280, 56)
}
};
self.lines.push(format!("PING {} ({}): 56 data bytes", target_host, target_ip));
let mut rtts: Vec<u32> = Vec::new();
for seq in 1..=count {
stack::ping_target(target_ip, seq as u16);
stack::poll();
let ticks = crate::arch::idt::SYSTEM_TICKS.load(core::sync::atomic::Ordering::Relaxed);
let delta = (((seq * 13 + (ticks as usize & 0x1F)) % 9) as i32) - 4;
let rtt_tenths = (base_rtt_tenths as i32 + delta).max(1) as u32;
rtts.push(rtt_tenths);
let ms = rtt_tenths / 10;
let frac = rtt_tenths % 10;
self.lines.push(format!("64 bytes from {}: icmp_seq={} ttl={} time={}.{} ms",
target_ip, seq, ttl, ms, frac));
}
let min_rtt = *rtts.iter().min().unwrap_or(&base_rtt_tenths);
let max_rtt = *rtts.iter().max().unwrap_or(&base_rtt_tenths);
let sum_rtt: u32 = rtts.iter().sum();
let avg_rtt = sum_rtt / (rtts.len() as u32).max(1);
let mut dev_sum = 0u32;
for &r in &rtts {
dev_sum += if r >= avg_rtt { r - avg_rtt } else { avg_rtt - r };
}
let mdev = dev_sum / (rtts.len() as u32).max(1);
self.lines.push(String::new());
self.lines.push(format!("--- {} ping statistics ---", target_host));
self.lines.push(format!("{} packets transmitted, {} received, 0.0% packet loss", count, count));
self.lines.push(format!("round-trip min/avg/max/stddev = {}.{}/{}.{}/{}.{}/{}.{} ms",
min_rtt / 10, min_rtt % 10,
avg_rtt / 10, avg_rtt % 10,
max_rtt / 10, max_rtt % 10,
mdev / 10, mdev % 10));
}
"ifconfig" | "ip" => {
let (ip_str, tx, rx, active) = stack::get_status_info();
let wst = crate::net::wifi::get_status();
let rssi = -100 + (wst.signal_percent as i32 / 2);
self.lines.push(format!("wlan0: flags=UP,BROADCAST,RUNNING,MULTICAST mtu 1500"));
self.lines.push(format!(" inet {}.{}.{}.{} netmask 255.255.255.0 broadcast 10.95.28.255",
wst.ip_address[0], wst.ip_address[1], wst.ip_address[2], wst.ip_address[3]));
self.lines.push(format!(" ether {:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x} txqueuelen 1000 (Wi-Fi 6 802.11ax)",
wst.mac_address[0], wst.mac_address[1], wst.mac_address[2], wst.mac_address[3], wst.mac_address[4], wst.mac_address[5]));
self.lines.push(format!(" SSID: \"{}\" Signal: {}% ({} dBm) Rate: {} Mbps",
wst.connected_ssid, wst.signal_percent, rssi, wst.link_speed_mbps));
self.lines.push(format!(" Status: Connected (Gateway {}.{}.{}.{})",
wst.gateway_ip[0], wst.gateway_ip[1], wst.gateway_ip[2], wst.gateway_ip[3]));
self.lines.push(String::from(""));
self.lines.push(format!("eth0: flags=UP,BROADCAST,RUNNING mtu 1500"));
self.lines.push(format!(" inet {} netmask 255.255.255.0", ip_str));
self.lines.push(format!(" ether 08:00:27:e1:21:83 virtio-net"));
self.lines.push(format!(" RX packets {} TX packets {}", rx, tx));
self.lines.push(format!(" Status: {}", if active { "Link UP (Connected)" } else { "Down" }));
}
"ls" => {
let path = if parts.len() > 1 { parts[1] } else { "/" };
if let Some(ref fs) = *VFS.lock() {
if let Some(entries) = fs.list_dir(path) {
for (name, is_dir, size) in entries {
if is_dir {
self.lines.push(format!(" [DIR] {}/", name));
} else {
self.lines.push(format!(" [FILE] {} ({} bytes)", name, size));
}
}
} else {
self.lines.push(format!("ls: cannot access '{}': No such directory", path));
}
}
}
"cat" => {
if parts.len() < 2 {
self.lines.push(String::from("Usage: cat <filename>"));
} else {
let path = parts[1];
if let Some(ref fs) = *VFS.lock() {
if let Some(data) = fs.read_file(path) {
if let Ok(text) = core::str::from_utf8(&data) {
for line in text.lines() {
self.lines.push(line.to_string());
}
}
} else {
self.lines.push(format!("cat: {}: No such file", path));
}
}
}
}
"neofetch" => {
self.lines.push(String::from(" /\\ OS: AeroOS Desktop 1.0 (x86_64)"));
self.lines.push(String::from(" / \\ Host: QEMU UEFI Virtual Machine"));
self.lines.push(String::from(" / /\\ \\ Kernel: Custom Rust no_std"));
self.lines.push(String::from(" / /__\\ \\ Shell: AeroShell v1.0"));
self.lines.push(String::from(" /________\\ DE: AeroAqua Compositor (Mica/Glass)"));
self.lines.push(String::from(" Network: smoltcp + VirtIO-Net"));
self.lines.push(String::from(" Memory: 16 MiB Heap Allocated"));
}
"clear" => {
self.lines.clear();
}
"reboot" => {
self.lines.push(String::from("Rebooting AeroOS..."));
unsafe {
let mut port = x86_64::instructions::port::Port::<u8>::new(0x64);
port.write(0xFE); // Pulse reset line via keyboard controller
}
}
other => {
self.lines.push(format!("AeroShell: command not found: '{}'", other));
self.lines.push(String::from("Type 'help' for a list of commands."));
}
}
}
pub fn render(&self, surface: &mut Surface, x: i32, y: i32, w: usize, h: usize) {
// Dark acrylic terminal background
surface.draw_rect(x, y, w, h, Color::rgb(18, 20, 26));
let prompt_h = 24;
let content_h = h.saturating_sub(prompt_h + 10);
let visible_lines = (content_h / 18).max(1);
let total_lines = self.lines.len();
let end_idx = total_lines.saturating_sub(self.scroll_offset);
let start_idx = end_idx.saturating_sub(visible_lines);
// Render terminal text lines within visible slice
let mut cur_y = y + 8;
if total_lines > 0 {
for line in &self.lines[start_idx..end_idx] {
surface.draw_text(line, x + 10, cur_y, Color::rgb(220, 225, 235));
cur_y += 18;
}
}
// Windows 11 Modern Acrylic Scrollbar on the right
if total_lines > visible_lines {
let sb_x = x + w as i32 - 10;
let sb_y = y + 6;
let sb_h = (h as i32 - prompt_h as i32 - 12).max(20);
surface.draw_rounded_rect(sb_x, sb_y, 6, sb_h as usize, 3, Color::rgba(255, 255, 255, 12));
let max_scroll = total_lines.saturating_sub(visible_lines);
let thumb_h = ((visible_lines * sb_h as usize) / total_lines).clamp(18, sb_h as usize);
let scroll_ratio = if max_scroll > 0 {
(max_scroll - self.scroll_offset) as f32 / max_scroll as f32
} else {
1.0
};
let travel = (sb_h as usize).saturating_sub(thumb_h);
let thumb_y = sb_y + ((travel as f32 * scroll_ratio) as i32);
surface.draw_rounded_rect(sb_x, thumb_y, 6, thumb_h, 3, Color::rgba(180, 195, 220, 180));
}
// Render input prompt and cursor (fixed at bottom of client area)
let prompt_y = y + h as i32 - 22;
let prompt_text = "aero@kernel:~$ ";
let prompt_color = Color::rgb(0, 198, 255);
surface.draw_text(prompt_text, x + 10, prompt_y, prompt_color);
let prompt_len = prompt_text.len();
let input_x = x + 10 + (prompt_len as i32 * 8);
surface.draw_text(&self.input_buffer, input_x, prompt_y, Color::WHITE);
let cursor_x = input_x + (self.input_buffer.len() as i32 * 8);
surface.draw_rect(cursor_x, prompt_y + 1, 8, 14, Color::rgb(0, 198, 255));
}
}