Skip to content
المشاريع

حول

Read PDFs, markdown files and web articles in the terminal.

أدوات التطوير

كيف تُقاس هذه الأرقام

744 نجمة41 التفرعات +85 خلال 24 ساعة

النمو المقاس للنجوم

خلال 24 ساعة
+٨٥
خلال 7 أيام
+٢٩٢
خلال 15 يومًا
+٤٢٠
خلال شهر
جارٍ جمع السجل

تغيّر صافي النجوم خلال فترات متداخلة، وليس مجموعًا يوميًا. تبقى القياسات المفقودة فارغة. النجوم تقيس الاهتمام لا جودة البرمجيات.

README.md

الأصل
leaf

leaf

Read PDFs, Markdown, office files and web articles in the terminal, review diffs and pull requests, sketch on a whiteboard, and review your coding agent's plans.

Sponsor Website @dipxsyy on X

Install

curl -fsSL https://leaf.dipxsy.app | sh

Installs a prebuilt leaf to ~/.local/bin for macOS 11+ or Linux (glibc 2.35+), x86_64 or arm64. The download is checked against its SHA-256. LEAF_INSTALL_DIR and LEAF_VERSION override the location and release. Linux needs the ALSA sound library (libasound2t64 or libasound2).

Homebrew:

brew install deepanshumishraa/tap/leaf

From source (Linux also needs build-essential cmake pkg-config libclang-dev libasound2-dev libfontconfig1 zlib1g-dev. On macOS, install CMake and the Xcode Command Line Tools. The iPhone Duo's hinge also needs Xcode's iOS Simulator SDK):

cargo install leaf-reader

leaf upgrade updates in place (Homebrew installs are left to brew upgrade). Shell completions are in completions/ (fish: leaf.fish, zsh: _leaf, nushell: leaf.nu, PowerShell: leaf.ps1).

Reading

leaf open paper.pdf
leaf open notes.md
leaf open talk.pptx
leaf open https://example.com/post
leaf --type md NOTES       # read a file in a format its name doesn't show
leaf                       # pick a recent or nearby document

Supports PDF, EPUB, Markdown (GitHub extensions, wikilinks, Mermaid, LaTeX math) and MDX, reStructuredText, saved HTML, pictures, Word, PowerPoint, Excel/ODS and CSV/TSV, and plays audio files. Any other text file (source code, scripts, config, logs) opens as code, colored by its language. --type reads a file in a format its name doesn't show: leaf --type md NOTES reads a markdown file called NOTES, and --type py colors a script as Python. It takes md, rst, html, txt or a language name, and the file keeps the format when it reloads. Links to PDFs, arXiv papers and raw Markdown open as such; other pages go through Readability.

Leaf renders TeX math offline in Markdown. Use $…$, \(…\), or GitHub's $`…`$ for inline math. Use $$…$$, \[…\], or a math, latex, tex, or katex fence for a display equation. Try leaf open examples/math.md.

  • ←/→ page, j/k scroll, g/G first/last, f find, ? all keys, q quit
  • Drag to select and copy; y highlights, d draws, @ asks your agent about the selection
  • a reads aloud with Microsoft Edge's online voices; s picks a voice
  • </> narrow or widen the column, i toggles painted images

Spreadsheets and CSV files open in a grid of cells, with column letters, row numbers and the first row pinned as the header. Move with the arrows or hjkl, or click a cell. Drag, or hold shift, to select a range, and the bottom line shows its count, sum and average. Click a column letter or row number to select the whole column or row. / finds, : goes to a cell such as B12, s sorts by the column, F shows only rows whose cell in the column holds some text, y copies the selection as tab-separated text, @ asks your agent about the selected cells, [/] switch sheets and </> resize the column. The cell bar at the top shows a cell's whole text, and its formula in Excel files. Sorting and filtering change only the view.

CSV and TSV files can be edited. e (or f2) edits the cell and enter keeps it, x empties the selected cells, o/O add a row below or above, D deletes the selected rows, I adds a column and X deletes the selected columns. u undoes and U redoes. Nothing is written until ctrl+s saves, which keeps the file's delimiter, line endings and quoting; quitting with unsaved edits asks first. Excel and OpenDocument files are only read.

