MCPcopy Create free account
hub / github.com/Effect-TS/effect / renderClearScreen

Function renderClearScreen

packages/cli/src/internal/prompt/text.ts:33–64  ·  view source on GitHub ↗
(state: State, options: Options)

Source from the content-addressed store, hash-verified

31const renderBeep = Doc.render(Doc.beep, { style: "pretty" })
32
33function renderClearScreen(state: State, options: Options) {
34 return Effect.gen(function*() {
35 const terminal = yield* Terminal.Terminal
36 const columns = yield* terminal.columns
37 // Erase the current line and place the cursor in column one
38 const resetCurrentLine = Doc.cat(Doc.eraseLine, Doc.cursorLeft)
39 // Check for any error output
40 const clearError = Option.match(state.error, {
41 onNone: () => Doc.empty,
42 onSome: (error) =>
43 // If there was an error, move the cursor down to the final error line and
44 // then clear all lines of error output
45 Doc.cursorDown(InternalAnsiUtils.lines(error, columns)).pipe(
46 // Add a leading newline to the error message to ensure that the corrrect
47 // number of error lines are erased
48 Doc.cat(InternalAnsiUtils.eraseText(`\n${error}`, columns))
49 )
50 })
51 // Ensure that the prior prompt output is cleaned up
52 // Calculate full rendered line: "? " + message + " › " + input
53 const inputValue = state.value.length > 0 ? state.value : options.default
54 const fullLine = `? ${options.message} \u203a ${inputValue}`
55 const clearOutput = InternalAnsiUtils.eraseText(fullLine, columns)
56 // Concatenate and render all documents
57 return clearError.pipe(
58 Doc.cat(clearOutput),
59 Doc.cat(resetCurrentLine),
60 Optimize.optimize(Optimize.Deep),
61 Doc.render({ style: "pretty", options: { lineWidth: columns } })
62 )
63 })
64}
65
66function renderInput(nextState: State, options: Options, submitted: boolean) {
67 const text = getValue(nextState, options)

Callers 1

handleClearFunction · 0.85

Calls 1

pipeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…