# file-icons A Files panel for Herdr. It lists the folder of the terminal you are working in, as a tree you open one folder at a time. Every file and folder has a coloured icon from VS Code's Material Icon Theme: a TypeScript file, a `package.json`, a `.github` folder, a `src` folder all look different. Changed files carry a small git letter. Click a file and its text opens in place, with syntax colours. The same icons are the set that the `filetree` mod draws from. ![file-icons](preview.png) ## What you see One rounded card that fills its block. It has two parts, top to bottom. - **Card.** Background `theme().background` (Nightfall: `#212121`), 1px border `theme().border` (`#2a2a2a`), corner radius 10px, text `theme().foreground` (`#c4c4c4`), base text 13px. Nothing spills outside the corners. - **Header.** 42px high, 14px side padding, 8px between items, 1px line under it in `border`. Left: the word "Files" in semibold 13px. Right, pushed to the end, 12px text in `theme().dim` (`#8f8f8f`), cut with an ellipsis when long: the name of the root folder (last path segment of the focused terminal's folder). While a file is open, the right side shows that file's icon (14px) and its path from the root instead, and a "←" (20px wide, `theme().muted`) appears before "Files". - **Tree** (shown when no file is open). Scrolls vertically with a scrollbar, 6px padding. Each row is 28px high, with 8px left padding plus 18px per level of depth, 8px right padding, 7px gap between items, corner radius 7px. A row holds, left to right: - a 12px chevron for folders (right when closed, down when open, tinted `dim`), or an empty 12px space for files so names line up; - a 16px icon; - the name, 13px, taking the rest of the width, cut with an ellipsis; - for changed files only, one letter at 11px: `A` in `theme().ansi2` (green), `D` or `U` in `theme().ansi1` (red), `M` in `theme().blocked`. Folders come first, then files; each group is sorted by name with `localeCompare`. The `.git` folder is never listed. - **Notes under the rows,** 12px `dim`, 8px padding: the error text, "Loading files…" (first load), "No files" (empty folder) or "No folder" (no folder known). When a limit was hit, an 11px line: "File list limited to 500 entries per folder and 5,000 total". - **Preview** (replaces the tree when a file is open). A read-only code view with line numbers, filling the rest of the card, font size 12 in the user's terminal font (`settings().font_family`). While loading or when it fails, a 12px padded line in `dim` shows the message instead. Syntax colours come from the theme: keyword `ansi5`, string `ansi2`, comment `dim`, function `ansi4`, type `ansi3`, number `ansi1`, constant `ansi6`. Light themes get the light variants of the icons; dark themes get the normal ones. ## How it behaves - **Which folder.** The folder of the focused pane (`cwd`). If a terminal block is focused, its `cwd`. Else the active space's folder. On another machine, it lists that machine's folder. When the folder or machine changes, the whole panel resets: open folders close, the preview closes, git marks clear, and it loads again. - **Open and close folders.** Click a folder row to open it. Its children load then, and appear one level deeper. Click again to close it; this also forgets all open folders below it, so opening it again reloads them. - **Preview.** Click a file row. The tree is replaced by the file's text. Click "←" in the header to go back; the tree comes back with the same folders open. - Text longer than 400,000 characters is cut there and a line `… (file truncated)` is added. - A file with a NUL character shows "Binary file · no text preview". - A file that vanished shows "This file is no longer available". - A read error shows "Cannot preview this file (binary, too large, or unreadable)". - The preview does not reload when the file changes on disk. Go back and click again. - **Language.** The file extension picks the highlighter. These are mapped first: `ts`, `tsx`, `mts`, `cts`, `jsx`, `mjs` to `js`; `toml` to `yaml`; `jsonc` to `json`; `svelte`, `vue` to `html`. Other extensions are used as they are. A name without a dot uses `txt`. - **Git marks.** After each load it runs git in the folder. In a repo, each changed or untracked file gets a letter: `A` for untracked (`??`) or any status with `A`; else `U` if the status has `U`; else `D` if it has `D`; else `M`. Only files get letters. Folders never do. Outside a repo, nothing is marked. - **Hover.** A row's background becomes `theme().hover` and the pointer becomes a hand. Nothing else reacts to hover. - **Keys.** None. The panel handles no keyboard input and has no commands. - **Refresh.** Every 10 seconds. For a folder on this computer it also refreshes when something under the root changes. For a space on another machine only the 10-second timer runs. A refresh reloads the root and every open folder, and the git marks. Only one refresh runs at a time. A failed load shows its error text under the rows; it clears on the next good refresh. - **Icons.** See Built from for the rules. The folder icon switches to its "open" variant while the folder is open. ## Built from **Folder.** `mods/file-icons/`. The mod must live in a folder with exactly this name: the icon paths are the fixed string `mods/file-icons/icons/.svg`, relative to the Herdr home. **`mod.json`:** ```json { "place": "none" } ``` It does not appear anywhere until a layout shows it, for example `{ "id": "files", "type": "block", "content": { "mod": "file-icons" } }`. It takes no props. It is a port of Herdr's own `files` mod (Apache-2.0, https://github.com/herdrdev/herdr-app) with the icons, the 28px rows and the preview-header icon added. **`main.js`** default-exports `class Files extends View`. Imports: - `gpui-kit`: `View`, `div`, `svg`, `image` - `gpui-base`: `v_flex`, `h_flex`, `Editor`, `EditorState` - `herdr`: `spaces`, `panes`, `focused`, `exec`, `readTextFile`, `watchFolder`, `theme`, `settings`, `window` - `./icons.js` (default export, the icon tables) **Herdr calls.** - `focused()`, `panes()`, `spaces()` find the folder: pane `cwd`, else focused `cwd`, else active space `folder`. The machine is `space.machine`, or the part before `/` in the focused terminal address when a terminal block is focused. `render` compares this against the last one and resets when it changed. - `exec` runs programs (below). `readTextFile(path, { on })` reads a file for the preview. `watchFolder(root)` loops: await a change, refresh. If it throws, watching stops until the next refresh. - `theme()` for colours, `settings().font_family`, `settings().dark` (picks light or dark icons), `window().platform` (`"windows"` switches the folder listing). - `cx.timer.every(10000, …)` for the refresh. `cx.spawn` for async work. No `run` commands. - Always use the `cx` a callback receives; never keep one. **Programs it runs (through `exec`, in the user's real environment, on the space's machine when it is remote).** 1. Folder listing, Unix or remote: `sh -c