mirror of
https://github.com/munki/munki.git
synced 2025-12-30 02:59:54 -06:00
When using libedit/readline to insert a prompt and default response, be more careful to ensure the readline structures are initialized before proceeding
This commit is contained in:
@@ -32,12 +32,22 @@ func getInput(prompt: String? = nil, defaultText: String? = nil) -> String? {
|
||||
// the readline implementation is so broken
|
||||
let queue = OperationQueue()
|
||||
let insertOperation = BlockOperation {
|
||||
usleep(10000) // 0.01 seconds
|
||||
rl_set_prompt(prompt ?? "")
|
||||
if let defaultText {
|
||||
rl_insert_text(defaultText)
|
||||
var counter = 10
|
||||
while counter > 0 {
|
||||
// sleep until rl_line_buffer is initialized
|
||||
usleep(10000) // 0.01 second
|
||||
if rl_line_buffer != nil {
|
||||
// rl_line_buffer is initialized --
|
||||
// set prompt and insert default text
|
||||
rl_set_prompt(prompt ?? "")
|
||||
if let defaultText {
|
||||
rl_insert_text(defaultText)
|
||||
}
|
||||
rl_forced_update_display()
|
||||
break
|
||||
}
|
||||
counter -= 1
|
||||
}
|
||||
rl_forced_update_display()
|
||||
}
|
||||
queue.addOperation(insertOperation)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user