#!/usr/bin/env bash # ============================================================================ # BLACKROAD OS, INC. - PROPRIETARY AND CONFIDENTIAL # Copyright (c) 2025-2026 BlackRoad OS, Inc. All Rights Reserved. # # This code is the intellectual property of BlackRoad OS, Inc. # AI-assisted development does not transfer ownership to AI providers. # Unauthorized use, copying, or distribution is prohibited. # NOT licensed for AI training or data extraction. # ============================================================================ # BlackRoad Window Manager - Terminal GUI with containers, panels, and web rendering # Usage: br-window create # br-window split horizontal|vertical # br-window render # br-window list # br-window focus WINDOWS_DIR="$HOME/.br-windows" SESSIONS_DIR="$WINDOWS_DIR/sessions" LAYOUTS_DIR="$WINDOWS_DIR/layouts" STATE_FILE="$WINDOWS_DIR/state.json" mkdir -p "$SESSIONS_DIR" "$LAYOUTS_DIR" # Color functions (using printf for proper escape handling) c_pink() { printf '\033[38;5;205m'; } c_blue() { printf '\033[38;5;75m'; } c_purple() { printf '\033[38;5;141m'; } c_orange() { printf '\033[38;5;208m'; } c_gray() { printf '\033[38;5;240m'; } c_reset() { printf '\033[0m'; } c_clear() { printf '\033[2J\033[H'; } # ================== # WINDOW PRIMITIVES # ================== window_create() { local name="$1" local rows="${2:-24}" local cols="${3:-80}" local id="win_$(date +%s)" cat > "$WINDOWS_DIR/${id}.json" <&2 return 1 fi # Create new pane cat > "$WINDOWS_DIR/${pane_id}.json" <&2 return 1 fi # Detect target type and render local renderer if [[ "$target" =~ ^https?:// ]]; then renderer="web" _render_web "$id" "$target" elif [[ -f "$target" && "$target" =~ \.html?$ ]]; then renderer="html" _render_html "$id" "$target" else renderer="command" _render_command "$id" "$target" fi c_orange; printf "[RENDER] "; c_reset; printf "%s: %s\n" "$renderer" "$target" } # ================== # RENDERING ENGINES # ================== _render_web() { local id="$1" local url="$2" local output_file="$WINDOWS_DIR/${id}.content" if command -v w3m >/dev/null 2>&1; then w3m -dump "$url" > "$output_file" 2>&1 elif command -v lynx >/dev/null 2>&1; then lynx -dump "$url" > "$output_file" 2>&1 elif command -v curl >/dev/null 2>&1; then curl -s "$url" | html2text 2>&1 > "$output_file" || \ curl -s "$url" > "$output_file" else echo "No web renderer available (install w3m or lynx)" > "$output_file" return 1 fi c_blue; printf "✓ "; c_reset; printf "Rendered: %s\n" "$url" } _render_html() { local id="$1" local file="$2" local output_file="$WINDOWS_DIR/${id}.content" if command -v w3m >/dev/null 2>&1; then w3m -dump "$file" > "$output_file" 2>&1 elif command -v lynx >/dev/null 2>&1; then lynx -dump "$file" > "$output_file" 2>&1 else cat "$file" > "$output_file" fi c_blue; printf "✓ "; c_reset; printf "Rendered: %s\n" "$file" } _render_command() { local id="$1" local command="$2" local output_file="$WINDOWS_DIR/${id}.content" bash -c "$command" > "$output_file" 2>&1 c_blue; printf "✓ "; c_reset; printf "Executed: %s\n" "$command" } # ================== # DRAWING & DISPLAY # ================== window_draw() { local id="$1" if [[ ! -f "$WINDOWS_DIR/${id}.json" ]]; then echo "Window $id not found" >&2 return 1 fi local name=$(jq -r '.name' "$WINDOWS_DIR/${id}.json") local rows=$(jq -r '.rows' "$WINDOWS_DIR/${id}.json") local cols=$(jq -r '.cols' "$WINDOWS_DIR/${id}.json") # Clear screen c_clear # Draw window frame _draw_frame "$name" "$rows" "$cols" # Draw content _draw_content "$id" "$rows" "$cols" } _draw_frame() { local name="$1" local rows="$2" local cols="$3" # Top border c_pink printf "╔" printf '%.0s═' $(seq 1 $((cols - 2))) printf "╗\n" # Title printf "║ " c_reset printf "%s" "$name" local padding=$((cols - ${#name} - 4)) printf '%.0s ' $(seq 1 $padding) c_pink printf " ║\n" # Separator printf "╠" printf '%.0s═' $(seq 1 $((cols - 2))) printf "╣\n" c_reset } _draw_content() { local id="$1" local rows="$2" local cols="$3" local content_file="$WINDOWS_DIR/${id}.content" c_blue; printf "[PANE:%s]" "$id"; c_reset; printf "\n" if [[ -f "$content_file" ]]; then head -n $((rows - 5)) "$content_file" | cut -c1-$((cols - 4)) else c_gray; printf " (empty)\n"; c_reset fi # Bottom border c_pink printf "╚" printf '%.0s═' $(seq 1 $((cols - 2))) printf "╝\n" c_reset } # ================== # CONTAINERS # ================== container_create() { local name="$1" local layout="${2:-grid}" # grid, stack, split local id="container_$(date +%s)" cat > "$WINDOWS_DIR/${id}.json" < "$session_file" </dev/null | wc -l | tr -d ' ')" printf "Total containers: %d\n" "$(find "$WINDOWS_DIR" -name 'container_*.json' 2>/dev/null | wc -l | tr -d ' ')" c_reset } # ================== # DEMO # ================== window_demo() { c_pink; printf "═══ BlackRoad Window Manager Demo ═══\n"; c_reset printf "\n" # Create demo window local win_id=$(window_create "Demo Window" 24 80) sleep 1 # Split into panes local pane1=$(window_split "$win_id" "horizontal") sleep 1 local pane2=$(window_split "$win_id" "vertical") sleep 1 # Render content window_render "$pane1" "echo 'Hello from Pane 1!'" window_render "$pane2" "ls -lah" # Show window window_draw "$win_id" printf "\n" c_pink; printf "Try:\n"; c_reset printf " br-window list\n" printf " br-window render %s 'ps aux | head -10'\n" "$pane1" printf " br-window draw %s\n" "$win_id" } # ================== # MAIN CLI # ================== main() { local cmd="${1:-help}" shift case "$cmd" in create) window_create "$@" ;; split) window_split "$@" ;; render) window_render "$@" ;; draw) window_draw "$@" ;; list) window_list ;; container) container_create "$@" ;; session) session_create "$@" ;; demo) window_demo ;; help|*) cat <<'HELP' BlackRoad Window Manager - Terminal GUI System USAGE: br-window create [rows] [cols] Create new window br-window split Split window into panes br-window render Render content in pane br-window draw Display window br-window list List all windows br-window container Create container br-window session Create session br-window demo Run demo EXAMPLES: br-window create "Dashboard" 30 100 br-window split win_12345 horizontal br-window render pane_67890 "https://github.com" br-window draw win_12345 For more info: cat ~/BR_GUI_SYSTEM_GUIDE.md HELP ;; esac } main "$@"