DOCUMENTATION / V1.0.0 LTS

Console.rs Extraction - Quick Start Guide

Location: /home/ldjiba/Sources/repos/OrbitOne/src/console.rs


📊 What You're Extracting

From console.rs (3,700 lines) to separate command modules:

Document Purpose Use For
CONSOLE_EXTRACTION_ANALYSIS.md Complete technical blueprint Understanding what to extract, exact line ranges, dependencies
CONSOLE_COMMANDS_REFERENCE.csv Quick lookup table Finding a command, its line numbers, and complexity
CONSOLE_DEPENDENCIES.md Dependency matrix Understanding what each module needs to import
CONSOLE_VISUAL_MAP.md Visual organization Understanding code structure and extraction strategy
This guide Quick reference Getting started fast

🎯 TL;DR - What to Do

The Numbers

The Modules

📁 commands/ (NEW)
├── mod.rs              (dispatch router)
├── help.rs             (3 commands, 95 lines) ← START HERE
├── storage.rs          (11 commands, 250 lines)
├── system.rs           (20+ commands, 1,700 lines)
└── memory.rs           (7 commands, 680 lines) OR split into:
    ├── memory.rs       (memory command only)
    ├── paging.rs       (paging command - 378 lines!)
    └── health.rs       (status/health/diagnose)

🔍 Finding Command Code

Option 1: Use Line Numbers (Fastest)

Open src/console.rs and go to line number:

Help section:          Lines 595-677
Storage (filesystem):  Lines 1794-2125
System/monitoring:     Lines 678-1026, 1515-1723, 2126-2203
Memory/paging:         Lines 812-1514

Option 2: Search by Command Name

Find your command in the execute_command function:

Ctrl+F in VS Code: "if eq_ignore_ascii_case(name, b"COMMAND_NAME""

Example: Find ls command

