diff --git a/app/javascript/controllers/terminal_controller.js b/app/javascript/controllers/terminal_controller.js index dd29b96c0..c1983f569 100644 --- a/app/javascript/controllers/terminal_controller.js +++ b/app/javascript/controllers/terminal_controller.js @@ -1,5 +1,6 @@ import { Controller } from "@hotwired/stimulus" import { HttpStatus } from "helpers/http_helpers" +import { isMultiLineString } from "helpers/text_helpers"; import { marked } from "marked" export default class extends Controller { @@ -127,7 +128,7 @@ export default class extends Controller { const { confirmation, message, redirect_to } = responseJson if (message) { - this.#showOutput(marked.parse(message)) + this.#showOutput(message) } if (confirmation) { @@ -141,10 +142,19 @@ export default class extends Controller { async #requestConfirmation(confirmationPrompt) { this.element.classList.add(this.confirmationClass) - this.inputTarget.value = `${confirmationPrompt}? [Y/n] ` + this.#showConfirmationPrompt(confirmationPrompt) this.waitingForConfirmationValue = true } + #showConfirmationPrompt(confirmationPrompt) { + if (isMultiLineString(confirmationPrompt)) { + this.#showOutput(confirmationPrompt) + this.inputTarget.value = `Do you confirm? [Y/n] ` + } else { + this.inputTarget.value = `${confirmationPrompt}? [Y/n] ` + } + } + #handleConfirmationKey(key) { if (key === "enter" || key === "y") { this.#submitWithConfirmation() @@ -162,9 +172,9 @@ export default class extends Controller { this.#reset() } - #showOutput(html) { + #showOutput(markdown) { + const html = marked.parse(markdown) this.element.classList.add(this.outputClass) - console.debug("PUT ON ", this.outputTarget); this.outputTarget.innerHTML = html } diff --git a/app/javascript/helpers/text_helpers.js b/app/javascript/helpers/text_helpers.js new file mode 100644 index 000000000..2a0a2dced --- /dev/null +++ b/app/javascript/helpers/text_helpers.js @@ -0,0 +1,3 @@ +export function isMultiLineString(string) { + return /\r|\n/.test(string) +} diff --git a/app/models/command/composite.rb b/app/models/command/composite.rb index 19bd62882..798a5e8ce 100644 --- a/app/models/command/composite.rb +++ b/app/models/command/composite.rb @@ -21,7 +21,13 @@ class Command::Composite < Command end def confirmation_prompt - commands_excluding_redirections.collect(&:confirmation_prompt).to_sentence + confirmations = commands_excluding_redirections.collect(&:confirmation_prompt).collect { "- #{it}" }.join("\n") + + <<~MD + This will: + + #{confirmations} + MD end def needs_confirmation?