@nuxt/docs-nightly 5.0.0-29794655.c0e8bf84 → 5.0.0-29794680.8e18278b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/4.api/5.kit/14.logging.md +54 -0
- package/package.json +3 -2
|
@@ -53,3 +53,57 @@ export default defineNuxtModule({
|
|
|
53
53
|
},
|
|
54
54
|
})
|
|
55
55
|
```
|
|
56
|
+
|
|
57
|
+
## `useTerminal`
|
|
58
|
+
|
|
59
|
+
Returns a set of primitives for interacting with the user's terminal. When Nuxt is running inside an interactive host such as the `nuxt dev` terminal UI, prompts, tasks and notifications are handed to it, so they are answerable and rendered in one place. Otherwise they fall back to logging.
|
|
60
|
+
|
|
61
|
+
### Usage
|
|
62
|
+
|
|
63
|
+
```ts twoslash
|
|
64
|
+
declare function runPackageInstall (name: string): Promise<void>
|
|
65
|
+
// ---cut---
|
|
66
|
+
import { defineNuxtModule, useTerminal } from '@nuxt/kit'
|
|
67
|
+
|
|
68
|
+
export default defineNuxtModule({
|
|
69
|
+
async setup () {
|
|
70
|
+
const terminal = useTerminal()
|
|
71
|
+
|
|
72
|
+
const install = await terminal.prompt('Do you want to install `my-module`?', { type: 'confirm' })
|
|
73
|
+
if (!install) {
|
|
74
|
+
return
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const task = terminal.startTask('Installing `my-module`...')
|
|
78
|
+
// run your actual task
|
|
79
|
+
await runPackageInstall('my-module')
|
|
80
|
+
task.stop('Installed `my-module`')
|
|
81
|
+
},
|
|
82
|
+
})
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Type
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
function useTerminal (): NuxtTerminal
|
|
89
|
+
|
|
90
|
+
interface NuxtTerminal {
|
|
91
|
+
readonly interactive: boolean
|
|
92
|
+
withTerminal: <T>(work: () => Promise<T>) => Promise<T>
|
|
93
|
+
prompt: (message: string, options?: NuxtPromptOptions) => Promise<any>
|
|
94
|
+
startTask: (label: string) => NuxtTerminalTask
|
|
95
|
+
notify: (notification: NuxtTerminalNotification) => NuxtTerminalNotice
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Properties
|
|
100
|
+
|
|
101
|
+
**`interactive`**: Whether an interactive host is present. When `false`, the primitives below log to the current process streams instead.
|
|
102
|
+
|
|
103
|
+
**`withTerminal`**: Borrows the terminal for the duration of `work`, suspending any host UI and releasing `stdin`. Use it when you need to write to the terminal or read from `stdin` directly. Concurrent callers are serialised, and a nested call from within a borrow runs immediately.
|
|
104
|
+
|
|
105
|
+
**`prompt`**: Asks the user a question, borrowing the terminal for as long as the prompt is open. Takes the same options as `logger.prompt`.
|
|
106
|
+
|
|
107
|
+
**`startTask`**: Starts a long-running task, rendered on the host's status surface where available. Finish it with `task.stop(message?, outcome?)`, or change its label with `task.update(label)`.
|
|
108
|
+
|
|
109
|
+
**`notify`**: Shows a message and holds it on screen until the user acknowledges it or `notice.dismiss()` is called. `notice.dismissed` settles once the notice is gone.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/docs-nightly",
|
|
3
|
-
"version": "5.0.0-
|
|
3
|
+
"version": "5.0.0-29794680.8e18278b",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/nuxt/nuxt.git",
|
|
@@ -17,5 +17,6 @@
|
|
|
17
17
|
"**/*.md",
|
|
18
18
|
"**/*.yml"
|
|
19
19
|
],
|
|
20
|
-
"_name": "@nuxt/docs"
|
|
20
|
+
"_name": "@nuxt/docs",
|
|
21
|
+
"scripts": {}
|
|
21
22
|
}
|