Images use the Kitty, iTerm2 or Sixel protocol, falling back to half blocks. Reading place, highlights and drawings are saved in ~/.local/share/leaf/leaf.db. Local files reload when they change.

Audio

leaf play song.mp3
leaf play interview.m4a
leaf play daft punk one more time                   # the best match on YouTube Music
leaf play https://youtu.be/dQw4w9WgXcQ
leaf play https://open.spotify.com/track/4cOdK2wGLETKBW3PvgPWqT

Audio files play in the terminal: MP3, AAC and ALAC (.m4a, .m4b), FLAC, WAV, AIFF, CAF, Ogg Vorbis and Matroska audio (.mka). A live spectrum moves with the sound, and the whole track's waveform is the seek bar: click or drag it to jump. The title, artist and album come from the file's tags.

leaf play plays from the web: a YouTube, YouTube Music, SoundCloud or Bandcamp link, or words to search YouTube Music for. It needs yt-dlp and ffmpeg (brew install yt-dlp ffmpeg). Sound starts as soon as yt-dlp finds the track, while the track downloads to a temporary folder. Once it's downloaded, the waveform and captions show and seeking is instant. A kept track is copied into leaf's cache, and playing the same link or search again opens it without going online. s keeps the track or not, and the footer shows kept or not kept. Tracks start kept. A track that isn't kept is deleted when the player closes or switches tracks. Tracks are saved in ~/Library/Caches/leaf/audio on macOS, or ~/.cache/leaf/audio ($XDG_CACHE_HOME) on Linux, and the 60 most recent are kept. Spotify's audio only plays in Spotify's apps, so a Spotify song link plays the same song from YouTube Music, found by its title and artist.

