github-search-cli 9.4.1 → 9.4.3
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/CHANGELOG.md +65 -1
- package/README.md +268 -237
- package/bin/ghfind.js +98 -89
- package/completions/ghfind.bash +1 -1
- package/completions/ghfind.fish +3 -1
- package/completions/ghfind.zsh +6 -0
- package/dist/{chunk-IVUU2KGR.js → chunk-GYIL4S5X.js} +4 -1
- package/dist/cli.js +1179 -403
- package/dist/{config-GNZOQRTH.js → config-OCIPF2IF.js} +1 -1
- package/package.json +16 -5
- package/release-notes/9.3.0.md +32 -29
- package/scripts/build.ts +34 -19
- package/scripts/generate-svg-demo.js +218 -168
- package/scripts/postinstall.js +176 -176
- package/src/bookmarks.ts +69 -69
- package/src/cli.ts +650 -566
- package/src/compare.ts +69 -47
- package/src/config.ts +70 -65
- package/src/deepdive.ts +149 -118
- package/src/doctor.ts +287 -287
- package/src/error-report.ts +8 -12
- package/src/errors.ts +62 -59
- package/src/explore.ts +34 -29
- package/src/export.ts +73 -63
- package/src/help.ts +157 -157
- package/src/history.ts +69 -55
- package/src/init.ts +60 -55
- package/src/landing.ts +106 -104
- package/src/login.ts +186 -0
- package/src/markdown-render.ts +1 -6
- package/src/notifications.ts +75 -59
- package/src/open-url.ts +16 -16
- package/src/org.ts +299 -0
- package/src/output.ts +153 -137
- package/src/package-browser.ts +317 -305
- package/src/package.ts +149 -137
- package/src/pipe.ts +60 -54
- package/src/releases.ts +182 -144
- package/src/saved-searches.ts +72 -50
- package/src/search-state.ts +283 -229
- package/src/search.ts +678 -653
- package/src/session.ts +26 -24
- package/src/share.ts +61 -54
- package/src/status.ts +68 -61
- package/src/storage.ts +136 -106
- package/src/themes.ts +259 -116
- package/src/tips.ts +42 -42
- package/src/toast.ts +70 -69
- package/src/trending-parser.ts +104 -0
- package/src/trending.ts +481 -462
- package/src/tui.ts +3015 -2867
- package/src/types.ts +160 -158
- package/src/update-check.ts +231 -215
- package/src/version.ts +33 -0
- package/src/watch.ts +95 -74
package/src/search-state.ts
CHANGED
|
@@ -1,229 +1,283 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SearchState — owns all TUI state and domain calls.
|
|
3
|
-
*
|
|
4
|
-
* The TUI view layer reads from SearchState and dispatches actions.
|
|
5
|
-
* This module is testable without the OpenTUI renderer.
|
|
6
|
-
*/
|
|
7
|
-
import type { Repo, SearchOptions, SortStrategy, SessionState } from "./types";
|
|
8
|
-
import type { TabName } from "./trending";
|
|
9
|
-
import { tabSince } from "./trending";
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
this.state.
|
|
100
|
-
this.state.
|
|
101
|
-
this.state.
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
this.state.
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
1
|
+
/**
|
|
2
|
+
* SearchState — owns all TUI state and domain calls.
|
|
3
|
+
*
|
|
4
|
+
* The TUI view layer reads from SearchState and dispatches actions.
|
|
5
|
+
* This module is testable without the OpenTUI renderer.
|
|
6
|
+
*/
|
|
7
|
+
import type { Repo, SearchOptions, SortStrategy, SessionState } from "./types";
|
|
8
|
+
import type { TabName } from "./trending";
|
|
9
|
+
import { tabSince } from "./trending";
|
|
10
|
+
import {
|
|
11
|
+
parseQuery,
|
|
12
|
+
applyFlagFilters,
|
|
13
|
+
rankRepos,
|
|
14
|
+
createGitHubSearch,
|
|
15
|
+
SearchModule,
|
|
16
|
+
TrendingAdapter,
|
|
17
|
+
} from "./search";
|
|
18
|
+
import { restoreSession, saveSession } from "./session";
|
|
19
|
+
import { appendHistory } from "./history";
|
|
20
|
+
import { toggleBookmark, isBookmarked } from "./bookmarks";
|
|
21
|
+
import {
|
|
22
|
+
saveSearch,
|
|
23
|
+
getSavedSearches,
|
|
24
|
+
touchSavedSearch,
|
|
25
|
+
} from "./saved-searches";
|
|
26
|
+
import { fetchDeepDive, buildDeepDiveText } from "./deepdive";
|
|
27
|
+
import { fetchTopics } from "./explore";
|
|
28
|
+
import { loadConfig } from "./config";
|
|
29
|
+
|
|
30
|
+
export type Overlay =
|
|
31
|
+
| "none"
|
|
32
|
+
| "history"
|
|
33
|
+
| "bookmarks"
|
|
34
|
+
| "saved"
|
|
35
|
+
| "help"
|
|
36
|
+
| "topics"
|
|
37
|
+
| "export"
|
|
38
|
+
| "compare"
|
|
39
|
+
| "notifications"
|
|
40
|
+
| "share"
|
|
41
|
+
| "leader"
|
|
42
|
+
| "readme";
|
|
43
|
+
|
|
44
|
+
export interface SearchState {
|
|
45
|
+
// Core search state
|
|
46
|
+
currentRepos: Repo[];
|
|
47
|
+
currentSort: SortStrategy;
|
|
48
|
+
currentLimit: number;
|
|
49
|
+
currentQueryInput: string;
|
|
50
|
+
isLoading: boolean;
|
|
51
|
+
currentMode: "search" | "trending";
|
|
52
|
+
currentPage: number;
|
|
53
|
+
totalCount: number;
|
|
54
|
+
|
|
55
|
+
// Trending
|
|
56
|
+
trendingTab: TabName;
|
|
57
|
+
trendingPeriod: string;
|
|
58
|
+
|
|
59
|
+
// UI overlays
|
|
60
|
+
currentOverlay: Overlay;
|
|
61
|
+
deepDiveActive: boolean;
|
|
62
|
+
compareList: Repo[];
|
|
63
|
+
graphFullscreen: boolean;
|
|
64
|
+
chartCommitData: number[];
|
|
65
|
+
quitArmed: boolean;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export class SearchStateManager {
|
|
69
|
+
private config = loadConfig();
|
|
70
|
+
private provider = createGitHubSearch(undefined, this.config.githubTokens);
|
|
71
|
+
private trendingSearch = new SearchModule(new TrendingAdapter());
|
|
72
|
+
|
|
73
|
+
state: SearchState = {
|
|
74
|
+
currentRepos: [],
|
|
75
|
+
currentSort: this.config.defaultSort,
|
|
76
|
+
currentLimit: this.config.defaultLimit,
|
|
77
|
+
currentQueryInput: "",
|
|
78
|
+
isLoading: false,
|
|
79
|
+
currentMode: "search",
|
|
80
|
+
currentPage: 1,
|
|
81
|
+
totalCount: 0,
|
|
82
|
+
trendingTab: "This Week",
|
|
83
|
+
trendingPeriod: "this week",
|
|
84
|
+
currentOverlay: "none",
|
|
85
|
+
deepDiveActive: false,
|
|
86
|
+
compareList: [],
|
|
87
|
+
graphFullscreen: false,
|
|
88
|
+
chartCommitData: [],
|
|
89
|
+
quitArmed: false,
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
constructor() {
|
|
93
|
+
const session = restoreSession();
|
|
94
|
+
if (session) {
|
|
95
|
+
// Only search/trending are restorable here; packages/bookmarks pages
|
|
96
|
+
// are re-entered interactively, so clamp anything else to "search".
|
|
97
|
+
this.state.currentMode =
|
|
98
|
+
session.mode === "trending" ? "trending" : "search";
|
|
99
|
+
this.state.currentQueryInput = session.query;
|
|
100
|
+
this.state.currentSort = session.sort;
|
|
101
|
+
this.state.currentLimit = session.limit;
|
|
102
|
+
this.state.trendingTab = (session.trendingTab as TabName) ?? "This Week";
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// ── Search ──
|
|
107
|
+
|
|
108
|
+
async search(query: string, page: number = 1): Promise<void> {
|
|
109
|
+
this.state.isLoading = true;
|
|
110
|
+
this.state.currentQueryInput = query;
|
|
111
|
+
this.state.currentPage = page;
|
|
112
|
+
try {
|
|
113
|
+
const parsed = applyFlagFilters(parseQuery(query), {});
|
|
114
|
+
const response = await this.provider.search(parsed, {
|
|
115
|
+
limit: this.state.currentLimit,
|
|
116
|
+
sort: this.state.currentSort,
|
|
117
|
+
json: false,
|
|
118
|
+
verbose: false,
|
|
119
|
+
token: this.config.githubToken,
|
|
120
|
+
page,
|
|
121
|
+
});
|
|
122
|
+
this.state.currentRepos = rankRepos(
|
|
123
|
+
response.repos,
|
|
124
|
+
this.state.currentSort,
|
|
125
|
+
);
|
|
126
|
+
this.state.totalCount = response.totalCount;
|
|
127
|
+
this.state.currentMode = "search";
|
|
128
|
+
appendHistory({
|
|
129
|
+
query,
|
|
130
|
+
mode: "search",
|
|
131
|
+
timestamp: Date.now(),
|
|
132
|
+
resultCount: response.repos.length,
|
|
133
|
+
});
|
|
134
|
+
} catch (err) {
|
|
135
|
+
throw err;
|
|
136
|
+
} finally {
|
|
137
|
+
this.state.isLoading = false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async nextPage(): Promise<void> {
|
|
142
|
+
await this.search(this.state.currentQueryInput, this.state.currentPage + 1);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async prevPage(): Promise<void> {
|
|
146
|
+
if (this.state.currentPage > 1) {
|
|
147
|
+
await this.search(
|
|
148
|
+
this.state.currentQueryInput,
|
|
149
|
+
this.state.currentPage - 1,
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// ── Trending ──
|
|
155
|
+
|
|
156
|
+
async loadTrending(tab: TabName): Promise<void> {
|
|
157
|
+
this.state.isLoading = true;
|
|
158
|
+
this.state.trendingTab = tab;
|
|
159
|
+
this.state.currentMode = "trending";
|
|
160
|
+
try {
|
|
161
|
+
const response = await this.trendingSearch.search(
|
|
162
|
+
{ keywords: [], qualifiers: [], raw: "trending" },
|
|
163
|
+
{
|
|
164
|
+
limit: 25,
|
|
165
|
+
sort: "stars",
|
|
166
|
+
json: false,
|
|
167
|
+
verbose: false,
|
|
168
|
+
trendingSince: tabSince(tab),
|
|
169
|
+
},
|
|
170
|
+
);
|
|
171
|
+
this.state.currentRepos = response.repos;
|
|
172
|
+
this.state.totalCount = response.totalCount;
|
|
173
|
+
appendHistory({
|
|
174
|
+
query: `trending:${tab}`,
|
|
175
|
+
mode: "trending",
|
|
176
|
+
tab,
|
|
177
|
+
timestamp: Date.now(),
|
|
178
|
+
resultCount: response.repos.length,
|
|
179
|
+
});
|
|
180
|
+
} finally {
|
|
181
|
+
this.state.isLoading = false;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// ── Bookmarks ──
|
|
186
|
+
|
|
187
|
+
toggleBookmark(repo: Repo): boolean {
|
|
188
|
+
return toggleBookmark(repo);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
isBookmarked(fullName: string): boolean {
|
|
192
|
+
return isBookmarked(fullName);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// ── Saved searches ──
|
|
196
|
+
|
|
197
|
+
saveCurrentSearch(name: string): void {
|
|
198
|
+
saveSearch(
|
|
199
|
+
name,
|
|
200
|
+
this.state.currentQueryInput,
|
|
201
|
+
this.state.currentMode,
|
|
202
|
+
this.state.currentSort,
|
|
203
|
+
this.state.currentLimit,
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
getSavedSearches() {
|
|
208
|
+
return getSavedSearches();
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
touchSavedSearch(name: string): void {
|
|
212
|
+
touchSavedSearch(name);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// ── Deep dive ──
|
|
216
|
+
|
|
217
|
+
async deepDive(repo: Repo): Promise<string> {
|
|
218
|
+
this.state.deepDiveActive = true;
|
|
219
|
+
try {
|
|
220
|
+
const data = await fetchDeepDive(repo, this.config.githubToken);
|
|
221
|
+
return buildDeepDiveText(data);
|
|
222
|
+
} finally {
|
|
223
|
+
this.state.deepDiveActive = false;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// ── Compare ──
|
|
228
|
+
|
|
229
|
+
addToCompare(repo: Repo): void {
|
|
230
|
+
if (!this.state.compareList.some((r) => r.fullName === repo.fullName)) {
|
|
231
|
+
this.state.compareList.push(repo);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
removeFromCompare(fullName: string): void {
|
|
236
|
+
this.state.compareList = this.state.compareList.filter(
|
|
237
|
+
(r) => r.fullName !== fullName,
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
clearCompare(): void {
|
|
242
|
+
this.state.compareList = [];
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// ── Session ──
|
|
246
|
+
|
|
247
|
+
saveSession(): void {
|
|
248
|
+
const s: SessionState = {
|
|
249
|
+
mode: this.state.currentMode,
|
|
250
|
+
query: this.state.currentQueryInput,
|
|
251
|
+
sort: this.state.currentSort,
|
|
252
|
+
limit: this.state.currentLimit,
|
|
253
|
+
trendingTab: this.state.trendingTab,
|
|
254
|
+
};
|
|
255
|
+
saveSession(s);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// ── Setters ──
|
|
259
|
+
|
|
260
|
+
setSort(sort: SortStrategy): void {
|
|
261
|
+
this.state.currentSort = sort;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
setLimit(limit: number): void {
|
|
265
|
+
this.state.currentLimit = limit;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
setOverlay(overlay: Overlay): void {
|
|
269
|
+
this.state.currentOverlay = overlay;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
setGraphFullscreen(fullscreen: boolean): void {
|
|
273
|
+
this.state.graphFullscreen = fullscreen;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
setChartCommitData(data: number[]): void {
|
|
277
|
+
this.state.chartCommitData = data;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
setQuitArmed(armed: boolean): void {
|
|
281
|
+
this.state.quitArmed = armed;
|
|
282
|
+
}
|
|
283
|
+
}
|