6615
Yc
yoctoselect / files
yoctoselect / examples / demo.ts
1.9 KB
1import * as c from "yoctocolors"; 2import { select } from "../src/index.ts"; 3 4async function main() { 5 console.log("=== Simple string items ==="); 6 const fruit = await select({ 7 items: [ 8 "apple", 9 "apricot", 10 "banana", 11 "blueberry", 12 "cherry", 13 "date", 14 "elderberry", 15 "fig", 16 "grape", 17 ], 18 }); 19 console.log(`Selected: ${fruit}`); 20 21 console.log("\n=== Rich items with ANSI colors ==="); 22 const model = await select({ 23 items: [ 24 { 25 label: `claude-sonnet-4 ${c.green("free")} ${c.dim("200k")}`, 26 value: "anthropic/claude-sonnet-4", 27 filterText: "anthropic/claude-sonnet-4 claude-sonnet-4", 28 }, 29 { 30 label: `claude-haiku-3 ${c.dim("200k")}`, 31 value: "anthropic/claude-haiku-3", 32 filterText: "anthropic/claude-haiku-3 claude-haiku-3", 33 }, 34 { 35 label: `gpt-4o ${c.dim("128k")}`, 36 value: "openai/gpt-4o", 37 filterText: "openai/gpt-4o gpt-4o", 38 }, 39 { 40 label: `gemini-2.5-pro ${c.dim("1M")}`, 41 value: "google/gemini-2.5-pro", 42 filterText: "google/gemini-2.5-pro gemini-2.5-pro", 43 }, 44 ], 45 placeholder: "search models...", 46 }); 47 console.log(`Selected model: ${model}`); 48 49 console.log("\n=== Scrollable list browsing ==="); 50 console.log( 51 c.dim(" Use ↑/↓ to scroll through all 50 items, Home/End to jump\n"), 52 ); 53 const colors = [ 54 "red", 55 "orange", 56 "yellow", 57 "green", 58 "blue", 59 "indigo", 60 "violet", 61 ]; 62 const items = Array.from({ length: 50 }, (_, i) => { 63 const color = colors[i % colors.length] as string; 64 return { 65 label: `${color}-${String(i + 1).padStart(2, "0")} ${c.dim(`shade ${i + 1}`)}`, 66 value: `${color}-${i + 1}`, 67 filterText: `${color} ${i + 1}`, 68 }; 69 }); 70 const item = await select({ 71 items, 72 maxVisible: 8, 73 placeholder: "browse or type to filter...", 74 }); 75 console.log(`Selected: ${item}`); 76} 77 78main();