Result: Line 1842: if eq_ignore_ascii_case(name, b"ls") {

Option 3: Use CSV Reference

Open CONSOLE_COMMANDS_REFERENCE.csv - all commands listed with line ranges


📝 How to Extract a Command

Example: Extract help command (Lines 595-631)

  1. Find the dispatch block:

    // Line 595
    if eq_ignore_ascii_case(name, b"help") {
        // ... command body ...
        return;
    }
  2. Identify called functions:

    • Calls: print_help_general(), print_help_shell(), etc.
    • These MUST be extracted together
  3. Find helper functions:

    • Search for fn print_help_general()
    • Copy entire function body
    • Check what it calls (other functions to extract)
  4. Extract to help.rs:

    pub fn handle_help_command(name: &[u8], args: &[u8]) {
        if eq_ignore_ascii_case(name, b"help") {
            // ... command body from console.rs ...
            return;
        }
    }
  5. Update dependencies:

    • Import needed: crate::serial_println!
    • Import helpers: move print_help_general(), etc.

🛠️ Step-by-Step Extraction Process

PHASE 1: Setup (15 minutes)

# Create directory structure
mkdir -p src/commands

# Create files with stubs
touch src/commands/mod.rs
touch src/commands/help.rs
touch src/commands/storage.rs
touch src/commands/system.rs
touch src/commands/memory.rs

PHASE 2: Extract help.rs (30 minutes)

  1. Open CONSOLE_EXTRACTION_ANALYSIS.md → Search for "Help-related handlers"
  2. Copy lines 595-677 from console.rs
  3. Copy helper functions (print_help_*, print_aliases)
  4. Paste into src/commands/help.rs
  5. Fix imports

PHASE 3: Extract storage.rs (1 hour)

  1. Open CONSOLE_EXTRACTION_ANALYSIS.md → Search for "Storage handlers"
  2. Copy lines 1794-2125
  3. Copy helpers: resolve_shell_path, print_tree_recursive, etc.
  4. Paste into src/commands/storage.rs
  5. Add WORKING_DIR access
  6. Fix imports

PHASE 4: Extract system.rs (2-3 hours)

  1. Find all system commands in CONSOLE_EXTRACTION_ANALYSIS.md
  2. Copy dispatch blocks (multiple non-contiguous ranges!)
  3. Copy 35+ helper functions
  4. Organize by category in file
  5. Fix imports

PHASE 5: Extract memory.rs (2-3 hours)

  1. Copy lines 812-1514 (memory, paging, health, diagnose commands)
  2. Copy all helper functions
  3. Decision point: Keep as one file or split?
    • Option A: Single memory.rs with 680 lines
    • Option B: Split into memory.rs, paging.rs, health.rs

PHASE 6: Integration (1 hour)

  1. Create commands/mod.rs dispatcher
  2. Update console.rs execute_command() to call dispatcher
  3. Test compilation
  4. Test command execution

For help.rs

// Need to import:
use crate::serial_println;
use crate::shell_parse;

// Use from console.rs:
fn ascii_bytes_to_str(bytes: &[u8]) -> &str

For storage.rs

// Need:
use alloc::string::String;
use crate::serial_println;
use crate::fs;
use crate::pathing;

// Need access to:
WORKING_DIR: Mutex<WorkingDirectoryState>

// Functions to move:
current_working_dir()
set_current_working_dir()
resolve_shell_path()
print_tree_recursive()

For system.rs

// Need many crate imports:
use crate::cpu;
use crate::interrupts;
use crate::paging;
use crate::memory;
use crate::boot;
use crate::power;
use crate::serial;
use crate::server_tasks;

// Move 40+ print functions
// Access collect_health_state()

For memory.rs

// Heavy dependencies:
use crate::paging;
use crate::memory;
use crate::interrupts;
use crate::cpu;
use crate::boot;

// Struct to move:
struct HealthState { ... }

// Functions to move:
collect_health_state()
print_diagnose()
print_diagnose_json()

⚠️ Critical Gotchas

1. Paging Command is HUGE (378 lines)

2. Shared State Access

3. Helper Function Reuse

These are used by MULTIPLE modules:

4. Print Functions Dependencies

Many print functions call OTHER print functions:

5. Compilation Issues

When compiling after extraction:

  1. You'll get "function not found" errors
  2. This means you missed extracting a helper
  3. Check CONSOLE_EXTRACTION_ANALYSIS.md for "Helper Functions" section
  4. Search console.rs for fn followed by the missing function name

📋 Extraction Checklist

[ ] Setup

[ ] Phase 1: help.rs

[ ] Phase 2: storage.rs

[ ] Phase 3: system.rs

[ ] Phase 4: memory.rs

[ ] Phase 5: Integration

[ ] Phase 6: Cleanup


🚀 Start Here

  1. Read: CONSOLE_VISUAL_MAP.md (5 min) - Understand structure
  2. Reference: Keep CONSOLE_COMMANDS_REFERENCE.csv open in editor
  3. Deep dive: Use CONSOLE_EXTRACTION_ANALYSIS.md for detailed line ranges
  4. Check dependencies: Use CONSOLE_DEPENDENCIES.md before extracting each module
  5. Start small: Begin with help.rs (lowest complexity)

📞 Troubleshooting

Problem Solution
"Function not found" error Function wasn't extracted. Search CONSOLE_EXTRACTION_ANALYSIS.md for function name in "Helper Functions" section
Multiple line ranges needed Some commands are in different parts of file. See CONSOLE_VISUAL_MAP.md for complete ranges
Compilation fails Missing imports. Check CONSOLE_DEPENDENCIES.md for required crates
Can't find WORKING_DIR It's in console.rs around line 150. You need pub access or pass as parameter
Memory.rs too large Consider splitting: memory.rs + paging.rs + health.rs (recommended)

🎯 Success Criteria

After extraction, you should have:

✅ src/commands/mod.rs - dispatcher ✅ src/commands/help.rs - 3 commands, 95 lines ✅ src/commands/storage.rs - 11 commands, 250 lines ✅ src/commands/system.rs - 20+ commands, 1,700 lines ✅ src/commands/memory.rs - 7 commands, 680 lines (or split) ✅ src/console.rs - reduced to ~500 lines ✅ All commands still work identically ✅ Code compiles without warnings ✅ Tests pass


Ready to start? Begin with help.rs - it's the simplest!