Skip to content

Instantly share code, notes, and snippets.

@Yoplitein
Created August 29, 2014 23:08
Show Gist options
  • Save Yoplitein/bd07e5a59a9bbd5e4d90 to your computer and use it in GitHub Desktop.
Save Yoplitein/bd07e5a59a9bbd5e4d90 to your computer and use it in GitHub Desktop.
string prompt function for tkd, similar to javascript's prompt function
string string_prompt(Window parent, string prompt, string initialValue = null)
{
string result;
auto window = new Window(parent, "Prompt");
auto label = new Label(window, prompt);
auto input = new Entry(window);
auto okButton = new Button(window, "OK");
auto cancelButton = new Button(window, "Cancel");
void close(CommandArgs _ = CommandArgs.init)
{
window.setGrab(false);
window.destroy;
}
void close_with_value(CommandArgs _)
{
result = input.getValue;
close;
}
okButton.setCommand(&close_with_value);
cancelButton.setCommand(&close);
input.bind("<Return>", &close_with_value);
label.grid(0, 0, 5, 0, 2);
input.grid(0, 1, 5, 0, 2);
okButton.grid(0, 2, 5);
cancelButton.grid(1, 2, 5);
input.setValue(initialValue);
input.focus;
window.setGrab(true);
window.wait;
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment