返回 CodeWhale
recipes.ts
根目录 / web / lib / ratatui / recipes.ts
1 import recipes from "./recipes.generated.json";
2
3 const REPOSITORY = "https://github.com/codewhale-hq/codewhale-ratatui";
4
5 /** Exact public functions exported from the library's compiled recipes example. */
6 export function getRecipe(id?: string): { code: string; line: number } | null {
7 if (!id || !Object.prototype.hasOwnProperty.call(recipes.recipes, id)) return null;
8 return recipes.recipes[id as keyof typeof recipes.recipes];
9 }
10
11 export function recipeSourceUrl(line: number) {
12 return `${REPOSITORY}/blob/${recipes.sourceRevision}/examples/recipes.rs#L${line}`;
13 }
14
15 export function learningGuideUrl(anchor?: string) {
16 return `${REPOSITORY}/blob/${recipes.sourceRevision}/GETTING-STARTED.md${anchor ? `#${anchor}` : ""}`;
17 }
18
19 export const STARTER_SOURCE = `${REPOSITORY}/blob/${recipes.sourceRevision}/examples/starter.rs`;
20 export const RECIPE_SOURCE = `${REPOSITORY}/blob/${recipes.sourceRevision}/examples/recipes.rs`;
21 export const INSTALL = `[dependencies]
22 codewhale-ratatui = { git = "${REPOSITORY}", rev = "${recipes.sourceRevision}" }
23 ratatui = { version = "0.30.2", default-features = false, features = ["std", "crossterm_0_29"] }
24 crossterm = "0.29"`;
25
26 export const TRY_STARTER = `git clone ${REPOSITORY}
27 cd codewhale-ratatui
28 cargo run --locked --example starter`;
29
29 lines TYPESCRIPT