Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
refactor the internals of prompt rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
IMax153 committed Nov 30, 2023
1 parent 1512ce7 commit 6854f8e
Show file tree
Hide file tree
Showing 13 changed files with 883 additions and 1,012 deletions.
94 changes: 50 additions & 44 deletions examples/prompt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Command from "@effect/cli/Command"
import * as Prompt from "@effect/cli/Prompt"
// import * as Command from "@effect/cli/Command"
import * as Prompt from "../src/internal/prompt/select.js"
// import * as Prompt from "@effect/cli/Prompt"
import * as NodeContext from "@effect/platform-node/NodeContext"
import * as Runtime from "@effect/platform-node/Runtime"
import * as Effect from "effect/Effect"
Expand All @@ -13,55 +14,60 @@ const colorPrompt = Prompt.select({
]
})

const confirmPrompt = Prompt.confirm({
message: "Can you please confirm?"
})
// const confirmPrompt = Prompt.confirm({
// message: "Can you please confirm?"
// })

const datePrompt = Prompt.date({
message: "What's your birth day?",
dateMask:
"\"Year:\" YYYY, \"Month:\" MM, \"Day:\" DD \\\\\\\\||// \\Hour: HH, \\Minute: mm, \"Seconds:\" ss",
validate: (date) =>
date.getTime() > Date.now()
? Effect.fail("Your birth day can't be in the future")
: Effect.succeed(date)
})
// const datePrompt = Prompt.date({
// message: "What's your birth day?",
// dateMask:
// "\"Year:\" YYYY, \"Month:\" MM, \"Day:\" DD \\\\\\\\||// \\Hour: HH, \\Minute: mm, \"Seconds:\" ss",
// validate: (date) =>
// date.getTime() > Date.now()
// ? Effect.fail("Your birth day can't be in the future")
// : Effect.succeed(date)
// })

const numberPrompt = Prompt.float({
message: `What is your favorite number?`,
validate: (n) => n > 0 ? Effect.succeed(n) : Effect.fail("must be greater than 0")
})
// const numberPrompt = Prompt.float({
// message: `What is your favorite number?`,
// validate: (n) => n > 0 ? Effect.succeed(n) : Effect.fail("must be greater than 0")
// })

const textPrompt = Prompt.text({
message: `Please answer the following question\nWhat is your favorite food?`,
type: "hidden",
validate: (value) =>
value.length === 0
? Effect.fail("must be non-empty\nyou entered " + value)
: Effect.succeed(value)
})
// const textPrompt = Prompt.text({
// message: "What is your password?",
// type: "password",
// validate: (value) =>
// value.length === 0
// ? Effect.fail("Password must be non-empty")
// : Effect.succeed(value)
// })

const togglePrompt = Prompt.toggle({
message: "Can you confirm?",
active: "yes",
inactive: "no"
})
// const togglePrompt = Prompt.toggle({
// message: "Can you confirm?",
// active: "yes",
// inactive: "no"
// })

const prompt = Prompt.all([
colorPrompt,
confirmPrompt,
datePrompt,
numberPrompt,
textPrompt,
togglePrompt
])
// const prompt = Prompt.all([
// colorPrompt,
// confirmPrompt,
// datePrompt,
// numberPrompt,
// textPrompt,
// togglePrompt
// ])

const cli = Command.run(Command.prompt("favorites", prompt, Effect.log), {
name: "Prompt Examples",
version: "0.0.1"
})
// const cli = Command.run(Command.prompt("favorites", textPrompt, Effect.log), {
// name: "Prompt Examples",
// version: "0.0.1"
// })

Effect.suspend(() => cli(process.argv.slice(2))).pipe(
colorPrompt.pipe(
Effect.provide(NodeContext.layer),
Runtime.runMain
)

// Effect.suspend(() => cli(process.argv.slice(2))).pipe(
// Effect.provide(NodeContext.layer),
// Runtime.runMain
// )
34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,38 +57,38 @@
"coverage": "vitest run --coverage"
},
"peerDependencies": {
"@effect/platform": "^0.31.0",
"@effect/platform": "^0.31.2",
"@effect/printer": "^0.24.0",
"@effect/printer-ansi": "^0.24.0",
"@effect/schema": "^0.49.0",
"@effect/printer-ansi": "^0.25.0",
"@effect/schema": "^0.50.0",
"effect": "2.0.0-next.56"
},
"devDependencies": {
"@babel/cli": "^7.23.4",
"@babel/core": "^7.23.3",
"@babel/core": "^7.23.5",
"@babel/plugin-transform-export-namespace-from": "^7.23.4",
"@babel/plugin-transform-modules-commonjs": "^7.23.3",
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.2",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.1",
"@effect/build-utils": "^0.5.0",
"@effect/docgen": "^0.3.5",
"@effect/docgen": "^0.3.6",
"@effect/eslint-plugin": "^0.1.2",
"@effect/language-service": "^0.0.21",
"@effect/platform": "^0.31.0",
"@effect/platform-node": "^0.32.0",
"@effect/platform": "^0.31.2",
"@effect/platform-node": "^0.32.3",
"@effect/printer": "^0.24.0",
"@effect/printer-ansi": "^0.24.0",
"@effect/schema": "^0.49.0",
"@types/node": "^20.9.2",
"@typescript-eslint/eslint-plugin": "^6.12.0",
"@typescript-eslint/parser": "^6.12.0",
"@effect/printer-ansi": "^0.25.0",
"@effect/schema": "^0.50.0",
"@types/node": "^20.10.1",
"@typescript-eslint/eslint-plugin": "^6.13.1",
"@typescript-eslint/parser": "^6.13.1",
"@vitest/coverage-v8": "^0.34.6",
"babel-plugin-annotate-pure-calls": "^0.4.0",
"effect": "2.0.0-next.56",
"error-stack-parser": "^2.1.4",
"eslint": "^8.54.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-codegen": "^0.18.1",
"eslint-plugin-codegen": "^0.21.0",
"eslint-plugin-deprecation": "^2.0.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
Expand All @@ -97,9 +97,9 @@
"madge": "^6.1.0",
"rimraf": "^5.0.5",
"stackframe": "^1.3.4",
"tsx": "^4.1.4",
"tsx": "^4.6.0",
"typescript": "^5.3.2",
"vite": "^5.0.0",
"vite": "^5.0.4",
"vitest": "^0.34.6"
}
}
Loading

0 comments on commit 6854f8e

Please sign in to comment.