namespace Terminal.Gui; /// /// MessageBox displays a modal message to the user, with a title, a message and a series of options that the user /// can choose from. /// /// /// The difference between the and /// method is the default set of colors used for the message box. /// /// /// The following example pops up a with the specified title and text, plus two /// s. The value -1 is returned when the user cancels the by pressing the /// ESC key. /// /// /// /// var n = MessageBox.Query ("Quit Demo", "Are you sure you want to quit this demo?", "Yes", "No"); /// if (n == 0) /// quit = true; /// else /// quit = false; /// /// public static class MessageBox { /// /// The index of the selected button, or -1 if the user pressed ESC to close the dialog. This is useful for web /// based console where by default there is no SynchronizationContext or TaskScheduler. /// public static int Clicked { get; private set; } = -1; /// /// Defines the default border styling for . Can be configured via /// . /// [SerializableConfigurationProperty (Scope = typeof (ThemeScope))] public static LineStyle DefaultBorderStyle { get; set; } = LineStyle.Single; /// /// Presents an error with the specified title and message and a list of buttons to show /// to the user. /// /// The index of the selected button, or -1 if the user pressed ESC to close the dialog. /// Width for the window. /// Height for the window. /// Title for the query. /// Message to display, might contain multiple lines. /// Array of buttons to add. /// /// Use instead; it automatically sizes the MessageBox based on /// the contents. /// public static int ErrorQuery (int width, int height, string title, string message, params string [] buttons) { return QueryFull (true, width, height, title, message, 0, true, buttons); } /// /// Presents an error with the specified title and message and a list of buttons to show /// to the user. /// /// The index of the selected button, or -1 if the user pressed ESC to close the dialog. /// Title for the query. /// Message to display, might contain multiple lines. /// Array of buttons to add. /// /// The message box will be vertically and horizontally centered in the container and the size will be /// automatically determined from the size of the title, message. and buttons. /// public static int ErrorQuery (string title, string message, params string [] buttons) { return QueryFull (true, 0, 0, title, message, 0, true, buttons); } /// /// Presents an error with the specified title and message and a list of buttons to show /// to the user. /// /// The index of the selected button, or -1 if the user pressed ESC to close the dialog. /// Width for the window. /// Height for the window. /// Title for the query. /// Message to display, might contain multiple lines. /// Index of the default button. /// Array of buttons to add. /// /// Use instead; it automatically sizes the MessageBox based on /// the contents. /// public static int ErrorQuery ( int width, int height, string title, string message, int defaultButton = 0, params string [] buttons ) { return QueryFull (true, width, height, title, message, defaultButton, true, buttons); } /// /// Presents an error with the specified title and message and a list of buttons to show /// to the user. /// /// The index of the selected button, or -1 if the user pressed ESC to close the dialog. /// Title for the query. /// Message to display, might contain multiple lines. /// Index of the default button. /// Array of buttons to add. /// /// The message box will be vertically and horizontally centered in the container and the size will be /// automatically determined from the size of the title, message. and buttons. /// public static int ErrorQuery (string title, string message, int defaultButton = 0, params string [] buttons) { return QueryFull (true, 0, 0, title, message, defaultButton, true, buttons); } /// /// Presents an error with the specified title and message and a list of buttons to show /// to the user. /// /// The index of the selected button, or -1 if the user pressed ESC to close the dialog. /// Width for the window. /// Height for the window. /// Title for the query. /// Message to display, might contain multiple lines. /// Index of the default button. /// If wrap the message or not. /// Array of buttons to add. /// /// Use instead; it automatically sizes the MessageBox based on /// the contents. /// public static int ErrorQuery ( int width, int height, string title, string message, int defaultButton = 0, bool wrapMessagge = true, params string [] buttons ) { return QueryFull (true, width, height, title, message, defaultButton, wrapMessagge, buttons); } /// /// Presents an error with the specified title and message and a list of buttons to show /// to the user. /// /// The index of the selected button, or -1 if the user pressed ESC to close the dialog. /// Title for the query. /// Message to display, might contain multiple lines. /// Index of the default button. /// If wrap the message or not. /// Array of buttons to add. /// /// The message box will be vertically and horizontally centered in the container and the size will be /// automatically determined from the size of the title, message. and buttons. /// public static int ErrorQuery ( string title, string message, int defaultButton = 0, bool wrapMessagge = true, params string [] buttons ) { return QueryFull (true, 0, 0, title, message, defaultButton, wrapMessagge, buttons); } /// /// Presents a normal with the specified title and message and a list of buttons to show /// to the user. /// /// The index of the selected button, or -1 if the user pressed ESC to close the dialog. /// Width for the window. /// Height for the window. /// Title for the query. /// Message to display, might contain multiple lines. /// Array of buttons to add. /// /// Use instead; it automatically sizes the MessageBox based on the /// contents. /// public static int Query (int width, int height, string title, string message, params string [] buttons) { return QueryFull (false, width, height, title, message, 0, true, buttons); } /// /// Presents an error with the specified title and message and a list of buttons to show /// to the user. /// /// The index of the selected button, or -1 if the user pressed ESC to close the dialog. /// Title for the query. /// Message to display, might contain multiple lines. /// Array of buttons to add. /// /// The message box will be vertically and horizontally centered in the container and the size will be /// automatically determined from the size of the message and buttons. /// public static int Query (string title, string message, params string [] buttons) { return QueryFull (false, 0, 0, title, message, 0, true, buttons); } /// /// Presents a normal with the specified title and message and a list of buttons to show /// to the user. /// /// The index of the selected button, or -1 if the user pressed ESC to close the dialog. /// Width for the window. /// Height for the window. /// Title for the query. /// Message to display, might contain multiple lines. /// Index of the default button. /// Array of buttons to add. /// /// Use instead; it automatically sizes the MessageBox based on the /// contents. /// public static int Query ( int width, int height, string title, string message, int defaultButton = 0, params string [] buttons ) { return QueryFull (false, width, height, title, message, defaultButton, true, buttons); } /// /// Presents an error with the specified title and message and a list of buttons to show /// to the user. /// /// The index of the selected button, or -1 if the user pressed ESC to close the dialog. /// Title for the query. /// Message to display, might contain multiple lines. /// Index of the default button. /// Array of buttons to add. /// /// The message box will be vertically and horizontally centered in the container and the size will be /// automatically determined from the size of the message and buttons. /// public static int Query (string title, string message, int defaultButton = 0, params string [] buttons) { return QueryFull (false, 0, 0, title, message, defaultButton, true, buttons); } /// /// Presents a normal with the specified title and message and a list of buttons to show /// to the user. /// /// The index of the selected button, or -1 if the user pressed ESC to close the dialog. /// Width for the window. /// Height for the window. /// Title for the query. /// Message to display, might contain multiple lines. /// Index of the default button. /// If wrap the message or not. /// Array of buttons to add. /// /// Use instead; it automatically sizes the MessageBox based on the /// contents. /// public static int Query ( int width, int height, string title, string message, int defaultButton = 0, bool wrapMessagge = true, params string [] buttons ) { return QueryFull (false, width, height, title, message, defaultButton, wrapMessagge, buttons); } /// /// Presents an error with the specified title and message and a list of buttons to show /// to the user. /// /// The index of the selected button, or -1 if the user pressed ESC to close the dialog. /// Title for the query. /// Message to display, might contain multiple lines. /// Index of the default button. /// If wrap the message or not. /// Array of buttons to add. /// /// The message box will be vertically and horizontally centered in the container and the size will be /// automatically determined from the size of the message and buttons. /// public static int Query ( string title, string message, int defaultButton = 0, bool wrapMessage = true, params string [] buttons ) { return QueryFull (false, 0, 0, title, message, defaultButton, wrapMessage, buttons); } private static int QueryFull ( bool useErrorColors, int width, int height, string title, string message, int defaultButton = 0, bool wrapMessage = true, params string [] buttons ) { // Create button array for Dialog var count = 0; List