Skip to content

the-ginger-geek/codepad

Repository files navigation

CodePad

CodePad is a lightweight, minimalist, and feature-rich code editor built natively for macOS using Swift and SwiftUI. It combines the simplicity of a scratchpad with the power of a document-based code editor, featuring first-class Swift script execution and an integrated terminal.


Key Features

  • 📂 Multi-Format Document Support: Seamlessly open, edit, and save a wide range of code-related and text files, including .swift, .json, .java, .cs, .csproj, .cpp, .dart, .env, and .gitignore.
  • ⚙️ Unified Editor Settings: Configure editor preferences globally, including:
    • Indentation settings (tabs vs soft spaces, custom tab widths).
    • Smart indentation and character auto-pairing.
    • Curated syntax highlighting themes.
  • ⌨️ Keyboard Shortcut Manager: View and re-assign keyboard shortcuts dynamically.
  • First-Class Swift Execution:
    • Run .swift scripts directly inside the app with Cmd + R or the floating play button.
    • Asynchronous background execution (uses /usr/bin/swift) prevents UI lockups.
    • Interactive play/stop states let you terminate infinite loops or long-running scripts cleanly.
    • Sliding glassmorphic console drawer logs stdout and stderr in real-time.
  • 🔢 Low-Key Line Numbers: A native, highly optimized NSRulerView gutter that renders line numbers cleanly in a small, faint monospaced font so you can focus on code.

Keyboard Shortcuts

Command Shortcut Description
New Window Cmd + N Open a new scratchpad or editor window
Open File Cmd + O Open any supported code/text file
Save File Cmd + S Save active file changes
Format Document Ctrl + Shift + F Auto-format braces/brackets for C-family, JSON, & Swift
Run Script Cmd + R Execute active .swift script / Open Console drawer
Settings Cmd + , Open CodePad preferences window

Architecture & Codebase

  • CodePadApp.swift: Bootstraps the SwiftUI application, configures multi-window groupings for document files (WindowGroup(for: URL.self)), and registers global menu shortcuts.
  • ContentView.swift: Implements the main workspace, coordinates file open/save dialogs, manages theme states, and operates the async Swift script subprocess engine.
  • LineNumberRuler.swift: Houses the native AppKit NSRulerView subclass (LineNumberRulerView) and the NSViewRepresentable view tree listener (LineNumberConfigurator) to inject line numbers into the editor's scroll view.
  • FormatterService.swift: Auto-formats brackets and indentation for C-style syntaxes (Swift, C++, C#, Java) and JSON.
  • ShortcutManager.swift & ShortcutsView.swift: Manage global shortcuts and render the shortcut re-assignment panel.

Build and Run Instructions

Prerequisites

  • macOS 14.0 or newer
  • Xcode 15.0+ or Swift Toolchain 5.9+

Build and Run Locally

To run CodePad in development mode:

swift run

Package Release DMG

To package a standalone, production-ready .app bundle inside a .dmg image, run:

bash scripts/build-dmg.sh

The final image will be output to .build/CodePad-1.0.0.dmg.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors