Skip to content

feat: add stdin/pipe support#3

Merged
PPRAMANIK62 merged 2 commits intomainfrom
feat/stdin-pipe-support
Mar 20, 2026
Merged

feat: add stdin/pipe support#3
PPRAMANIK62 merged 2 commits intomainfrom
feat/stdin-pipe-support

Conversation

@PPRAMANIK62
Copy link
Copy Markdown
Owner

@PPRAMANIK62 PPRAMANIK62 commented Mar 20, 2026

Summary

  • Add support for reading markdown from stdin via pipes (echo "# Hello" | mdt, cat README.md | mdt, mdt -)
  • Stdin mode is read-only: editor, file tree, and file finder are disabled with clear status messages
  • Navigation, search, help overlay, link picker, and quit all work normally on piped content

Changes

File What
src/app/mod.rs stdin_mode field, App::from_stdin() constructor, display_file_path() returns <stdin>
src/main.rs Stdin detection, eager read before terminal setup, skip bg color detection for pipes, branched init, run_loop takes Option<&Receiver>
src/input/editor.rs Guard enter_editor() — "Read-only (stdin)"
src/input/normal.rs Guard toggle_file_tree() — no-op in stdin mode
src/app/file_finder.rs Guard open_file_finder() — "Not available (stdin)"
src/ui/status_bar.rs Show line position for stdin content
src/app/tests.rs 8 new tests for stdin mode
website/ Document stdin support in configuration and getting-started docs

Test plan

  • cargo test — 300 tests pass (8 new stdin tests, 0 regressions)
  • cargo clippy -- -D warnings — clean
  • cargo fmt --check — clean
  • echo "# Hello World" | cargo run — renders heading
  • echo "# Hello\n\n- item 1\n- item 2" | cargo run — renders list
  • cargo run -- - with typed input then Ctrl+D — renders stdin
  • cargo run (no pipe) — existing behavior unchanged
  • i/e in stdin mode — shows "Read-only (stdin)"
  • Space+e in stdin mode — does nothing
  • ff in stdin mode — shows "Not available (stdin)"
  • Scrolling, / search, heading jump, ? help, q quit — all work

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added stdin mode: pipe Markdown into the app for read-only preview (e.g., cat file.md | mdt or mdt -). Editor, file finder, and file-tree toggling are disabled; a stdin pseudo-path is shown.
  • Documentation

    • Added docs and examples for reading Markdown from stdin.
  • Tests

    • Added tests covering stdin-mode behavior (UI focus, read-only enforcement, navigation, help, quit).
  • Chores

    • Updated project/site URLs in docs and metadata.

Allow mdt to read markdown content from stdin via pipes (e.g.,
`echo "# Hello" | mdt`, `cat README.md | mdt`, or `mdt -`).

Stdin mode is read-only with the file tree, file finder, and editor
disabled. The status bar shows `<stdin>` as the file path. Navigation,
search, help, and link picker all work normally on piped content.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 20, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ba8ab492-2a91-4578-8453-3336d1d05ff7

📥 Commits

Reviewing files that changed from the base of the PR and between 73188a0 and 8128b2a.

📒 Files selected for processing (4)
  • Cargo.toml
  • README.md
  • website/astro.config.ts
  • website/src/components/LandingLayout.astro

📝 Walkthrough

Walkthrough

Adds a piped-stdin read-only mode: main detects piped input, reads content, constructs the app via App::from_stdin(...), and disables editor, file tree, and file finder while rendering the document in preview mode.

Changes

Cohort / File(s) Summary
App Core
src/app/mod.rs, src/app/file_finder.rs
Added stdin_mode: bool and App::from_stdin(...); display_file_path() returns "<stdin>" in stdin mode. open_file_finder() now short-circuits with status "Not available (stdin)" when stdin mode is active.
Input & Interaction
src/input/editor.rs, src/input/normal.rs
enter_editor() and toggle_file_tree() short-circuit in stdin mode (set status messages "Read-only (stdin)" / prevent toggling), preventing editor creation and file-tree visibility changes.
Startup & Runtime
src/main.rs
Detects piped stdin (or -), reads content (enforces --max-file-size), uses App::from_stdin(...) for piped mode, skips lockfile and watcher, and makes watcher/lockfile teardown conditional; run_loop accepts optional watcher receiver.
UI
src/ui/status_bar.rs
Line counter now also renders for stdin mode when rendered_lines non-empty.
Tests
src/app/tests.rs
Added tests covering App::from_stdin behavior: stdin initialization, read-only enforcement (editor/file-tree/file-finder), pseudo-path display, navigation/search/help, and quitting.
Docs / Website
website/src/content/docs/configuration.mdx, website/src/content/docs/getting-started.mdx
Documented piped-stdin usage and - path, read-only semantics, examples (`echo ...
Metadata / Site
Cargo.toml, website/astro.config.ts, website/src/components/LandingLayout.astro, README.md
Updated homepage/site URL references from https://mdtui.pages.dev/... to https://mdt.purbayan.me/....

Sequence Diagram

sequenceDiagram
    participant User
    participant Main as main()
    participant Stdin
    participant App
    participant UI

    User->>Main: invoke mdt with piped input
    Main->>Stdin: detect piped stdin / read content (enforce max size)
    Stdin-->>Main: content string
    Main->>App: App::from_stdin(content, bg_color)
    App->>App: render markdown, rebuild caches, set stdin_mode
    Main->>UI: render read-only preview (no lockfile, no watcher)
    UI-->>User: display document (editor/file-tree/file-finder disabled)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐇 I nibble bytes from pipes at night,

stdin glows, a soft preview light,
No keys to worry, no tree to roam,
Just rendered Markdown, snug as home,
Hop, enjoy the read-only sight! 📜✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add stdin/pipe support' directly and clearly summarizes the main change—adding stdin/pipe input capability to the application.
Docstring Coverage ✅ Passed Docstring coverage is 89.47% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/stdin-pipe-support

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can use OpenGrep to find security vulnerabilities and bugs across 17+ programming languages.

OpenGrep is compatible with Semgrep configurations. Add an opengrep.yml or semgrep.yml configuration file to your project to enable OpenGrep analysis.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Mar 20, 2026

Deploying mdtui with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8128b2a
Status: ✅  Deploy successful!
Preview URL: https://3a9d63ef.mdtui.pages.dev
Branch Preview URL: https://feat-stdin-pipe-support.mdtui.pages.dev

View logs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@PPRAMANIK62 PPRAMANIK62 merged commit 94251e9 into main Mar 20, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant