Skip to content

Ctrl+C is not propagated #1531

@alamothe

Description

@alamothe

When I press Ctrl+C, the exception does happen, but it just gets printed in a different thread, and it's not propagated at all:

Image

My application continues to work.

I have:

		val terminal = TerminalBuilder.builder()
				.dumb(false)
				.build()

		// Handle Ctrl+C gracefully
		terminal.handle(Terminal.Signal.INT, {
			throw UserInterruptException("Caught Ctrl+C signal");
		})

		try {
			terminal.puts(Capability.cursor_invisible)

			val promptBuilder = PromptBuilder()
			val checkboxBuilder = promptBuilder.createCheckboxPrompt()
					.name("selection")
					.message(title)

			options.forEach { opt ->
				when (opt) {
					is Option.Label -> {
						checkboxBuilder
								.newSeparator()
								.text(opt.label)
								.add()
					}

					is Option.Item<*> -> {
						checkboxBuilder
								.newItem(opt.key)
								.text(opt.key)
								.add()
					}
				}
			}

			checkboxBuilder.addPrompt()

			val promptResult = ConsolePrompt(
					terminal,
					ConsolePrompt.UiConfig(
							"",
							"$FILLED_CIRCLE ",
							"$CIRCLE ",
							"- ",
					),
			)
					.prompt(promptBuilder.build())["selection"] as? CheckboxResult
					?: return emptyList()

			return options
					.filterIsInstance<Option.Item<*>>()
					.filter { item ->
						item.key in promptResult.selectedIds
					}
		} catch (e: UserInterruptException) {
			// Does not happen			
			println("\nOperation cancelled.")
			return emptyList()
		} finally {
			// Does not happen			
			showCursorSafely(terminal)
			terminal.close()
		}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions