-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gemi command to run gemini prompt/chat from cmd line
- Loading branch information
Showing
2 changed files
with
42 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,20 +2,53 @@ | |
// cat README.md | deno run --allow-env --allow-read --allow-run bin/render-streaming-markdown.ts | ||
// | ||
|
||
import $ from "jsr:@david/[email protected]" | ||
import $ from 'jsr:@david/[email protected]' | ||
// todo: replace dax with this: | ||
// import { exec } from 'https://deno.land/std/process.mod.ts'; | ||
import { writeAllSync } from 'https://deno.land/[email protected]/streams/mod.ts'; | ||
|
||
let inputBuffer = "" | ||
|
||
const decoder = new TextDecoder() | ||
const encoder = new TextEncoder() | ||
|
||
// This style works well for prompt.. but not chat | ||
for await (const chunk of Deno.stdin.readable) { | ||
const decoded = decoder.decode(chunk); | ||
inputBuffer += decoded | ||
// console.log("$$$$$$$$$$", decoder.decode(chunk), "$$$zzz$$$") | ||
// show immediately, but meanwhile… | ||
writeAllSync(Deno.stdout, chunk); | ||
// Collect it. | ||
inputBuffer += decoder.decode(chunk); | ||
} | ||
|
||
// --style auto is there to force it to output styled https://github.com/charmbracelet/glow/blob/2430b0a/main.go#L158 | ||
const output = await $`glow --style auto`.stdinText(decoded).text() | ||
// and now re-render it. | ||
if (inputBuffer) { | ||
console.log('⬇️… and now rendered…⬇️'); | ||
const output = await $`glow --style auto`.stdinText(inputBuffer).text() | ||
writeAllSync(Deno.stdout, encoder.encode(output)); | ||
} | ||
|
||
|
||
// This is a newline-buffered variant to avoid getting extra newlines in the output because we send it to glow too eagerly | ||
// it works but... the next problem is backtick codeblocks are broken up and... i'm sure there's more. | ||
// definitely need a better solution | ||
|
||
// let remainingContent = ''; | ||
// for await (const chunk of Deno.stdin.readable) { | ||
// const decoded = remainingContent + decoder.decode(chunk); | ||
|
||
// const lastNewline = decoded.lastIndexOf("\n"); | ||
// if (lastNewline !== -1) { | ||
// // Flush everything up to it | ||
// const output = await $`glow --style auto`.stdinText(decoded.substring(0, lastNewline + 1)).text() | ||
// writeAllSync(Deno.stdout, encoder.encode(output)); | ||
|
||
// // Hold onto the remaining content to flush with the next chunk | ||
// remainingContent = decoded.substring(lastNewline + 1); | ||
// } | ||
// } | ||
|
||
// // Flush any remaining content | ||
// if (remainingContent) { | ||
// const output = await $`glow --style auto`.stdinText(remainingContent).text() | ||
// writeAllSync(Deno.stdout, encoder.encode(output)); | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters