Skip to content

Commit dcfca89

Browse files
committed
fix(macos-cli): drop fflush(stdout) and align with existing readLineWithPrompt pattern
1 parent 6274de3 commit dcfca89

1 file changed

Lines changed: 10 additions & 13 deletions

File tree

apps/macos/Sources/OpenClawMacCLI/WizardCommand.swift

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -537,24 +537,21 @@ private func readPasswordWithPrompt(_ prompt: String) throws -> String {
537537
// input at _PASSWORD_LEN (128 chars on BSD/macOS), which would silently
538538
// discard longer credentials such as JWTs or extended provider tokens.
539539
print("\(prompt): ", terminator: "")
540-
fflush(stdout)
541540

542-
var oldTerm = termios()
543-
let echoDisabled: Bool
544-
if isatty(STDIN_FILENO) != 0 && tcgetattr(STDIN_FILENO, &oldTerm) == 0 {
545-
var newTerm = oldTerm
546-
newTerm.c_lflag &= ~tcflag_t(ECHO)
547-
echoDisabled = tcsetattr(STDIN_FILENO, TCSANOW, &newTerm) == 0
548-
} else {
549-
echoDisabled = false
541+
var oldAttrs = termios()
542+
var echoDisabled = false
543+
if isatty(STDIN_FILENO) != 0 && tcgetattr(STDIN_FILENO, &oldAttrs) == 0 {
544+
var newAttrs = oldAttrs
545+
newAttrs.c_lflag &= ~tcflag_t(ECHO)
546+
echoDisabled = tcsetattr(STDIN_FILENO, TCSANOW, &newAttrs) == 0
550547
}
551548
defer {
552549
if echoDisabled {
553-
_ = tcsetattr(STDIN_FILENO, TCSANOW, &oldTerm)
550+
_ = tcsetattr(STDIN_FILENO, TCSANOW, &oldAttrs)
551+
// The user's Enter keystroke wasn't echoed while ECHO was disabled;
552+
// emit a newline so subsequent output starts on its own line.
553+
print("")
554554
}
555-
// The user's Enter keystroke wasn't echoed while ECHO was disabled;
556-
// emit a newline so subsequent output starts on its own line.
557-
print("")
558555
}
559556

560557
guard let line = readLine() else {

0 commit comments

Comments
 (0)