Skip to content

simwai/babae

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PowerShell 7+ Cross-platform SSH / xterm-256color Pester 5 Highly Experimental MIT License


Warning

babae is highly experimental. It is a quick and dirty attempt at building a PowerShell-based TUI code editor. Expect rough edges, missing features, and occasional cursed behaviour. Use at your own risk — preferably not on production systems.


Introduction

babae is a zero-dependency TUI text editor written in pure PowerShell. No NuGet packages, no compiled DLLs, no external binaries — just a single .ps1 file you can drop anywhere and run. It renders via raw ANSI escape sequences, handles input via bracketed paste mode (BPM), and speaks .editorconfig.

Its primary reason for existence: most terminal editors misbehave when pasting indented text over SSH in Bitvise (xterm-256color). babae fixes that at the input layer.

Key Features

  • Zero Dependencies: One file. pwsh ./babae.ps1. Done.
  • SSH-Safe Paste: Bracketed paste mode (BPM) support across both interactive and redirected stdin paths. Right-click paste over SSH does not staircase — ever. See The Stairway Paste Fix.
  • ANSI TUI Rendering: Low-flicker frame rendering via a shadow row buffer and direct stdout stream writes. Only changed rows are redrawn.
  • Four Dark Themes: babae dark, Catppuccin Mocha, Catppuccin Frappe, GitHub Dark. Cycle with ^T.
  • Undo / Redo: Snapshot-based undo stack (up to 200 entries) with ^Z / ^Y.
  • Incremental Search: Live highlighting across the buffer with ^F.
  • Cross-Platform Clipboard: ^C / ^V via xclip / xsel / wl-copy on Linux (X11 and Wayland), pbcopy / pbpaste on macOS, System.Windows.Forms.Clipboard on Windows.
  • .editorconfig Support: Picks up indent_style, indent_size, end_of_line, trim_trailing_whitespace, insert_final_newline, and charset from the nearest .editorconfig.
  • Mouse Right-Click Paste on Windows: Win32 console API integration for native right-click paste events.
  • Language Detection: Automatic language label in the header based on file extension (see Language Detection).
  • Global Install: On first run outside ~/.babae/, babae offers to install itself globally and register a babae shell function in your PowerShell profile.

Environment Setup Guide

1. Install PowerShell 7+

babae requires PowerShell 7 or later.

2. Download babae

curl -O https://raw.githubusercontent.com/simwai/babae/main/babae.ps1

That is the entire installation.

Global Install

On first run, if babae detects it is not already running from ~/.babae/babae.ps1, it will prompt:

babae is not installed globally. Install to ~/.babae/babae.ps1 and add to profile? (y/n):

Answering y copies babae.ps1 to ~/.babae/ and appends a babae function to your $PROFILE, so you can launch it from anywhere with:

babae myfile.txt

If a different version is already installed, the same prompt appears offering to update it. Set $Env:BABAE_SKIP_INSTALL = 1 to suppress this check entirely.

Usage Guide

# Open a new buffer
pwsh ./babae.ps1

# Open an existing file
pwsh ./babae.ps1 myfile.txt

# Open with a specific theme
pwsh ./babae.ps1 myfile.txt -Theme mocha

Keybindings

Key Action
^S Save
^Q Quit
^Z Undo
^Y Redo
^F Find (incremental search)
^A Select all
^C Copy selection (or current line)
^V Paste from clipboard
^T Cycle theme
^H Help
Arrow keys Move cursor
Shift+Arrows Extend selection
Home / End Start / end of line
PgUp / PgDn Scroll by screen
Backspace / Del Delete character
Enter New line with auto-indent
Tab Insert indent (space or tab per .editorconfig)
Esc Cancel search / clear selection
RightClick Paste from clipboard (Windows only)

Themes

Flag value Name
dark (default) babae dark
mocha Catppuccin Mocha
frappe Catppuccin Frappe
github-dark GitHub Dark

Language Detection

babae automatically displays a language label in the header bar based on the opened file's extension. No configuration needed.

Extension(s) Language
.ps1, .psm1, .psd1 PowerShell
.cs C#
.ts, .tsx TypeScript
.js, .jsx JavaScript
.py Python
.json JSON
.md Markdown
.sh, .bash Bash
(anything else) Plain Text

The Stairway Paste Fix

When pasting multi-line indented text via right-click over SSH (Bitvise, xterm-256color), every \n in the paste stream used to hit the Enter handler, which re-injected the current line's leading whitespace — compounding it on every successive line and producing an ever-widening staircase of indentation.

This is an open bug in micro and stems from editors not properly handling bracketed paste mode (BPM) sentinels (ESC[200~ / ESC[201~), which terminals use to wrap paste payloads so editors can distinguish pasted text from typed input.

babae fixes this by enabling BPM (ESC[?2004h) on launch and running a dual-path input architecture:

  • Interactive mode (normal terminal use): a background PowerShell runspace reads keys via [Console]::ReadKey($true) and pushes them into a ConcurrentQueue. When an ESC is detected, babae peeks ahead in the queue to assemble the full sequence. If ESC[200~ is matched, the paste payload is drained via Stdin-DrainPasteInteractive — consuming chars until ESC[201~ — and routed directly to the insert routine, bypassing the Enter handler and its auto-indent logic entirely.

  • Redirected mode (test harness / piped stdin): babae falls back to reading Console.OpenStandardInput() as a raw byte stream. BPM sentinels are detected at the byte level in Stdin-DrainPaste, making the test suite independent of any terminal or .NET console abstraction.

In both paths, the paste payload never touches the Enter handler. No staircase.

Testing

E2E tests use Pester 5 with no Docker. Each test starts babae as a child process with stdin/stdout fully redirected, writes raw byte sequences to stdin, and verifies the output file.

# Install Pester (once)
Install-Module -Name Pester -MinimumVersion 5.0 -Force -Scope CurrentUser

# Run the suite
Invoke-Pester ./babae.tests.ps1 -Output Detailed

The suite covers:

  • BPM byte-sequence helper unit tests
  • Stairway regression: uniform indent, mixed indent, empty paste, 500-line large paste
  • Normal key input: printable chars, Enter auto-indent, Ctrl+Z undo/redo
  • Ctrl+V clipboard paste path isolation

Contributors