namespace Terminal.Gui; public partial class ColorPicker { /// /// Open a with two or , based on the /// is false or true, respectively, for /// and colors. /// /// The title to show in the dialog. /// The current attribute used. /// The new attribute. /// if a new color was accepted, otherwise . public static bool Prompt (string title, Attribute? currentAttribute, out Attribute newAttribute) { var accept = false; var d = new Dialog { Title = title, Width = Application.Force16Colors ? 37 : Dim.Auto (DimAutoStyle.Auto, Dim.Percent (80), Dim.Percent (90)), Height = 20 }; var btnOk = new Button { X = Pos.Center () - 5, Y = Application.Force16Colors ? 6 : 4, Text = "Ok", Width = Dim.Auto (), IsDefault = true }; btnOk.Accepting += (s, e) => { accept = true; e.Cancel = true; Application.RequestStop (); }; var btnCancel = new Button { X = Pos.Center () + 5, Y = 4, Text = "Cancel", Width = Dim.Auto () }; btnCancel.Accepting += (s, e) => { e.Cancel = true; Application.RequestStop (); }; d.Add (btnOk); d.Add (btnCancel); d.AddButton (btnOk); d.AddButton (btnCancel); View cpForeground; if (Application.Force16Colors) { cpForeground = new ColorPicker16 { SelectedColor = currentAttribute!.Value.Foreground.GetClosestNamedColor16 (), Width = Dim.Fill (), BorderStyle = LineStyle.Single, Title = "Foreground" }; } else { cpForeground = new ColorPicker { SelectedColor = currentAttribute!.Value.Foreground, Width = Dim.Fill (), Style = new () { ShowColorName = true, ShowTextFields = true }, BorderStyle = LineStyle.Single, Title = "Foreground" }; ((ColorPicker)cpForeground).ApplyStyleChanges (); } View cpBackground; if (Application.Force16Colors) { cpBackground = new ColorPicker16 { SelectedColor = currentAttribute!.Value.Background.GetClosestNamedColor16 (), Y = Pos.Bottom (cpForeground) + 1, Width = Dim.Fill (), BorderStyle = LineStyle.Single, Title = "Background" }; } else { cpBackground = new ColorPicker { SelectedColor = currentAttribute!.Value.Background, Width = Dim.Fill (), Y = Pos.Bottom (cpForeground) + 1, Style = new () { ShowColorName = true, ShowTextFields = true }, BorderStyle = LineStyle.Single, Title = "Background" }; ((ColorPicker)cpBackground).ApplyStyleChanges (); } d.Add (cpForeground, cpBackground); Application.Run (d); d.Dispose (); Color newForeColor = Application.Force16Colors ? ((ColorPicker16)cpForeground).SelectedColor : ((ColorPicker)cpForeground).SelectedColor; Color newBackColor = Application.Force16Colors ? ((ColorPicker16)cpBackground).SelectedColor : ((ColorPicker)cpBackground).SelectedColor; newAttribute = new (newForeColor, newBackColor); return accept; } }