Skip to content

Commit 52655ab

Browse files
committed
feat: accept Enter as confirmation in confirm()
Previously only "y"/"yes" was accepted. Pressing Enter (empty input) is the standard UX convention for confirming the default action, so we now treat it as affirmative. Prompts updated from [y/n] to [Y/n] to signal the default per convention.
1 parent 21c218a commit 52655ab

File tree

5 files changed

+9
-8
lines changed

5 files changed

+9
-8
lines changed

core/input.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func InputConfirm(title string, prompt string) (bool, error) {
2121
input.Title(title)
2222
}
2323
err := input.Run()
24-
return strings.HasPrefix(strings.ToLower(response), "y"), err
24+
return response == "" || strings.HasPrefix(strings.ToLower(response), "y"), err
2525
}
2626

2727
func InputText(prompt, hint, default_ string, secret bool) (RadString, error) {

core/shell.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func (i *Interpreter) executeShellCmd(shell *rl.Shell) shellResult {
136136
// warning: as of writing, this is *not* covered in tests
137137
func realShellExecutor(invocation ShellInvocation) (string, string, int) {
138138
if FlagConfirmShellCommands.Value || invocation.IsConfirm {
139-
ok, err := InputConfirm(invocation.Command, "Run above command? [y/n] > ")
139+
ok, err := InputConfirm(invocation.Command, "Run above command? [Y/n] > ")
140140
if err != nil {
141141
panic(fmt.Sprintf("Error confirming shell command: %v", err))
142142
}

docs-web/docs/examples/brewi.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ We use [string interpolation](../guide/strings-advanced.md#string-interpolation)
9191
You can try running the command now! Make sure it's executable (`chmod +x ./brewi`).
9292

9393
Next, we want to ask the user if they'd like to proceed with installing the formula. For that, Rad offers the [`confirm`](../reference/functions.md#confirm) function.
94-
The default prompt is `Confirm? [y/n] > `, which works fine for us here, so we'll do a simple 0-arg `confirm()` call. The function returns a bool for yes/no, so we'll put it in an if statement.
94+
The default prompt is `Confirm? [Y/n] > `, which works fine for us here, so we'll do a simple 0-arg `confirm()` call. The function returns a bool for yes/no, so we'll put it in an if statement.
9595

9696
```rad linenums="1" hl_lines="9-10"
9797
#!/usr/bin/env rad

docs-web/docs/reference/functions.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,17 +507,18 @@ password = input("Password: ", secret=true) // -> Hides typed characte
507507

508508
### confirm
509509

510-
Gets a boolean confirmation from the user (y/n prompt).
510+
Gets a boolean confirmation from the user (y/n prompt). Accepts "y", "yes", or Enter (empty input) as
511+
confirmation.
511512

512513
```rad
513-
confirm(prompt: str = "Confirm? [y/n] > ") -> bool|error
514+
confirm(prompt: str = "Confirm? [Y/n] > ") -> bool|error
514515
```
515516

516517
```rad
517-
if confirm(): // -> Uses default "Confirm? [y/n] > " prompt
518+
if confirm(): // -> Uses default "Confirm? [Y/n] > " prompt
518519
print("Confirmed!")
519520
520-
if confirm("Delete file? [y/n] "): // -> Custom prompt
521+
if confirm("Delete file? [Y/n] "): // -> Custom prompt
521522
print("File deleted")
522523
```
523524

rts/signatures.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func init() {
6161
newFnSignature(`truncate(_str: str, _len: int) -> error|str`),
6262
newFnSignature(`unique(_list: any[]) -> any[]`),
6363
newFnSignature(`index_of(_subject: str|list, _target: any, *, n: int = 0, start: int = 0) -> int?`),
64-
newFnSignature(`confirm(prompt: str = "Confirm? [y/n] > ") -> error|bool`),
64+
newFnSignature(`confirm(prompt: str = "Confirm? [Y/n] > ") -> error|bool`),
6565
newFnSignature(`parse_json(_str: str) -> any|error`),
6666
newFnSignature(`parse_int(_str: str) -> int|error`),
6767
newFnSignature(`parse_float(_str: str) -> float|error`),

0 commit comments

Comments
 (0)