(state: State, options: Options)
| 31 | const renderBeep = Doc.render(Doc.beep, { style: "pretty" }) |
| 32 | |
| 33 | function 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 | |
| 66 | function renderInput(nextState: State, options: Options, submitted: boolean) { |
| 67 | const text = getValue(nextState, options) |
no test coverage detected
searching dependent graphs…