@ahmd-sh/hntui 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +171 -0
- package/package.json +59 -0
- package/src/App.tsx +629 -0
- package/src/api/hn.test.ts +84 -0
- package/src/api/hn.ts +200 -0
- package/src/api/hnDemo.ts +70 -0
- package/src/api/types.ts +40 -0
- package/src/components/CommentNode.tsx +81 -0
- package/src/components/ContextMenu.tsx +78 -0
- package/src/components/Header.tsx +89 -0
- package/src/components/HelpOverlay.tsx +133 -0
- package/src/components/LinksPopup.tsx +101 -0
- package/src/components/Loader.tsx +30 -0
- package/src/components/StatusBar.tsx +40 -0
- package/src/components/StoryRow.tsx +76 -0
- package/src/hooks/useCommentTree.ts +95 -0
- package/src/hooks/useHistory.ts +40 -0
- package/src/hooks/useItems.ts +34 -0
- package/src/hooks/useSaved.ts +37 -0
- package/src/hooks/useStoryIds.ts +38 -0
- package/src/index.tsx +8 -0
- package/src/runtime.ts +12 -0
- package/src/spinner.ts +243 -0
- package/src/theme.ts +131 -0
- package/src/utils/configDir.ts +22 -0
- package/src/utils/errors.test.ts +21 -0
- package/src/utils/errors.ts +13 -0
- package/src/utils/format.test.ts +56 -0
- package/src/utils/format.ts +97 -0
- package/src/utils/historyStore.ts +38 -0
- package/src/utils/openUrl.ts +10 -0
- package/src/utils/savedStore.ts +34 -0
- package/src/views/MessageView.tsx +34 -0
- package/src/views/StoryDetailView.tsx +116 -0
- package/src/views/StoryListView.tsx +83 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ahmed Shaikh
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# hntui
|
|
2
|
+
|
|
3
|
+
Hacker News in your terminal! (formerly published as `@ahmd-sh/hackernuis`)
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
curl -fsSL https://raw.githubusercontent.com/ahmd-sh/hntui/main/install.sh | sh
|
|
7
|
+
hntui
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## What it does
|
|
11
|
+
|
|
12
|
+
- Browse all six HN feeds: Top, New, Best, Ask, Show, and Jobs.
|
|
13
|
+
- Navigate through a post's comments.
|
|
14
|
+
- Save posts for later.
|
|
15
|
+
- Vim + mouse support.
|
|
16
|
+
- Themes.
|
|
17
|
+
- ... and a really cool Knight Rider scanner animation for loaders (◕ᴗ◕ )
|
|
18
|
+
|
|
19
|
+
## Requirements
|
|
20
|
+
|
|
21
|
+
Any modern terminal with truecolor, mouse support, and UTF-8 will work. I've tested it in Ghostty on MacOS. Linux/Windows is supported by OpenTUI but I haven't tried it (yet).
|
|
22
|
+
|
|
23
|
+
The prebuilt binaries have no dependencies. Installing through npm (or hacking on the code) needs [Bun](https://bun.sh) 1.2 or newer.
|
|
24
|
+
|
|
25
|
+
## Install
|
|
26
|
+
|
|
27
|
+
### Standalone binary (recommended)
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
curl -fsSL https://raw.githubusercontent.com/ahmd-sh/hntui/main/install.sh | sh
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Installs a self-contained binary (runtime included, nothing else needed) to `~/.local/bin`. You can also grab a binary for your platform directly from the [releases page](https://github.com/ahmd-sh/hntui/releases).
|
|
34
|
+
|
|
35
|
+
### With Bun
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
bun add -g @ahmd-sh/hntui
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Either way the command is `hntui`. Or run it once without installing:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
bunx @ahmd-sh/hntui
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Run
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
hntui
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Press `q` (or `Ctrl-C`) to quit.
|
|
54
|
+
|
|
55
|
+
## Keybindings
|
|
56
|
+
|
|
57
|
+
### Story list
|
|
58
|
+
|
|
59
|
+
| Key | Action |
|
|
60
|
+
|---|---|
|
|
61
|
+
| `j` / `↓`, `k` / `↑` | Move cursor |
|
|
62
|
+
| `gg`, `Shift-G` | Jump to first or last |
|
|
63
|
+
| `Ctrl-D`, `Ctrl-U`, `PgDown`, `PgUp` | Scroll a half page |
|
|
64
|
+
| `c`, `Enter` | Open the story and read its comments |
|
|
65
|
+
| `h` / `←`, `l` / `→` | Previous or next tab |
|
|
66
|
+
| `Tab`, `Shift-Tab` | Cycle through tabs |
|
|
67
|
+
| `1` through `6` | Jump to a specific category |
|
|
68
|
+
| `Shift-S` | Jump to the Saved list |
|
|
69
|
+
| `s` | Save or unsave the highlighted post |
|
|
70
|
+
| `o` | Open the story's URL in your browser |
|
|
71
|
+
| `r` | Refresh the current feed |
|
|
72
|
+
| `t` | Toggle theme |
|
|
73
|
+
| `q`, `Ctrl-C` | Quit |
|
|
74
|
+
|
|
75
|
+
### Story detail (comments)
|
|
76
|
+
|
|
77
|
+
| Key | Action |
|
|
78
|
+
|---|---|
|
|
79
|
+
| `j` / `↓`, `k` / `↑` | Move the comment cursor |
|
|
80
|
+
| `gg`, `Shift-G` | Jump to first or last comment |
|
|
81
|
+
| `Ctrl-D`, `Ctrl-U`, `PgDown`, `PgUp` | Scroll a half page |
|
|
82
|
+
| `Space` | Collapse or expand the current subtree |
|
|
83
|
+
| `Enter` | Open the links popup for the current comment |
|
|
84
|
+
| `s` | Save or unsave this story |
|
|
85
|
+
| `o` | Open the story's URL |
|
|
86
|
+
| `Esc`, `Backspace`, `h` / `←` | Back to the list |
|
|
87
|
+
| `t` | Toggle theme |
|
|
88
|
+
| `q` | Quit |
|
|
89
|
+
|
|
90
|
+
### Links popup
|
|
91
|
+
|
|
92
|
+
| Key | Action |
|
|
93
|
+
|---|---|
|
|
94
|
+
| `j`, `k`, `↑`, `↓` | Move |
|
|
95
|
+
| `gg`, `Shift-G` | First or last link |
|
|
96
|
+
| `o`, `Enter` | Open the highlighted link |
|
|
97
|
+
| `Esc`, `Backspace` | Close the popup |
|
|
98
|
+
|
|
99
|
+
### Context menu (right-click)
|
|
100
|
+
|
|
101
|
+
| Key | Action |
|
|
102
|
+
|---|---|
|
|
103
|
+
| `j` / `↓`, `k` / `↑` | Move |
|
|
104
|
+
| `Enter` | Activate |
|
|
105
|
+
| `Esc`, `Backspace` | Close |
|
|
106
|
+
|
|
107
|
+
### Mouse
|
|
108
|
+
|
|
109
|
+
Most things you can do with the keyboard, you can do with a mouse too.
|
|
110
|
+
|
|
111
|
+
- Click a tab to switch feeds.
|
|
112
|
+
- Click the `Y` tile to refresh the current feed (or to exit a story back to its list).
|
|
113
|
+
- Click any story row to select it. Click it again to open the comments.
|
|
114
|
+
- Right-click a story to open a context menu with Save, Open URL, and Open Comments.
|
|
115
|
+
- Click a comment's header line to collapse or expand its subtree.
|
|
116
|
+
- Double-click a comment's body to open its links popup.
|
|
117
|
+
- Click the story URL in the detail header to open it in your browser.
|
|
118
|
+
- Click outside a popup or context menu to dismiss it.
|
|
119
|
+
- Use your scroll wheel to scroll lists and comment trees.
|
|
120
|
+
|
|
121
|
+
### Selecting and copying text
|
|
122
|
+
|
|
123
|
+
Because the app captures mouse events, your terminal's normal click-and-drag selection is intercepted. To select text the regular way:
|
|
124
|
+
|
|
125
|
+
- On macOS (Terminal.app, iTerm2, WezTerm, Ghostty), hold `Option` while you drag, then `Cmd-C`.
|
|
126
|
+
- On Linux (Kitty, Alacritty, WezTerm, GNOME Terminal), hold `Shift` while you drag, then `Ctrl-Shift-C`.
|
|
127
|
+
|
|
128
|
+
## Themes
|
|
129
|
+
|
|
130
|
+
Press `t` to toggle. The dark theme is mostly black with orange accents. The light theme is faithful to news.ycombinator.com: white background, orange topbar, the familiar beige row highlight, and HN's classic grey byline text.
|
|
131
|
+
|
|
132
|
+
## Saved posts
|
|
133
|
+
|
|
134
|
+
Press `s` on any story to save it. Saved posts get a small star next to the title and show up in the Saved tab on the right side of the tab strip. The list persists across sessions in `~/.config/hntui/saved.json` as a small JSON file. (Config from the app's `hackernuis` days is migrated automatically on first run.) Press `s` again to remove a post from the list.
|
|
135
|
+
|
|
136
|
+
`Shift-S` jumps straight to the Saved list from anywhere.
|
|
137
|
+
|
|
138
|
+
## Development
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
git clone https://github.com/ahmd-sh/hntui.git
|
|
142
|
+
cd hntui
|
|
143
|
+
bun install
|
|
144
|
+
bun dev # hot reload
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Data comes from the public [Hacker News Firebase API](https://github.com/HackerNews/API).
|
|
148
|
+
|
|
149
|
+
## Releases
|
|
150
|
+
|
|
151
|
+
Pushing a `v*` tag triggers two workflows:
|
|
152
|
+
|
|
153
|
+
- `.github/workflows/release.yml` cross-compiles standalone binaries (`bun build --compile`) for macOS and Linux (arm64 and x64), smoke-tests the Linux build against the live API, and attaches the tarballs to a GitHub release. This is what `install.sh` downloads.
|
|
154
|
+
- `.github/workflows/publish.yml` publishes `@ahmd-sh/hntui` to npm via OIDC trusted publishing, with a [SLSA provenance attestation](https://slsa.dev/) linking the tarball back to the exact commit and workflow run that produced it. It skips gracefully if the version is already on npm.
|
|
155
|
+
|
|
156
|
+
To release a new version:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
npm version patch # or minor / major
|
|
160
|
+
git push --follow-tags
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Acknowledgments
|
|
164
|
+
|
|
165
|
+
- [OpenTUI](https://github.com/anomalyco/opentui) by Anomaly. The native TUI core that makes all of this possible.
|
|
166
|
+
- [opentui-spinner](https://github.com/msmps/opentui-spinner) by Matt Simpson. The Knight Rider loading scanner is adapted from `examples/knight-rider/utils.ts` (MIT).
|
|
167
|
+
- [Hacker News](https://news.ycombinator.com) for the content and the open API.
|
|
168
|
+
|
|
169
|
+
## License
|
|
170
|
+
|
|
171
|
+
[MIT](./LICENSE), Copyright (c) 2026 Ahmed Shaikh.
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ahmd-sh/hntui",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Beautiful Hacker News browser for the terminal, built on OpenTUI + React + Bun",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"module": "src/index.tsx",
|
|
7
|
+
"bin": {
|
|
8
|
+
"hntui": "./src/index.tsx"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"src",
|
|
12
|
+
"LICENSE",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
15
|
+
"keywords": [
|
|
16
|
+
"hackernews",
|
|
17
|
+
"hn",
|
|
18
|
+
"tui",
|
|
19
|
+
"terminal",
|
|
20
|
+
"cli",
|
|
21
|
+
"opentui",
|
|
22
|
+
"bun",
|
|
23
|
+
"hackernuis"
|
|
24
|
+
],
|
|
25
|
+
"author": "Ahmed Shaikh <ahmeds@mun.ca>",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"homepage": "https://github.com/ahmd-sh/hntui#readme",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/ahmd-sh/hntui.git"
|
|
31
|
+
},
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/ahmd-sh/hntui/issues"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"bun": ">=1.2.0"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"dev": "bun run --watch src/index.tsx",
|
|
43
|
+
"start": "bun run src/index.tsx"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@effect/language-service": "^0.87.1",
|
|
47
|
+
"@types/bun": "latest"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"typescript": "^5"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@opentui/core": "^0.1.103",
|
|
54
|
+
"@opentui/react": "^0.1.103",
|
|
55
|
+
"effect": "^3.21.4",
|
|
56
|
+
"opentui-spinner": "^0.0.6",
|
|
57
|
+
"react": "^19.2.4"
|
|
58
|
+
}
|
|
59
|
+
}
|