From 7d9bfec4e437b7585e7f7ca17045580b3d7dbb33 Mon Sep 17 00:00:00 2001 From: Denny Tsai Date: Sun, 8 Oct 2023 11:11:01 +0800 Subject: [PATCH 1/2] Add the ability to show text input explicitly on dialog --- dialog.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dialog.go b/dialog.go index aabc869..7fbe43e 100644 --- a/dialog.go +++ b/dialog.go @@ -50,6 +50,7 @@ func buildDialog(text string, options []string) string { // dialog := mack.DialogOptions{ // Text: "Dialog text", // Required // Title: "Dialog title", // Optional +// CollectAnswer: true, // Optional - If true, shows a text input to collect answer // Answer: "Default answer", // Optional // Duration: 5, // Optional // HiddenAnswer: true, // Optional - If true, turns the input text to bullets @@ -70,7 +71,7 @@ func buildDialogBox(dialog DialogOptions) string { if dialog.Title != "" { title = "with title " + wrapInQuotes(dialog.Title) } - if dialog.Answer != "" { + if dialog.CollectAnswer || dialog.Answer != "" { answer = "default answer " + wrapInQuotes(dialog.Answer) } if dialog.HiddenAnswer { @@ -103,6 +104,7 @@ func buildDialogBox(dialog DialogOptions) string { type DialogOptions struct { Text string // The content of the dialog box Title string // The title of the dialog box, displayed in emphasis + CollectAnswer bool // If true, shows a text input to collect answer Answer string // The default text in the input field HiddenAnswer bool // If true, converts the answer text to bullets (like a password field) Icon string // The path to a .icns file, or one of the following: "stop", "note", "caution" From cba6d2e133f401a02af513bbf32bf8a0f0e6e48a Mon Sep 17 00:00:00 2001 From: Denny Tsai Date: Sun, 8 Oct 2023 11:19:32 +0800 Subject: [PATCH 2/2] Add test for CollectAnswer --- dialog_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dialog_test.go b/dialog_test.go index 533d6d2..70aae74 100644 --- a/dialog_test.go +++ b/dialog_test.go @@ -51,6 +51,14 @@ func TestBuildDialogBox(t *testing.T) { }), expected: "display dialog \"text\" with title \"title\"", }, + StringAssert{ + actual: buildDialogBox(DialogOptions{ + Text: "text", + Title: "title", + CollectAnswer: true, + }), + expected: "display dialog \"text\" with title \"title\" default answer \"\"", + }, StringAssert{ actual: buildDialogBox(DialogOptions{ Text: "text",