| /* eslint-disable no-console */ | ||
| import * as React from "react"; | ||
| import clipboard from "clipboardy"; | ||
| import * as Ink from "ink"; | ||
@@ -39,2 +40,4 @@ import OpenAI from "openai"; | ||
| const command = chunk_list.join(""); | ||
| const [copied, set_copied] = React.useState(false); | ||
| const [output, set_output] = React.useState(""); | ||
| return (React.createElement(Ink.Box, { flexDirection: "column" }, | ||
@@ -44,10 +47,23 @@ React.createElement(Ink.Text, { bold: true }, | ||
| command), | ||
| !done ? null : (React.createElement(YesNoPrompt, { message: " Run?", onNo: onNo, onYes: onYes })))); | ||
| !done ? null : (React.createElement(YesNoPrompt, { message: " Run?", onNo: onNo, onYes: onYes })), | ||
| !output ? null : (React.createElement(React.Fragment, null, | ||
| React.createElement(Ink.Box, { height: 1 }), | ||
| React.createElement(Ink.Text, null, output))), | ||
| !copied ? null : (React.createElement(React.Fragment, null, | ||
| React.createElement(Ink.Box, { height: 1 }), | ||
| React.createElement(Ink.Text, { dimColor: true }, "Command copied to clipboard."))))); | ||
| function onNo() { | ||
| handle_clipboard(); | ||
| actions.exit(0, false); | ||
| } | ||
| async function onYes() { | ||
| await cli(command, { stdio: "inherit" }); | ||
| const result = await cli(command); | ||
| set_output(result.output); | ||
| handle_clipboard(); | ||
| actions.exit(0, false); | ||
| } | ||
| function handle_clipboard() { | ||
| clipboard.writeSync(command); | ||
| set_copied(true); | ||
| } | ||
| } | ||
@@ -54,0 +70,0 @@ async function command_completion(args) { |
@@ -5,4 +5,6 @@ import * as React from "react"; | ||
| export function YesNoPrompt(props) { | ||
| const [answer, set_answer] = React.useState(""); | ||
| Ink.useInput((input) => { | ||
| const inputLower = input.toLowerCase(); | ||
| set_answer(inputLower); | ||
| switch (inputLower) { | ||
@@ -21,5 +23,5 @@ case "n": | ||
| React.createElement(Ink.Text, { color: "gray" }, | ||
| React.createElement(Ink.Text, { bold: true, color: "#22c55e" }, "Y"), | ||
| "/", | ||
| React.createElement(Ink.Text, { color: "#ef4444" }, "n")))))); | ||
| answer && answer !== "y" ? null : (React.createElement(Ink.Text, { bold: true, color: "#22c55e" }, "Y")), | ||
| answer ? null : React.createElement(Ink.Text, null, "/"), | ||
| answer && answer !== "n" ? null : (React.createElement(Ink.Text, { color: "#ef4444" }, "n"))))))); | ||
| } |
+6
-4
@@ -10,8 +10,10 @@ import * as child from "node:child_process"; | ||
| childProcess.stdout?.on("data", (data) => { | ||
| stdout += data.toString(); | ||
| output += data.toString(); | ||
| const str = String(data); | ||
| stdout += str; | ||
| output += str; | ||
| }); | ||
| childProcess.stderr?.on("data", (data) => { | ||
| stderr += data.toString(); | ||
| output += data.toString(); | ||
| const str = String(data); | ||
| stderr += str; | ||
| output += str; | ||
| }); | ||
@@ -18,0 +20,0 @@ childProcess.on("close", (code) => { |
+2
-1
| { | ||
| "name": "hakase", | ||
| "version": "0.2.0", | ||
| "version": "0.3.0", | ||
| "description": "", | ||
@@ -24,2 +24,3 @@ "author": "magus", | ||
| "dependencies": { | ||
| "clipboardy": "^4.0.0", | ||
| "immer": "^10.0.3", | ||
@@ -26,0 +27,0 @@ "ink": "^4.4.1", |
20790
5.08%587
3.53%7
16.67%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added