On macOS 26 and later, captions show the phrase being spoken, with the word being said marked. They come from macOS's own speech recognition, on the device, read from the file a little ahead of playback. The first time, macOS may download the speech model for your language.

  • space plays or pauses, ←/→ seek 5 seconds, H/L seek 30, g goes back to the start
  • ] goes round the speeds 1×, 1.5× and 2×; [ and > step slower or faster, from 0.5× to 4×; = goes back to 1×. The pitch stays the same.
  • ↑/↓ or the scroll wheel change the volume, c shows or hides captions, ? all keys, q quits
  • t opens the library beside the player: every saved track, newest first. j/k or ↑/↓ move, enter or a click plays the track, and t or esc closes it. Other keys still reach the player.

Every key can be rebound under [keys.audio] and [keys.audio_library] in config.toml; leaf config keys lists them.

SQLite databases

Open a local SQLite file with leaf data.db or leaf open data.sqlite3. The sidebar groups regular tables under Tables and saved queries under Views. Press t or click Hide sidebar to collapse it. Press Tab to switch focus between the sidebar and grid. In a narrow pane, t opens a full-width list. Use [ and ] to switch tables, and i to inspect column types, defaults and primary keys. Browse 200 rows at a time with - and +. Use / to find text in the current batch and y to copy the selected cells.

Press x to open the SQL drawer. The first draft starts with a query for the current table, and X starts a fresh one. ctrl+o inserts the selected grid column's name. As you type, the drawer suggests SQL keywords, table names after FROM and JOIN, and the columns of tables you have opened. Press tab or enter to insert a suggestion, up and down to pick another, and esc to close the list. ctrl+r runs one read-only SQL statement and shows up to 200 result rows in the same grid. esc returns to the table. The current view refreshes as other programs commit changes. Press L to pause live refresh or r to refresh on demand. Rebind viewer actions and grid navigation under [keys.db]. Rebind text controls such as Enter and Backspace under [keys.db_input]. Run leaf config keys to see the defaults, or press ? in the viewer to see your active bindings.

Try bookshop.db or transit.sqlite3. The database tour has keys to try, join and aggregation queries, and a live refresh demo.

PostgreSQL databases

Open a PostgreSQL URL with leaf open 'postgresql://[email protected]/catalog'. Use postgres:// or postgresql://. A password in the URL takes precedence over PGPASSWORD. Percent-encode characters such as @ in a URL password. To keep the entire URL out of command arguments, set DATABASE_URL and run leaf open --database-url.

The connection verifies the TLS certificate and hostname by default. Use sslrootcert=/path/to/ca.pem in the URL or set PGSSLROOTCERT for a private CA. Use sslmode=disable for a trusted local connection. Use a read-only database role for shared or production databases.

PostgreSQL uses the same grid and SQL drawer. Leaf reuses the connection as you switch tables or move between 200-row batches. Press r to refresh the schema and active view, or L to turn on polling every five seconds. Remote polling starts paused.

Reader fonts

Leaf uses your terminal font by default. In Rex, choose Leaf: Reader Font… from the command palette and search the installed font families. Rex opens a Leaf picker when its palette picker is unavailable or the reader is on a remote host. From any terminal, use the same setting:

leaf font list
leaf font select "IBM Plex Serif"
leaf font select ibm-plex-serif
leaf font reset
leaf font --pick

The list marks your current choice, and it is saved for documents you open later on the same machine. leaf font --pick searches the fonts in the terminal and shows each one in open readers as you move to it. enter keeps it and esc puts the old one back. Open readers check for changes four times a second. Custom fonts work in the reflowable reader when the terminal supports direct Kitty graphics, including Rex and Ghostty. If the graphics or selected font are unavailable, Leaf uses the terminal font. Code blocks and tables use the reader font with each character in its terminal column, so their columns still line up. Paragraphs with inline equations and original-layout pages keep their own layout.

Configuration

Optional, at $XDG_CONFIG_HOME/leaf/config.toml (default ~/.config/leaf/config.toml):

[reader]
max_width = 100   # reading column width, default 76
colorful_markdown = true   # terminal palette colors for heading levels and links, default false
hide_link_urls = true   # hide URLs printed after clickable link labels, default false

[diff]
layout = "inline"   # "split" or "inline"; left out, a diff opens in the layout last used
wrap = false        # wrap long code lines when a diff opens, default false
auto_refresh = true # refresh open diffs in the background, default true

[outline]
width = 40   # the outline sidebar's width when it opens, 20 through 80, default 32

[plan]
jump = "top"   # where ], [ and other block jumps in leaf plan leave the block: "top" of the screen, or "nearest" (default), scrolling the least
scrolloff = 3   # rows kept below the cursor as it moves down in leaf plan, at most half the screen, default 0

# Rebind keys. Each line names an action and one key or a list of them.
# Actions you leave out keep their keys; an empty list unbinds one.
[keys.reader]
quit = ["q", "ctrl+q"]
scroll_down = ["j", "down", "ctrl+e"]
pen = []

[keys.diff]
next_file = ["]", "n", "tab"]
reload = "R"        # rebind the default reload key, r

[keys.board]
tool_box = "R"

Every view has its own key table: reader, ink, bookmarks, outline, diff, diff_comments, diff_overview, confirm_post, verdict, plan, plan_notes, plan_quit, board, browser, pr_list, pr and sheet. leaf config keys prints them all with every action, its default keys and what it does, ready to copy. Text you type, such as comments, find and filters, keeps its own keys.

Keys are written as q, G, ctrl+d, alt+enter, shift+tab, space, enter, esc, tab, up, pagedown, home, f1 and so on. A key an action didn't have before is taken from any other action that had it, so each key does one thing; restating an action's defaults changes nothing. A reader color can't share a key with a [keys.ink] action, since ink keys come first while a stroke is picked. ? lists the keys as you set them.

leaf config check reads the file as leaf would. A file that doesn't read stops the reader, leaf diff, leaf review, leaf plan, leaf board and leaf pr with a message naming the line. If it breaks while leaf pr is open, opening the Code tab shows the error instead and leaf pr stays as it was. A misspelled action lists the actions its table has, and a misspelled key says how to write one. leaf config path prints where the file is.

Diffs

leaf diff                  # unstaged changes
leaf diff --staged
leaf diff --branch         # working tree, including untracked files, against the merge base
leaf diff main...HEAD
leaf diff changes.patch
leaf diff https://github.com/owner/repo/pull/12

Side-by-side by default; i switches to one column. c comments on a line or range, ctrl+enter sends it to your agent, ctrl+g posts it to GitHub. GitLab merge requests work too (via glab or GITLAB_TOKEN). leaf comments --json exports saved comments.

W toggles code line wrapping in both layouts, including in a pull request's Code tab. With wrapping off, H and L scroll sideways.

Press r to reload a diff, or rebind it with [keys.diff] reload. Leaf also checks for local changes about once a second. Set [diff] auto_refresh = false to refresh by key only. Automatic refresh waits while you're typing a comment or selecting lines. If a file with saved line comments changes, Leaf keeps the reviewed snapshot until you clear those comments.

Pull requests and issues

leaf pr                    # your open PRs and issues
leaf pr 12
leaf pr owner/repo#12

Tabs for summary, timeline, comments, code and checks. Merge, approve, comment, close and re-run jobs from the terminal. Needs gh signed in.

Forgejo

Forgejo does not require gh. In a Forgejo checkout, leaf pr lists that repository's pull requests and issues. leaf pr 12 opens a pull request; a full /pulls/12 or /issues/12 link works from any folder. Browse the summary, timeline, comments and diff. Forgejo is read-only in Leaf, and its checks are not loaded yet. Press o to open the item in your browser.

Leaf recognizes codeberg.org without setup. For a self-hosted Forgejo, set FORGEJO_HOST to its HTTPS origin, including the port if needed. Installations under a URL subpath are not supported. HTTPS uses your system's trusted certificates. FORGEJO_TOKEN is optional for public repositories. For private repositories, set it to a token with read:repository and read:issue access. Leaf sends it only to the exact configured origin (or https://codeberg.org if FORGEJO_HOST is unset).

export FORGEJO_HOST=https://forge.example.org
leaf pr https://forge.example.org/owner/repo/pulls/12
leaf pr https://forge.example.org/owner/repo/issues/7
leaf diff https://forge.example.org/owner/repo/pulls/12

leaf diff and the Code tab try fj first, then the Forgejo API. fj can use its own login to fetch a diff, but the PR and issue pages use the API and don't read fj's login.

Whiteboard

leaf board [file.excalidraw]

An Excalidraw-compatible board in the terminal. @ asks your agent, which draws by editing the file; its changes appear live. E exports SVG and PNG. In Rex, Leaf: Open Whiteboard in the command palette starts one in the pane's folder.

Margin: review your agent's plans and changes

leaf agent setup           # install skills and plan hooks for agents found here
leaf plan plan.md
leaf review --branch

Your agent hands you a plan or a diff, you leave notes on lines, blocks or files, and S sends one review back as its next message. Hooks are installed for Claude Code, Codex, Cursor, Grok Build, Antigravity and Pi; OpenCode uses the skills. When an agent opens a review it appears in a pane beside it (needs Rex, tmux or Herdr).

Rex

leaf rex install

Adds Leaf to Rex's command palette (cmd+shift+p): open documents, review diffs, browse PRs, pick an agent and control reading aloud. Remote sessions work too.

Open Browser (or leaf browser [url]) opens a WebKit browser in a pane, macOS 13+. Its start page lists local dev servers. The browser runs off screen and the terminal draws it with Kitty graphics, bar, dialogs and all, so the pane is the browser: it shows on iPhone and iPad in Rex too, and stays put through Mission Control and session switches. Only rows of the pane the terminal hasn't seen are sent, so a scroll sends the rows that come into view. It also works in Ghostty, kitty and WezTerm, outside tmux.

Click, scroll, type and paste as in Safari. The browser's cmd shortcuts work when the terminal passes cmd on: cmd+l address, cmd+r reload, cmd+[ and cmd+] back and forward, cmd+f find, cmd+=, cmd+- and cmd+0 zoom, shift+cmd+c point, cmd+w close. For the cmd keys a terminal keeps for itself, and terminals that don't report cmd:

Key Does
ctrl+l type an address, localhost:3000 or search words
ctrl+r reload
alt+left, alt+right back, forward
ctrl+f find on the page
alt+p point at part of the page to ask your agent about it
alt+a, alt+c, alt+x, alt+z select all, copy, cut, undo
alt+=, alt+-, alt+0 zoom
ctrl+q, ctrl+c close

Change these under [keys.browser]. Copying puts the text on the clipboard of the device you're on, phone included. <select> menus and right-click menus open as lists over the page. A page's alerts, confirmations and prompts, and its requests to upload files, open as dialogs in the pane; uploads take a path on the Mac.

To point at UI, press alt+p (or the pointer button in the bar), click elements with React Grab, type a question in the card at the bottom and press enter. It goes to your agent.

leaf browser --overlay [url] opens the earlier browser instead: a native window floating over the Rex pane, on the Mac only. Minimal Address Bar in the palette hides its address strip.

A blank browser pane? Run it with a log and attach the file to an issue: LEAF_BROWSER_LOG=/tmp/leaf-browser.log leaf browser https://example.com. The log records what leaf found out about the terminal, the size it asked for, how the page was captured, and which frames were sent and drawn. Runs are appended to the same file.

Open Simulator… in Rex opens an installed simulator on a 3D phone in a pane on macOS 13 or later. Open Android Simulator skips the picker and opens your Android emulator, a booted one first. Run leaf sim install or pick Install Simulator… in Rex, then choose iPhone (iOS) or Android to download that platform's models and enable the pane. For scripts, use leaf sim install --platform ios --yes or leaf sim install --platform android --yes.

  • iOS uses Xcode and lists the iPhone Duo, iPhone 18 Pro Max and iPhone 17 Pro Max. Press cmd+f to fold or open the Duo.
  • Android uses Android Emulator and SDK Platform-Tools. Install both in Android Studio's SDK Manager and create a phone in Device Manager. Set ANDROID_HOME if your SDK is outside ~/Library/Android/sdk and its tools are outside your PATH. Leaf draws the emulator on a Galaxy S26 Ultra. Leaf streams the display from the emulator's local gRPC service, which it turns on with a token when it starts the emulator. An emulator started elsewhere without gRPC falls back to ADB screen capture, at a few frames a second. ADB handles input on both.

Run leaf sim list to find a device ID, then leaf sim open <id> in a Rex pane. Android IDs start with android-. Leaf starts an Android emulator without a separate window. Closing the pane stops the emulator, including one that was already running.

Agents use leaf sim snapshot to read accessibility elements and leaf sim tap @e3, fill, scroll, wait and launch to drive either platform. The same commands also work on a booted device outside Rex. See leaf sim help and the leaf-sim skill.

3D models

Run leaf open model.glb in a Kitty graphics terminal such as Ghostty or kitty outside tmux. It works on Linux and macOS 13 or later. On macOS, the same command also works in a local Rex pane, and Rex lists models under Leaf: Open Document…. Drag or use the arrow keys to orbit, shift-drag to pan, and scroll or press + / - to zoom. Press 0 to fit the model, w to toggle wireframe, and esc to return to the shell.

The bundled Assimp importer reads GLB, glTF, FBX, OBJ, STL, PLY, 3MF, and other formats. Linux draws static triangle meshes with material colors and base-color textures in software. On macOS, Leaf also uses the system importers for formats such as USDZ, Alembic, and SceneKit files. Keep textures and other sidecar files with the model. Use leaf open --model FILE for ambiguous or extensionless files.

With Amber

With Amber installed, add Leaf to your Rex config instead:

local amber = dofile(os.getenv("HOME") .. "/.local/share/rex/amber/amber.lua")

amber.setup({
  plugins = {
    {
      "DeepanshuMishraa/leaf",
      main = "leaf",
      -- Installs the leaf release matching this checkout, like the install script above.
      build = [[LEAF_VERSION=$(awk -F'"' '/^version/ {print $2; exit}' Cargo.toml) sh site/public/install.sh]],
    },
  },
})

Run amber install: it clones the plugin, installs the matching leaf command and reloads Rex. amber update keeps both in step. Loading the config alone does not install.

  • Already ran leaf rex install? Run leaf rex uninstall first, or the palette lists Leaf twice.
  • Installed leaf with Homebrew? Leave out build and update it with brew upgrade.
  • leaf not on the default path (~/.local/bin, ~/.cargo/bin, Homebrew)? Pass its location: opts = { bin = { "/path/to/leaf" } }.

Development

cargo test
cargo clippy

To release: bump version in Cargo.toml, package.nix and the ver badge in site/public/index.html, add notes to CHANGELOG.md (the tests require them), run cargo check, commit, and push a matching tag (git tag v0.12.0 && git push origin v0.12.0). The workflow builds all four targets, publishes the release and updates the Homebrew tap. The site deploys with cd site && wrangler deploy.

استكشف مشاريع مشابهة ومرتبطة

جارٍ التحميل…