Skip to content

Commit

Permalink
Merge branch 'master' into text_only_prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn authored Dec 20, 2024
2 parents 129477c + 8087827 commit f07d8ce
Showing 1 changed file with 38 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,6 @@ public Map<String, PromptResultItemIF> prompt(
Map<String, PromptResultItemIF> resultMap = new HashMap<>();
prompt(header, promptableElementList, resultMap);
return resultMap;
} catch (IOError e) {
if (e.getCause() instanceof InterruptedIOException) {
throw new UserInterruptException(e.getCause());
} else {
throw e;
}
} finally {
close();
}
Expand Down Expand Up @@ -259,44 +253,50 @@ public void prompt(
removePreviousResult(pe);
backward = false;
}
PromptResultItemIF oldResult = resultMap.get(pe.getName());
PromptResultItemIF result = promptElement(header, pe, oldResult);
if (result == null) {
// Prompt was cancelled by the user
if (i > 0) {
// Go back to previous prompt
i -= 2;
backward = true;
continue;
} else {
if (config.cancellableFirstPrompt()) {
resultMap.clear();
return;
} else {
// Repeat current prompt
i -= 1;
try {
PromptResultItemIF oldResult = resultMap.get(pe.getName());
PromptResultItemIF result = promptElement(header, pe, oldResult);
if (result == null) {
// Prompt was cancelled by the user
if (i > 0) {
// Go back to previous prompt
i -= 2;
backward = true;
continue;
} else {
if (config.cancellableFirstPrompt()) {
resultMap.clear();
return;
} else {
// Repeat current prompt
i -= 1;
}
}
}
AttributedStringBuilder message;
if (pe instanceof Text) {
Text te = (Text) pe;
header.addAll(te.getLines());
} else {
String resp = result.getDisplayResult();
if (result instanceof ConfirmResult) {
ConfirmResult cr = (ConfirmResult) result;
if (cr.getConfirmed() == ConfirmChoice.ConfirmationValue.YES) {
resp = config.resourceBundle().getString("confirmation_yes_answer");
} else {
resp = config.resourceBundle().getString("confirmation_no_answer");
AttributedStringBuilder message;
if (pe instanceof Text) {
Text te = (Text) pe;
header.addAll(te.getLines());
} else {
String resp = result.getDisplayResult();
if (result instanceof ConfirmResult) {
ConfirmResult cr = (ConfirmResult) result;
if (cr.getConfirmed() == ConfirmChoice.ConfirmationValue.YES) {
resp = config.resourceBundle().getString("confirmation_yes_answer");
} else {
resp = config.resourceBundle().getString("confirmation_no_answer");
}
}
message = createMessage(pe.getMessage(), resp);
header.add(message.toAttributedString());
}
resultMap.put(pe.getName(), result);
} catch (IOError e) {
if (e.getCause() instanceof InterruptedIOException) {
throw new UserInterruptException(e.getCause());
} else {
throw e;
}
message = createMessage(pe.getMessage(), resp);
header.add(message.toAttributedString());
}
resultMap.put(pe.getName(), result);
}
}

Expand Down

0 comments on commit f07d8ce

Please sign in to comment.