diff --git a/Terminal.Gui/Resources/Strings.Designer.cs b/Terminal.Gui/Resources/Strings.Designer.cs index 408e14395..99c47bd57 100644 --- a/Terminal.Gui/Resources/Strings.Designer.cs +++ b/Terminal.Gui/Resources/Strings.Designer.cs @@ -61,7 +61,7 @@ namespace Terminal.Gui.Resources { } /// - /// Looks up a localized string similar to Cancel. + /// Looks up a localized string similar to _Cancel. /// internal static string btnCancel { get { @@ -70,7 +70,7 @@ namespace Terminal.Gui.Resources { } /// - /// Looks up a localized string similar to No. + /// Looks up a localized string similar to _No. /// internal static string btnNo { get { @@ -79,7 +79,7 @@ namespace Terminal.Gui.Resources { } /// - /// Looks up a localized string similar to OK. + /// Looks up a localized string similar to _OK. /// internal static string btnOk { get { @@ -88,7 +88,7 @@ namespace Terminal.Gui.Resources { } /// - /// Looks up a localized string similar to Open. + /// Looks up a localized string similar to O_pen. /// internal static string btnOpen { get { @@ -97,7 +97,7 @@ namespace Terminal.Gui.Resources { } /// - /// Looks up a localized string similar to Save. + /// Looks up a localized string similar to _Save. /// internal static string btnSave { get { @@ -106,7 +106,7 @@ namespace Terminal.Gui.Resources { } /// - /// Looks up a localized string similar to Save as. + /// Looks up a localized string similar to Save _as. /// internal static string btnSaveAs { get { @@ -115,7 +115,7 @@ namespace Terminal.Gui.Resources { } /// - /// Looks up a localized string similar to Yes. + /// Looks up a localized string similar to _Yes. /// internal static string btnYes { get { diff --git a/Terminal.Gui/Resources/Strings.resx b/Terminal.Gui/Resources/Strings.resx index 1152cfb1d..60fbac4f7 100644 --- a/Terminal.Gui/Resources/Strings.resx +++ b/Terminal.Gui/Resources/Strings.resx @@ -227,7 +227,7 @@ New Folder - No + _No Rename Failed @@ -239,25 +239,25 @@ Rename - Yes + _Yes Existing - Open + O_pen - Save + _Save - Save as + Save _as - OK + _OK - Cancel + _Cancel _Delete diff --git a/Terminal.Gui/Text/TextFormatter.cs b/Terminal.Gui/Text/TextFormatter.cs index 7ada30a32..dbcd6ef11 100644 --- a/Terminal.Gui/Text/TextFormatter.cs +++ b/Terminal.Gui/Text/TextFormatter.cs @@ -960,12 +960,14 @@ namespace Terminal.Gui { /// /// The text to look in. /// The HotKey specifier (e.g. '_') to look for. - /// If true the legacy behavior of identifying the first upper case character as the HotKey will be enabled. - /// Regardless of the value of this parameter, hotKeySpecifier takes precedence. /// Outputs the Rune index into text. /// Outputs the hotKey. if not found. + /// If true the legacy behavior of identifying the + /// first upper case character as the HotKey will be enabled. + /// Regardless of the value of this parameter, hotKeySpecifier takes precedence. + /// Defaults to . /// true if a HotKey was found; false otherwise. - public static bool FindHotKey (string text, Rune hotKeySpecifier, bool firstUpperCase, out int hotPos, out Key hotKey) + public static bool FindHotKey (string text, Rune hotKeySpecifier, out int hotPos, out Key hotKey, bool firstUpperCase = false) { if (string.IsNullOrEmpty (text) || hotKeySpecifier == (Rune)0xFFFF) { hotPos = -1; @@ -1328,7 +1330,7 @@ namespace Terminal.Gui { if (NeedsFormat) { var shown_text = _text; - if (FindHotKey (_text, HotKeySpecifier, true, out _hotKeyPos, out var newHotKey)) { + if (FindHotKey (_text, HotKeySpecifier, out _hotKeyPos, out var newHotKey)) { HotKey = newHotKey; shown_text = RemoveHotKeySpecifier (Text, _hotKeyPos, HotKeySpecifier); shown_text = ReplaceHotKeyWithTag (shown_text, _hotKeyPos); @@ -1412,7 +1414,7 @@ namespace Terminal.Gui { foreach (var line in Lines) { sb.AppendLine (line); } - return sb.ToString (); + return sb.ToString ().TrimEnd (Environment.NewLine.ToCharArray ()); } /// diff --git a/Terminal.Gui/View/ViewDrawing.cs b/Terminal.Gui/View/ViewDrawing.cs index 4edf04a72..f55991324 100644 --- a/Terminal.Gui/View/ViewDrawing.cs +++ b/Terminal.Gui/View/ViewDrawing.cs @@ -299,8 +299,8 @@ public partial class View { { var hotkeySpec = HotKeySpecifier == (Rune)0xffff ? (Rune)'_' : HotKeySpecifier; Application.Driver.SetAttribute (normalColor); - foreach (var rune in text) { - if (rune == hotkeySpec.Value) { + foreach (var rune in text.EnumerateRunes ()) { + if (rune == new Rune(hotkeySpec.Value)) { Application.Driver.SetAttribute (hotColor); continue; } diff --git a/Terminal.Gui/View/ViewKeyboard.cs b/Terminal.Gui/View/ViewKeyboard.cs index 6caccdac4..62e14acf8 100644 --- a/Terminal.Gui/View/ViewKeyboard.cs +++ b/Terminal.Gui/View/ViewKeyboard.cs @@ -194,7 +194,7 @@ public partial class View { if (TextFormatter == null || HotKeySpecifier == new Rune ('\xFFFF')) { return; // throw new InvalidOperationException ("Can't set HotKey unless a TextFormatter has been created"); } - if (TextFormatter.FindHotKey (_text, HotKeySpecifier, true, out _, out var hk)) { + if (TextFormatter.FindHotKey (_text, HotKeySpecifier, out _, out var hk)) { if (_hotKey.KeyCode != hk) { HotKey = hk; } diff --git a/Terminal.Gui/Views/Button.cs b/Terminal.Gui/Views/Button.cs index c22ec013d..20bc2d55c 100644 --- a/Terminal.Gui/Views/Button.cs +++ b/Terminal.Gui/Views/Button.cs @@ -23,9 +23,6 @@ namespace Terminal.Gui; /// Use to change the hot key specifier from the default of ('_'). /// /// -/// If no hot key specifier is found, the first uppercase letter encountered will be used as the hot key. -/// -/// /// When the button is configured as the default () and the user presses /// the ENTER key, if no other processes the key, the 's /// event will will be fired. diff --git a/Terminal.Gui/Views/RadioGroup.cs b/Terminal.Gui/Views/RadioGroup.cs index e56505e70..f3fb75145 100644 --- a/Terminal.Gui/Views/RadioGroup.cs +++ b/Terminal.Gui/Views/RadioGroup.cs @@ -170,14 +170,14 @@ public class RadioGroup : View { set { // Remove old hot key bindings foreach (var label in _radioLabels) { - if (TextFormatter.FindHotKey (label, HotKeySpecifier, true, out _, out var hotKey)) { + if (TextFormatter.FindHotKey (label, HotKeySpecifier, out _, out var hotKey)) { AddKeyBindingsForHotKey (hotKey, KeyCode.Null); } } var prevCount = _radioLabels.Count; _radioLabels = value.ToList (); foreach (var label in _radioLabels) { - if (TextFormatter.FindHotKey (label, HotKeySpecifier, true, out _, out var hotKey)) { + if (TextFormatter.FindHotKey (label, HotKeySpecifier, out _, out var hotKey)) { AddKeyBindingsForHotKey (KeyCode.Null, hotKey); } } @@ -202,7 +202,7 @@ public class RadioGroup : View { if (KeyBindings.TryGet (key, out _)) { // Search RadioLabels for (int i = 0; i < _radioLabels.Count; i++) { - if (TextFormatter.FindHotKey (_radioLabels [i], HotKeySpecifier, true, out _, out var hotKey) + if (TextFormatter.FindHotKey (_radioLabels [i], HotKeySpecifier, out _, out var hotKey, true) && (key.NoAlt.NoCtrl.NoShift) == hotKey) { SelectedItem = i; keyEvent.Scope = KeyBindingScope.HotKey; @@ -246,7 +246,7 @@ public class RadioGroup : View { var rl = _radioLabels [i]; Driver.SetAttribute (GetNormalColor ()); Driver.AddStr ($"{(i == _selected ? CM.Glyphs.Selected : CM.Glyphs.UnSelected)} "); - TextFormatter.FindHotKey (rl, HotKeySpecifier, true, out int hotPos, out var hotKey); + TextFormatter.FindHotKey (rl, HotKeySpecifier, out int hotPos, out var hotKey); if (hotPos != -1 && (hotKey != KeyCode.Null)) { var rlRunes = rl.ToRunes (); for (int j = 0; j < rlRunes.Length; j++) { diff --git a/UICatalog/Scenarios/Adornments.cs b/UICatalog/Scenarios/Adornments.cs index f6424932c..8f6a9137d 100644 --- a/UICatalog/Scenarios/Adornments.cs +++ b/UICatalog/Scenarios/Adornments.cs @@ -5,8 +5,7 @@ using Terminal.Gui; namespace UICatalog.Scenarios; [ScenarioMetadata ("Adornments Demo", "Demonstrates Margin, Border, and Padding on Views.")] -[ScenarioCategory ("Layout")] -[ScenarioCategory ("Borders")] +[ScenarioCategory ("Layout"), ScenarioCategory ("Borders")] public class Adornments : Scenario { public override void Init () @@ -193,7 +192,7 @@ public class Adornments : Scenario { _bottomEdit.TextChanging += Edit_TextChanging; Add (_bottomEdit); - var copyTop = new Button ("Copy Top") { + var copyTop = new Button ("Cop_y Top") { X = Pos.Center () + 1, Y = Pos.Bottom (_bottomEdit) }; @@ -370,7 +369,7 @@ public class Adornments : Scenario { Add (_paddingEditor); _diagCheckBox = new CheckBox { - Text = "Diagnostics", + Text = "_Diagnostics", Y = Pos.Bottom (_paddingEditor) }; _diagCheckBox.Toggled += (s, e) => { diff --git a/UICatalog/Scenarios/AllViewsTester.cs b/UICatalog/Scenarios/AllViewsTester.cs index eb4b15c0e..323dc3475 100644 --- a/UICatalog/Scenarios/AllViewsTester.cs +++ b/UICatalog/Scenarios/AllViewsTester.cs @@ -7,35 +7,36 @@ using Terminal.Gui; namespace UICatalog.Scenarios; [ScenarioMetadata ("All Views Tester", "Provides a test UI for all classes derived from View.")] -[ScenarioCategory ("Layout")] -[ScenarioCategory ("Tests")] -[ScenarioCategory ("Top Level Windows")] +[ScenarioCategory ("Layout")] [ScenarioCategory ("Tests")] [ScenarioCategory ("Top Level Windows")] public class AllViewsTester : Scenario { - FrameView _leftPane; ListView _classListView; + CheckBox _computedCheckBox; + View _curView; + readonly List _dimNames = new () { "Factor", "Fill", "Absolute" }; FrameView _hostPane; + RadioGroup _hRadioGroup; + TextField _hText; + int _hVal; + FrameView _leftPane; + FrameView _locationFrame; - Dictionary _viewClasses; - View _curView = null; + // TODO: This is missing some + readonly List _posNames = new () { "Factor", "AnchorEnd", "Center", "Absolute" }; // Settings FrameView _settingsPane; - CheckBox _computedCheckBox; - FrameView _locationFrame; - RadioGroup _xRadioGroup; - TextField _xText; - int _xVal = 0; - RadioGroup _yRadioGroup; - TextField _yText; - int _yVal = 0; - FrameView _sizeFrame; + + Dictionary _viewClasses; RadioGroup _wRadioGroup; TextField _wText; - int _wVal = 0; - RadioGroup _hRadioGroup; - TextField _hText; - int _hVal = 0; + int _wVal; + RadioGroup _xRadioGroup; + TextField _xText; + int _xVal; + RadioGroup _yRadioGroup; + TextField _yText; + int _yVal; public override void Init () { @@ -62,9 +63,9 @@ public class AllViewsTester : Scenario { Application.Top.Add (statusBar); _viewClasses = GetAllViewClassesCollection () - .OrderBy (t => t.Name) - .Select (t => new KeyValuePair (t.Name, t)) - .ToDictionary (t => t.Key, t => t.Value); + .OrderBy (t => t.Name) + .Select (t => new KeyValuePair (t.Name, t)) + .ToDictionary (t => t.Key, t => t.Value); _leftPane = new FrameView ("Classes") { X = 0, @@ -78,8 +79,8 @@ public class AllViewsTester : Scenario { _classListView = new ListView (_viewClasses.Keys.ToList ()) { X = 0, Y = 0, - Width = Dim.Fill (0), - Height = Dim.Fill (0), + Width = Dim.Fill (), + Height = Dim.Fill (), AllowsMarking = false, ColorScheme = Colors.ColorSchemes ["TopLevel"], SelectedItem = 0 @@ -108,7 +109,7 @@ public class AllViewsTester : Scenario { CanFocus = false, ColorScheme = Colors.ColorSchemes ["TopLevel"] }; - _computedCheckBox = new CheckBox ("Computed Layout", true) { X = 0, Y = 0 }; + _computedCheckBox = new CheckBox ("_Computed Layout", true) { X = 0, Y = 0 }; _computedCheckBox.Toggled += (s, e) => { if (_curView != null) { _hostPane.LayoutSubviews (); @@ -116,7 +117,7 @@ public class AllViewsTester : Scenario { }; _settingsPane.Add (_computedCheckBox); - string [] radioItems = new string [] { "Percent(x)", "AnchorEnd(x)", "Center", "At(x)" }; + string [] radioItems = { "_Percent(x)", "_AnchorEnd(x)", "_Center", "A_t(x)" }; _locationFrame = new FrameView ("Location (Pos)") { X = Pos.Left (_computedCheckBox), Y = Pos.Bottom (_computedCheckBox), @@ -125,7 +126,7 @@ public class AllViewsTester : Scenario { }; _settingsPane.Add (_locationFrame); - var label = new Label ("x:") { X = 0, Y = 0 }; + var label = new Label ("X:") { X = 0, Y = 0 }; _locationFrame.Add (label); _xRadioGroup = new RadioGroup (radioItems) { X = 0, @@ -143,8 +144,8 @@ public class AllViewsTester : Scenario { _locationFrame.Add (_xRadioGroup); - radioItems = new string [] { "Percent(y)", "AnchorEnd(y)", "Center", "At(y)" }; - label = new Label ("y:") { X = Pos.Right (_xRadioGroup) + 1, Y = 0 }; + radioItems = new [] { "P_ercent(y)", "A_nchorEnd(y)", "C_enter", "At(_y)" }; + label = new Label ("Y:") { X = Pos.Right (_xRadioGroup) + 1, Y = 0 }; _locationFrame.Add (label); _yText = new TextField ($"{_yVal}") { X = Pos.Right (label) + 1, Y = 0, Width = 4 }; _yText.TextChanged += (s, args) => { @@ -168,8 +169,8 @@ public class AllViewsTester : Scenario { Width = 40 }; - radioItems = new string [] { "Percent(width)", "Fill(width)", "Sized(width)" }; - label = new Label ("width:") { X = 0, Y = 0 }; + radioItems = new [] { "_Percent(width)", "_Fill(width)", "_Sized(width)" }; + label = new Label ("Width:") { X = 0, Y = 0 }; _sizeFrame.Add (label); _wRadioGroup = new RadioGroup (radioItems) { X = 0, @@ -194,8 +195,8 @@ public class AllViewsTester : Scenario { _sizeFrame.Add (_wText); _sizeFrame.Add (_wRadioGroup); - radioItems = new string [] { "Percent(height)", "Fill(height)", "Sized(height)" }; - label = new Label ("height:") { X = Pos.Right (_wRadioGroup) + 1, Y = 0 }; + radioItems = new [] { "P_ercent(height)", "F_ill(height)", "Si_zed(height)" }; + label = new Label ("Height:") { X = Pos.Right (_wRadioGroup) + 1, Y = 0 }; _sizeFrame.Add (label); _hText = new TextField ($"{_hVal}") { X = Pos.Right (label) + 1, Y = 0, Width = 4 }; _hText.TextChanged += (s, args) => { @@ -278,27 +279,21 @@ public class AllViewsTester : Scenario { }; } catch (Exception e) { MessageBox.ErrorQuery ("Exception", e.Message, "Ok"); - } finally { - //view.LayoutStyle = layout; } UpdateTitle (view); } - // TODO: This is missing some - List _posNames = new () { "Factor", "AnchorEnd", "Center", "Absolute" }; - List _dimNames = new () { "Factor", "Fill", "Absolute" }; - void UpdateSettings (View view) { - string x = view.X.ToString (); - string y = view.Y.ToString (); + var x = view.X.ToString (); + var y = view.Y.ToString (); _xRadioGroup.SelectedItem = _posNames.IndexOf (_posNames.Where (s => x.Contains (s)).First ()); _yRadioGroup.SelectedItem = _posNames.IndexOf (_posNames.Where (s => y.Contains (s)).First ()); _xText.Text = $"{view.Frame.X}"; _yText.Text = $"{view.Frame.Y}"; - string w = view.Width.ToString (); - string h = view.Height.ToString (); + var w = view.Width.ToString (); + var h = view.Height.ToString (); _wRadioGroup.SelectedItem = _dimNames.IndexOf (_dimNames.Where (s => w.Contains (s)).First ()); _hRadioGroup.SelectedItem = _dimNames.IndexOf (_dimNames.Where (s => h.Contains (s)).First ()); _wText.Text = $"{view.Frame.Width}"; @@ -311,7 +306,7 @@ public class AllViewsTester : Scenario { { var types = new List (); foreach (var type in typeof (View).Assembly.GetTypes () - .Where (myType => myType.IsClass && !myType.IsAbstract && myType.IsPublic && myType.IsSubclassOf (typeof (View)))) { + .Where (myType => myType.IsClass && !myType.IsAbstract && myType.IsPublic && myType.IsSubclassOf (typeof (View)))) { types.Add (type); } types.Add (typeof (View)); @@ -364,7 +359,7 @@ public class AllViewsTester : Scenario { // If the view supports a Source property, set it so we have something to look at if (view != null && view.GetType ().GetProperty ("Source") != null && view.GetType ().GetProperty ("Source").PropertyType == typeof (IListDataSource)) { - var source = new ListWrapper (new List () { "Test Text #1", "Test Text #2", "Test Text #3" }); + var source = new ListWrapper (new List { "Test Text #1", "Test Text #2", "Test Text #3" }); view?.GetType ().GetProperty ("Source")?.GetSetMethod ()?.Invoke (view, new [] { source }); } diff --git a/UICatalog/Scenarios/Buttons.cs b/UICatalog/Scenarios/Buttons.cs index 6966cd857..46666e6b9 100644 --- a/UICatalog/Scenarios/Buttons.cs +++ b/UICatalog/Scenarios/Buttons.cs @@ -3,8 +3,7 @@ using Terminal.Gui; namespace UICatalog.Scenarios; [ScenarioMetadata (Name: "Buttons", Description: "Demonstrates all sorts of Buttons.")] -[ScenarioCategory ("Controls")] -[ScenarioCategory ("Layout")] +[ScenarioCategory ("Controls"), ScenarioCategory ("Layout")] public class Buttons : Scenario { public override void Setup () { @@ -32,7 +31,7 @@ public class Buttons : Scenario { defaultButton.Clicked += (s, e) => Application.RequestStop (); Win.Add (defaultButton); - var swapButton = new Button (50, 0, "Swap Default (Absolute Layout)"); + var swapButton = new Button (50, 0, "S_wap Default (Absolute Layout)"); swapButton.Clicked += (s, e) => { defaultButton.IsDefault = !defaultButton.IsDefault; swapButton.IsDefault = !swapButton.IsDefault; @@ -58,7 +57,7 @@ public class Buttons : Scenario { //With this method there is no need to call Application.TopReady += () => Application.TopRedraw (Top.Bounds); var x = Pos.Right (colorButtonsLabel) + 2; foreach (var colorScheme in Colors.ColorSchemes) { - var colorButton = new Button ($"{colorScheme.Key}") { + var colorButton = new Button ($"_{colorScheme.Key}") { ColorScheme = colorScheme.Value, //X = Pos.Right (prev) + 2, X = x, @@ -119,7 +118,7 @@ public class Buttons : Scenario { Win.Add (computedFrame); // Demonstrates how changing the View.Frame property can move Views - var moveBtn = new Button ("Move This \u263b Button _via Pos") { + var moveBtn = new Button ("Move This \u263b Button v_ia Pos") { X = 0, Y = Pos.Center () - 1, Width = 30, @@ -163,7 +162,7 @@ public class Buttons : Scenario { absoluteFrame.Add (moveBtnA); // Demonstrates how changing the View.Frame property can SIZE Views (#583) - var sizeBtnA = new Button (0, 2, " ~  s  gui.cs   master ↑10 = Со_хранить") { + var sizeBtnA = new Button (0, 2, " ~  s  gui.cs   master ↑_10 = Сохранить") { ColorScheme = Colors.ColorSchemes ["Error"], }; sizeBtnA.Clicked += (s, e) => { diff --git a/UICatalog/Scenarios/Dialogs.cs b/UICatalog/Scenarios/Dialogs.cs index 382c3c43e..445b8cdf5 100644 --- a/UICatalog/Scenarios/Dialogs.cs +++ b/UICatalog/Scenarios/Dialogs.cs @@ -108,14 +108,14 @@ namespace UICatalog.Scenarios { }; frame.Add (label); - var styleRadioGroup = new RadioGroup (new string [] { "Center", "Justify", "Left", "Right" }) { + var styleRadioGroup = new RadioGroup (new string [] { "_Center", "_Justify", "_Left", "_Right" }) { X = Pos.Right (label) + 1, Y = Pos.Top (label), }; frame.Add (styleRadioGroup); frame.ValidatePosDim = true; - void Top_Loaded (object sender, EventArgs args) + void Top_LayoutComplete (object sender, EventArgs args) { frame.Height = widthEdit.Frame.Height + @@ -123,10 +123,9 @@ namespace UICatalog.Scenarios { titleEdit.Frame.Height + numButtonsEdit.Frame.Height + glyphsNotWords.Frame.Height + - styleRadioGroup.Frame.Height; - Application.Top.Loaded -= Top_Loaded; + styleRadioGroup.Frame.Height + frame.GetAdornmentsThickness().Vertical; } - Application.Top.Loaded += Top_Loaded; + Application.Top.LayoutComplete += Top_LayoutComplete; Win.Add (frame); @@ -150,7 +149,7 @@ namespace UICatalog.Scenarios { // true: var btnText = new [] { "0", "\u2780", "➁", "\u2783", "\u2784", "\u2785", "\u2786", "\u2787", "\u2788", "\u2789" }; // \u2781 is ➁ dingbats \ufb70 is - var showDialogButton = new Button ("Show Dialog") { + var showDialogButton = new Button ("_Show Dialog") { X = Pos.Center (), Y = Pos.Bottom (frame) + 2, IsDefault = true, diff --git a/UICatalog/Scenarios/MessageBoxes.cs b/UICatalog/Scenarios/MessageBoxes.cs index bbd781b50..f4fc75dd9 100644 --- a/UICatalog/Scenarios/MessageBoxes.cs +++ b/UICatalog/Scenarios/MessageBoxes.cs @@ -14,7 +14,6 @@ namespace UICatalog.Scenarios { X = Pos.Center (), Y = 1, Width = Dim.Percent (75), - Height = 12 }; Win.Add (frame); @@ -140,14 +139,14 @@ namespace UICatalog.Scenarios { }; frame.Add (styleRadioGroup); - var ckbWrapMessage = new CheckBox ("Wrap Message", true) { + var ckbWrapMessage = new CheckBox ("_Wrap Message", true) { X = Pos.Right (label) + 1, - Y = Pos.Top (label) + 3 + Y = Pos.Bottom (styleRadioGroup) }; frame.Add (ckbWrapMessage); frame.ValidatePosDim = true; - void Top_Loaded (object sender, EventArgs args) + void Top_LayoutComplete (object sender, EventArgs args) { frame.Height = widthEdit.Frame.Height + @@ -157,22 +156,22 @@ namespace UICatalog.Scenarios { numButtonsEdit.Frame.Height + defaultButtonEdit.Frame.Height + styleRadioGroup.Frame.Height + - 2 + - ckbWrapMessage.Frame.Height; - Application.Top.Loaded -= Top_Loaded; + ckbWrapMessage.Frame.Height + + frame.GetAdornmentsThickness ().Vertical; + Application.Top.Loaded -= Top_LayoutComplete; } - //Application.Top.Loaded += Top_Loaded; + Application.Top.LayoutComplete += Top_LayoutComplete; label = new Label ("Button Pressed:") { X = Pos.Center (), - Y = Pos.Bottom (frame) + 4, + Y = Pos.Bottom (frame) + 2, Height = 1, TextAlignment = Terminal.Gui.TextAlignment.Right, }; Win.Add (label); var buttonPressedLabel = new Label (" ") { X = Pos.Center (), - Y = Pos.Bottom (frame) + 5, + Y = Pos.Bottom (label) + 1, Width = 25, Height = 1, ColorScheme = Colors.ColorSchemes ["Error"], @@ -181,12 +180,12 @@ namespace UICatalog.Scenarios { //var btnText = new [] { "_Zero", "_One", "T_wo", "_Three", "_Four", "Fi_ve", "Si_x", "_Seven", "_Eight", "_Nine" }; - var showMessageBoxButton = new Button ("Show MessageBox") { + var showMessageBoxButton = new Button ("_Show MessageBox") { X = Pos.Center (), Y = Pos.Bottom (frame) + 2, IsDefault = true, }; - showMessageBoxButton.Clicked += (s,e) => { + showMessageBoxButton.Clicked += (s, e) => { try { int width = int.Parse (widthEdit.Text); int height = int.Parse (heightEdit.Text); diff --git a/UnitTests/Text/TextFormatterTests.cs b/UnitTests/Text/TextFormatterTests.cs index 482c967dc..4d7fa23ef 100644 --- a/UnitTests/Text/TextFormatterTests.cs +++ b/UnitTests/Text/TextFormatterTests.cs @@ -287,7 +287,7 @@ public class TextFormatterTests { Key hotKey = KeyCode.Null; var result = false; - result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out hotPos, out hotKey); + result = TextFormatter.FindHotKey (text, hotKeySpecifier, out hotPos, out hotKey, supportFirstUpperCase); Assert.False (result); Assert.Equal (-1, hotPos); Assert.Equal (KeyCode.Null, hotKey); @@ -310,7 +310,7 @@ public class TextFormatterTests { { var hotKeySpecifier = (Rune)'_'; - var result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out var hotPos, out var hotKey); + var result = TextFormatter.FindHotKey (text, hotKeySpecifier, out var hotPos, out var hotKey, supportFirstUpperCase); if (expectedResult) { Assert.True (result); } else { @@ -338,7 +338,7 @@ public class TextFormatterTests { { var hotKeySpecifier = (Rune)'_'; - var result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out var hotPos, out var hotKey); + var result = TextFormatter.FindHotKey (text, hotKeySpecifier, out var hotPos, out var hotKey, supportFirstUpperCase); if (expectedResult) { Assert.True (result); } else { @@ -364,7 +364,7 @@ public class TextFormatterTests { { var hotKeySpecifier = (Rune)'_'; - var result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out var hotPos, out var hotKey); + var result = TextFormatter.FindHotKey (text, hotKeySpecifier, out var hotPos, out var hotKey, supportFirstUpperCase); if (expectedResult) { Assert.True (result); } else { @@ -387,7 +387,7 @@ public class TextFormatterTests { var hotKeySpecifier = (Rune)0; - var result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out var hotPos, out var hotKey); + var result = TextFormatter.FindHotKey (text, hotKeySpecifier, out var hotPos, out var hotKey, supportFirstUpperCase); if (expectedResult) { Assert.True (result); } else { @@ -411,7 +411,7 @@ public class TextFormatterTests { { var hotKeySpecifier = (Rune)'_'; - var result = TextFormatter.FindHotKey (text, hotKeySpecifier, false, out var _, out var hotKey); + var result = TextFormatter.FindHotKey (text, hotKeySpecifier, out var _, out var hotKey, false); Assert.Equal (found, result); Assert.Equal (expected, hotKey); } @@ -431,7 +431,7 @@ public class TextFormatterTests { var hotKeySpecifier = (Rune)0; - var result = TextFormatter.FindHotKey (text, hotKeySpecifier, supportFirstUpperCase, out var hotPos, out var hotKey); + var result = TextFormatter.FindHotKey (text, hotKeySpecifier, out var hotPos, out var hotKey, supportFirstUpperCase); Assert.False (result); Assert.Equal (-1, hotPos); Assert.Equal (KeyCode.Null, hotKey); diff --git a/UnitTests/View/DrawTests.cs b/UnitTests/View/DrawTests.cs index b14bef730..f6bdae0da 100644 --- a/UnitTests/View/DrawTests.cs +++ b/UnitTests/View/DrawTests.cs @@ -1,8 +1,6 @@ using System.Text; -using System; using Xunit; using Xunit.Abstractions; -using Microsoft.VisualStudio.TestPlatform.Utilities; namespace Terminal.Gui.ViewsTests; @@ -382,6 +380,18 @@ t ", _output); TestHelpers.AssertDriverContentsWithFrameAre ("", _output); } + [Theory, SetupFakeDriver] + [InlineData ("𝔽𝕆𝕆𝔹𝔸R")] + [InlineData ("a𐐀b")] + void DrawHotString_NonBmp (string expected) + { + var view = new View () { Width = 10, Height = 1 }; + view.DrawHotString (expected, Attribute.Default, Attribute.Default); + + TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); + + } + [Fact, AutoInitShutdown] public void Draw_Minimum_Full_Border_With_Empty_Bounds () { @@ -512,4 +522,4 @@ t ", _output); │Test│ └────┘", _output); } -} +} \ No newline at end of file diff --git a/UnitTests/View/HotKeyTests.cs b/UnitTests/View/HotKeyTests.cs index 6f36fff95..e9c00cb95 100644 --- a/UnitTests/View/HotKeyTests.cs +++ b/UnitTests/View/HotKeyTests.cs @@ -208,13 +208,13 @@ public class HotKeyTests { } [Theory] - [InlineData ("Test", KeyCode.T)] + [InlineData ("Test", KeyCode.Null)] [InlineData ("^Test", KeyCode.T)] [InlineData ("T^est", KeyCode.E)] [InlineData ("Te^st", KeyCode.S)] [InlineData ("Tes^t", KeyCode.T)] [InlineData ("other", KeyCode.Null)] - [InlineData ("oTher", KeyCode.T)] + [InlineData ("oTher", KeyCode.Null)] [InlineData ("^Öther", (KeyCode)'Ö')] [InlineData ("^öther", (KeyCode)'ö')] // BUGBUG: '!' should be supported. Line 968 of TextFormatter filters on char.IsLetterOrDigit diff --git a/UnitTests/Views/ButtonTests.cs b/UnitTests/Views/ButtonTests.cs index 072ec55ab..d545c4c09 100644 --- a/UnitTests/Views/ButtonTests.cs +++ b/UnitTests/Views/ButtonTests.cs @@ -1,23 +1,28 @@ using Xunit; using Xunit.Abstractions; -namespace Terminal.Gui.ViewsTests; +namespace Terminal.Gui.ViewsTests; + public class ButtonTests { - readonly ITestOutputHelper output; + readonly ITestOutputHelper _output; - public ButtonTests (ITestOutputHelper output) - { - this.output = output; - } + public ButtonTests (ITestOutputHelper output) => _output = output; - [Fact, AutoInitShutdown] + [Fact] [SetupFakeDriver] public void Constructors_Defaults () { var btn = new Button (); Assert.Equal (string.Empty, btn.Text); - Application.Top.Add (btn); - var rs = Application.Begin (Application.Top); + btn.BeginInit (); + btn.EndInit (); + Assert.Equal ($"{CM.Glyphs.LeftBracket} {CM.Glyphs.RightBracket}", btn.TextFormatter.Text); + Assert.False (btn.IsDefault); + Assert.Equal (TextAlignment.Centered, btn.TextAlignment); + Assert.Equal ('_', btn.HotKeySpecifier.Value); + Assert.True (btn.CanFocus); + Assert.Equal (new Rect (0, 0, 4, 1), btn.Bounds); + Assert.Equal (new Rect (0, 0, 4, 1), btn.Frame); Assert.Equal ($"{CM.Glyphs.LeftBracket} {CM.Glyphs.RightBracket}", btn.TextFormatter.Text); Assert.False (btn.IsDefault); Assert.Equal (TextAlignment.Centered, btn.TextAlignment); @@ -29,42 +34,50 @@ public class ButtonTests { Assert.Equal (string.Empty, btn.Title); Assert.Equal (KeyCode.Null, btn.HotKey); + btn.Draw (); + var expected = @$" {CM.Glyphs.LeftBracket} {CM.Glyphs.RightBracket} "; - TestHelpers.AssertDriverContentsWithFrameAre (expected, output); - Application.End (rs); + TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - btn = new Button ("ARGS", true) { Text = "Test" }; - Assert.Equal ("Test", btn.Text); - Application.Top.Add (btn); - rs = Application.Begin (Application.Top); + btn = new Button ("ARGS", true) { Text = "_Test" }; + btn.BeginInit (); + btn.EndInit (); + Assert.Equal ('_', btn.HotKeySpecifier.Value); + Assert.Equal (Key.T, btn.HotKey); + Assert.Equal ("_Test", btn.Text); - Assert.Equal ($"{CM.Glyphs.LeftBracket}{CM.Glyphs.LeftDefaultIndicator} Test {CM.Glyphs.RightDefaultIndicator}{CM.Glyphs.RightBracket}", btn.TextFormatter.Text); + Assert.Equal ($"{CM.Glyphs.LeftBracket}{CM.Glyphs.LeftDefaultIndicator} Test {CM.Glyphs.RightDefaultIndicator}{CM.Glyphs.RightBracket}", btn.TextFormatter.Format ()); Assert.True (btn.IsDefault); Assert.Equal (TextAlignment.Centered, btn.TextAlignment); - Assert.Equal ('_', btn.HotKeySpecifier.Value); Assert.True (btn.CanFocus); Assert.Equal (new Rect (0, 0, 10, 1), btn.Bounds); Assert.Equal (new Rect (0, 0, 10, 1), btn.Frame); Assert.Equal (KeyCode.T, btn.HotKey); - Application.End (rs); - btn = new Button (3, 4, "Test", true); - Assert.Equal ("Test", btn.Text); - Application.Top.Add (btn); - rs = Application.Begin (Application.Top); + btn = new Button (1, 2, "_abc", true); + btn.BeginInit (); + btn.EndInit (); + Assert.Equal ("_abc", btn.Text); + Assert.Equal (Key.A, btn.HotKey); - Assert.Equal ($"{CM.Glyphs.LeftBracket}{CM.Glyphs.LeftDefaultIndicator} Test {CM.Glyphs.RightDefaultIndicator}{CM.Glyphs.RightBracket}", btn.TextFormatter.Text); + Assert.Equal ($"{CM.Glyphs.LeftBracket}{CM.Glyphs.LeftDefaultIndicator} abc {CM.Glyphs.RightDefaultIndicator}{CM.Glyphs.RightBracket}", btn.TextFormatter.Format ()); Assert.True (btn.IsDefault); Assert.Equal (TextAlignment.Centered, btn.TextAlignment); Assert.Equal ('_', btn.HotKeySpecifier.Value); Assert.True (btn.CanFocus); - Assert.Equal (new Rect (0, 0, 10, 1), btn.Bounds); - Assert.Equal (new Rect (3, 4, 10, 1), btn.Frame); - Assert.Equal (KeyCode.T, btn.HotKey); - Application.End (rs); + Application.Driver.ClearContents (); + btn.Draw (); + + expected = @$" + {CM.Glyphs.LeftBracket}{CM.Glyphs.LeftDefaultIndicator} abc {CM.Glyphs.RightDefaultIndicator}{CM.Glyphs.RightBracket} +"; + TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); + + Assert.Equal (new Rect (0, 0, 10, 1), btn.Bounds); + Assert.Equal (new Rect (1, 2, 10, 1), btn.Frame); } [Fact] @@ -72,21 +85,24 @@ public class ButtonTests { public void KeyBindings_Command () { var clicked = false; - Button btn = new Button ("_Test"); + var btn = new Button ("_Test"); btn.Clicked += (s, e) => clicked = true; Application.Top.Add (btn); Application.Begin (Application.Top); // Hot key. Both alone and with alt Assert.Equal (KeyCode.T, btn.HotKey); - Assert.True (btn.NewKeyDownEvent (new (KeyCode.T))); + Assert.True (btn.NewKeyDownEvent (new Key (KeyCode.T))); Assert.True (clicked); clicked = false; - Assert.True (btn.NewKeyDownEvent (new (KeyCode.T | KeyCode.AltMask))); + Assert.True (btn.NewKeyDownEvent (new Key (KeyCode.T | KeyCode.AltMask))); Assert.True (clicked); clicked = false; + Assert.True (btn.NewKeyDownEvent (btn.HotKey)); + Assert.True (clicked); + clicked = false; Assert.True (btn.NewKeyDownEvent (btn.HotKey)); Assert.True (clicked); clicked = false; @@ -94,32 +110,32 @@ public class ButtonTests { // IsDefault = false // Space and Enter should work Assert.False (btn.IsDefault); - Assert.True (btn.NewKeyDownEvent (new (KeyCode.Enter))); + Assert.True (btn.NewKeyDownEvent (new Key (KeyCode.Enter))); Assert.True (clicked); clicked = false; // IsDefault = true // Space and Enter should work btn.IsDefault = true; - Assert.True (btn.NewKeyDownEvent (new (KeyCode.Enter))); + Assert.True (btn.NewKeyDownEvent (new Key (KeyCode.Enter))); Assert.True (clicked); clicked = false; // Toplevel does not handle Enter, so it should get passed on to button - Assert.True (Application.Top.NewKeyDownEvent (new (KeyCode.Enter))); + Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.Enter))); Assert.True (clicked); clicked = false; // Direct - Assert.True (btn.NewKeyDownEvent (new (KeyCode.Enter))); + Assert.True (btn.NewKeyDownEvent (new Key (KeyCode.Enter))); Assert.True (clicked); clicked = false; - Assert.True (btn.NewKeyDownEvent (new (KeyCode.Space))); + Assert.True (btn.NewKeyDownEvent (new Key (KeyCode.Space))); Assert.True (clicked); clicked = false; - Assert.True (btn.NewKeyDownEvent (new ((KeyCode)'T'))); + Assert.True (btn.NewKeyDownEvent (new Key ((KeyCode)'T'))); Assert.True (clicked); clicked = false; @@ -135,22 +151,22 @@ public class ButtonTests { public void HotKeyChange_Works () { var clicked = false; - Button btn = new Button ("Test"); + var btn = new Button ("_Test"); btn.Clicked += (s, e) => clicked = true; Application.Top.Add (btn); Application.Begin (Application.Top); Assert.Equal (KeyCode.T, btn.HotKey); - Assert.True (btn.NewKeyDownEvent (new (KeyCode.T))); + Assert.True (btn.NewKeyDownEvent (new Key (KeyCode.T))); Assert.True (clicked); clicked = false; - Assert.True (btn.NewKeyDownEvent (new (KeyCode.T | KeyCode.AltMask))); + Assert.True (btn.NewKeyDownEvent (new Key (KeyCode.T | KeyCode.AltMask))); Assert.True (clicked); clicked = false; btn.HotKey = KeyCode.E; - Assert.True (btn.NewKeyDownEvent (new (KeyCode.E | KeyCode.AltMask))); + Assert.True (btn.NewKeyDownEvent (new Key (KeyCode.E | KeyCode.AltMask))); Assert.True (clicked); } @@ -162,7 +178,7 @@ public class ButtonTests { [AutoInitShutdown] public void KeyBindingExample () { - int pressed = 0; + var pressed = 0; var btn = new Button ("Press Me"); btn.Clicked += (s, e) => pressed++; @@ -171,44 +187,46 @@ public class ButtonTests { Assert.Contains (Command.Default, btn.GetSupportedCommands ()); Assert.Contains (Command.Accept, btn.GetSupportedCommands ()); + Application.Top.Add (btn); + Application.Begin (Application.Top); Application.Top.Add (btn); Application.Begin (Application.Top); // default keybinding is Space which results in keypress - Application.OnKeyDown (new ((KeyCode)' ')); + Application.OnKeyDown (new Key ((KeyCode)' ')); Assert.Equal (1, pressed); // remove the default keybinding (Space) btn.KeyBindings.Clear (Command.Default, Command.Accept); // After clearing the default keystroke the Space button no longer does anything for the Button - Application.OnKeyDown (new ((KeyCode)' ')); + Application.OnKeyDown (new Key ((KeyCode)' ')); Assert.Equal (1, pressed); // Set a new binding of b for the click (Accept) event btn.KeyBindings.Add (KeyCode.B, Command.Default, Command.Accept); // now pressing B should call the button click event - Application.OnKeyDown (new (KeyCode.B)); + Application.OnKeyDown (new Key (KeyCode.B)); Assert.Equal (2, pressed); // now pressing Shift-B should NOT call the button click event - Application.OnKeyDown (new (KeyCode.ShiftMask | KeyCode.B)); + Application.OnKeyDown (new Key (KeyCode.ShiftMask | KeyCode.B)); Assert.Equal (2, pressed); // now pressing Alt-B should NOT call the button click event - Application.OnKeyDown (new (KeyCode.AltMask | KeyCode.B)); + Application.OnKeyDown (new Key (KeyCode.AltMask | KeyCode.B)); Assert.Equal (2, pressed); // now pressing Shift-Alt-B should NOT call the button click event - Application.OnKeyDown (new (KeyCode.ShiftMask | KeyCode.AltMask | KeyCode.B)); + Application.OnKeyDown (new Key (KeyCode.ShiftMask | KeyCode.AltMask | KeyCode.B)); Assert.Equal (2, pressed); } [Fact] public void TestAssignTextToButton () { - View b = new Button () { Text = "heya" }; + View b = new Button { Text = "heya" }; Assert.Equal ("heya", b.Text); Assert.Contains ("heya", b.TextFormatter.Text); b.Text = "heyb"; @@ -223,14 +241,17 @@ public class ButtonTests { public void Setting_Empty_Text_Sets_HoKey_To_KeyNull () { var super = new View (); - var btn = new Button ("Test"); + var btn = new Button ("_Test"); super.Add (btn); super.BeginInit (); super.EndInit (); - Assert.Equal ("Test", btn.Text); + Assert.Equal ("_Test", btn.Text); Assert.Equal (KeyCode.T, btn.HotKey); + btn.Text = string.Empty; + Assert.Equal ("", btn.Text); + Assert.Equal (KeyCode.Null, btn.HotKey); btn.Text = string.Empty; Assert.Equal ("", btn.Text); Assert.Equal (KeyCode.Null, btn.HotKey); @@ -247,15 +268,18 @@ public class ButtonTests { X = Pos.Center (), Y = Pos.Center () }; - var win = new Window () { + var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () }; win.Add (btn); Application.Top.Add (win); + Assert.False (btn.IsInitialized); Assert.False (btn.IsInitialized); + Application.Begin (Application.Top); + ((FakeDriver)Application.Driver).SetBufferSize (30, 5); Application.Begin (Application.Top); ((FakeDriver)Application.Driver).SetBufferSize (30, 5); @@ -272,27 +296,30 @@ public class ButtonTests { └────────────────────────────┘ "; - var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (0, 0, 30, 5), pos); } [Fact, AutoInitShutdown] public void Update_Parameterless_Only_On_Or_After_Initialize () { - var btn = new Button () { + var btn = new Button { X = Pos.Center (), Y = Pos.Center (), Text = "Say Hello 你" }; - var win = new Window () { + var win = new Window { Width = Dim.Fill (), - Height = Dim.Fill (), + Height = Dim.Fill () }; win.Add (btn); Application.Top.Add (win); + Assert.False (btn.IsInitialized); Assert.False (btn.IsInitialized); + Application.Begin (Application.Top); + ((FakeDriver)Application.Driver).SetBufferSize (30, 5); Application.Begin (Application.Top); ((FakeDriver)Application.Driver).SetBufferSize (30, 5); @@ -309,30 +336,33 @@ public class ButtonTests { └────────────────────────────┘ "; - var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (0, 0, 30, 5), pos); } [Fact, AutoInitShutdown] public void AutoSize_Stays_True_With_EmptyText () { - var btn = new Button () { + var btn = new Button { X = Pos.Center (), Y = Pos.Center (), AutoSize = true }; - var win = new Window () { + var win = new Window { Width = Dim.Fill (), - Height = Dim.Fill (), + Height = Dim.Fill () }; win.Add (btn); Application.Top.Add (win); + Assert.True (btn.AutoSize); Assert.True (btn.AutoSize); + btn.Text = "Say Hello 你"; btn.Text = "Say Hello 你"; + Assert.True (btn.AutoSize); Assert.True (btn.AutoSize); Application.Begin (Application.Top); @@ -345,25 +375,26 @@ public class ButtonTests { └────────────────────────────┘ "; - TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); } [Fact, AutoInitShutdown] public void AutoSize_Stays_True_Center () { - var btn = new Button () { + var btn = new Button { X = Pos.Center (), Y = Pos.Center (), Text = "Say Hello 你" }; - var win = new Window () { + var win = new Window { Width = Dim.Fill (), - Height = Dim.Fill (), + Height = Dim.Fill () }; win.Add (btn); Application.Top.Add (win); + Assert.True (btn.AutoSize); Assert.True (btn.AutoSize); Application.Begin (Application.Top); @@ -376,7 +407,7 @@ public class ButtonTests { └────────────────────────────┘ "; - TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.True (btn.AutoSize); btn.Text = "Say Hello 你 changed"; @@ -390,28 +421,30 @@ public class ButtonTests { └────────────────────────────┘ "; - TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); } - [Fact, AutoInitShutdown] + [Fact] [AutoInitShutdown] public void AutoSize_Stays_True_AnchorEnd () { - var btn = new Button () { + var btn = new Button { Y = Pos.Center (), Text = "Say Hello 你", AutoSize = true }; var btnTxt = $"{CM.Glyphs.LeftBracket} {btn.Text} {CM.Glyphs.RightBracket}"; + btn.X = Pos.AnchorEnd () - Pos.Function (() => btn.TextFormatter.Text.GetColumns ()); btn.X = Pos.AnchorEnd () - Pos.Function (() => btn.TextFormatter.Text.GetColumns ()); - var win = new Window () { + var win = new Window { Width = Dim.Fill (), - Height = Dim.Fill (), + Height = Dim.Fill () }; win.Add (btn); Application.Top.Add (win); + Assert.True (btn.AutoSize); Assert.True (btn.AutoSize); Application.Begin (Application.Top); @@ -424,7 +457,7 @@ public class ButtonTests { └────────────────────────────┘ "; - TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.True (btn.AutoSize); btn.Text = "Say Hello 你 changed"; @@ -439,10 +472,10 @@ public class ButtonTests { └────────────────────────────┘ "; - TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); } - [Fact, AutoInitShutdown] + [Fact] [AutoInitShutdown] public void AutoSize_False_With_Fixed_Width () { var tab = new View (); @@ -508,13 +541,13 @@ public class ButtonTests { }; tab.Add (ckbMatchWholeWord); - var tabView = new TabView () { + var tabView = new TabView { Width = Dim.Fill (), Height = Dim.Fill () }; tabView.AddTab (new Tab () { DisplayText = "Find", View = tab }, true); - var win = new Window () { + var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () }; @@ -559,10 +592,10 @@ public class ButtonTests { └────────────────────────────────────────────────────┘ "; - TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); } - [Fact, AutoInitShutdown] + [Fact] [AutoInitShutdown] public void Pos_Center_Layout_AutoSize_True () { var button = new Button ("Process keys") { @@ -570,7 +603,7 @@ public class ButtonTests { Y = Pos.Center (), IsDefault = true }; - var win = new Window () { + var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () }; @@ -591,10 +624,10 @@ public class ButtonTests { └────────────────────────────┘ "; - TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); } - [Fact, AutoInitShutdown] + [Fact] [AutoInitShutdown] public void Pos_Center_Layout_AutoSize_False () { var button = new Button ("Process keys") { @@ -604,7 +637,7 @@ public class ButtonTests { IsDefault = true, AutoSize = false }; - var win = new Window () { + var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () }; @@ -623,29 +656,38 @@ public class ButtonTests { └────────────────────────────┘ "; - TestHelpers.AssertDriverContentsWithFrameAre (expected, output); + TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); } - [Fact, AutoInitShutdown] + + [Fact] [AutoInitShutdown] public void Button_HotKeyChanged_EventFires () { - var btn = new Button ("Yar"); + var btn = new Button ("_Yar"); object sender = null; KeyChangedEventArgs args = null; + btn.HotKeyChanged += (s, e) => { + sender = s; + args = e; btn.HotKeyChanged += (s, e) => { sender = s; args = e; }; + }; btn.HotKey = KeyCode.R; Assert.Same (btn, sender); Assert.Equal (KeyCode.Y, args.OldKey); Assert.Equal (KeyCode.R, args.NewKey); - + btn.HotKey = KeyCode.R; + Assert.Same (btn, sender); + Assert.Equal (KeyCode.Y, args.OldKey); + Assert.Equal (KeyCode.R, args.NewKey); } - [Fact, AutoInitShutdown] + + [Fact] [AutoInitShutdown] public void Button_HotKeyChanged_EventFires_WithNone () { var btn = new Button (); @@ -656,6 +698,7 @@ public class ButtonTests { btn.HotKeyChanged += (s, e) => { sender = s; args = e; + }; btn.HotKey = KeyCode.R; @@ -663,4 +706,4 @@ public class ButtonTests { Assert.Equal (KeyCode.Null, args.OldKey); Assert.Equal (KeyCode.R, args.NewKey); } -} +} \ No newline at end of file diff --git a/UnitTests/Views/CheckBoxTests.cs b/UnitTests/Views/CheckBoxTests.cs index dd78aec01..c22a7968a 100644 --- a/UnitTests/Views/CheckBoxTests.cs +++ b/UnitTests/Views/CheckBoxTests.cs @@ -1,19 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Xunit; +using Xunit; using Xunit.Abstractions; namespace Terminal.Gui.ViewsTests; + public class CheckboxTests { readonly ITestOutputHelper _output; - public CheckboxTests (ITestOutputHelper output) - { - this._output = output; - } + public CheckboxTests (ITestOutputHelper output) => _output = output; [Fact] public void Constructors_Defaults () @@ -60,7 +53,7 @@ public class CheckboxTests { public void KeyBindings_Command () { var toggled = false; - CheckBox ckb = new CheckBox (); + var ckb = new CheckBox (); ckb.Toggled += (s, e) => toggled = true; Application.Top.Add (ckb); Application.Begin (Application.Top); @@ -69,32 +62,32 @@ public class CheckboxTests { Assert.False (toggled); Assert.Equal (KeyCode.Null, ckb.HotKey); - ckb.Text = "Test"; + ckb.Text = "_Test"; Assert.Equal (KeyCode.T, ckb.HotKey); - Assert.True (Application.Top.NewKeyDownEvent (new (KeyCode.T))); + Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.T))); Assert.True (ckb.Checked); Assert.True (toggled); ckb.Text = "T_est"; toggled = false; Assert.Equal (KeyCode.E, ckb.HotKey); - Assert.True (Application.Top.NewKeyDownEvent (new (KeyCode.E | KeyCode.AltMask))); + Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.E | KeyCode.AltMask))); Assert.True (toggled); Assert.False (ckb.Checked); toggled = false; Assert.Equal (KeyCode.E, ckb.HotKey); - Assert.True (Application.Top.NewKeyDownEvent (new (KeyCode.E))); + Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.E))); Assert.True (toggled); Assert.True (ckb.Checked); toggled = false; - Assert.True (Application.Top.NewKeyDownEvent (new ((KeyCode)' '))); + Assert.True (Application.Top.NewKeyDownEvent (new Key ((KeyCode)' '))); Assert.True (toggled); Assert.False (ckb.Checked); toggled = false; - Assert.True (Application.Top.NewKeyDownEvent (new (KeyCode.Space))); + Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.Space))); Assert.True (toggled); Assert.True (ckb.Checked); Assert.True (ckb.AutoSize); @@ -109,15 +102,15 @@ public class CheckboxTests { Assert.Equal (new Rect (0, 0, 6, 1), pos); } - [Fact, AutoInitShutdown] + [Fact] [AutoInitShutdown] public void AutoSize_StaysVisible () { - var checkBox = new CheckBox () { + var checkBox = new CheckBox { X = 1, Y = Pos.Center (), Text = "Check this out 你" }; - var win = new Window () { + var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" @@ -186,17 +179,17 @@ public class CheckboxTests { Assert.Equal (new Rect (0, 0, 30, 5), pos); } - [Fact, AutoInitShutdown] + [Fact] [AutoInitShutdown] public void TextAlignment_Left () { - var checkBox = new CheckBox () { + var checkBox = new CheckBox { X = 1, Y = Pos.Center (), Text = "Check this out 你", AutoSize = false, Width = 25 }; - var win = new Window () { + var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" @@ -236,10 +229,10 @@ public class CheckboxTests { Assert.Equal (new Rect (0, 0, 30, 5), pos); } - [Fact, AutoInitShutdown] + [Fact] [AutoInitShutdown] public void TextAlignment_Centered () { - var checkBox = new CheckBox () { + var checkBox = new CheckBox { X = 1, Y = Pos.Center (), Text = "Check this out 你", @@ -247,7 +240,7 @@ public class CheckboxTests { AutoSize = false, Width = 25 }; - var win = new Window () { + var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" @@ -288,10 +281,10 @@ public class CheckboxTests { Assert.Equal (new Rect (0, 0, 30, 5), pos); } - [Fact, AutoInitShutdown] + [Fact] [AutoInitShutdown] public void TextAlignment_Justified () { - var checkBox1 = new CheckBox () { + var checkBox1 = new CheckBox { X = 1, Y = Pos.Center (), Text = "Check first out 你", @@ -299,7 +292,7 @@ public class CheckboxTests { AutoSize = false, Width = 25 }; - var checkBox2 = new CheckBox () { + var checkBox2 = new CheckBox { X = 1, Y = Pos.Bottom (checkBox1), Text = "Check second out 你", @@ -307,7 +300,7 @@ public class CheckboxTests { AutoSize = false, Width = 25 }; - var win = new Window () { + var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" @@ -357,10 +350,10 @@ public class CheckboxTests { Assert.Equal (new Rect (0, 0, 30, 6), pos); } - [Fact, AutoInitShutdown] + [Fact] [AutoInitShutdown] public void TextAlignment_Right () { - var checkBox = new CheckBox () { + var checkBox = new CheckBox { X = 1, Y = Pos.Center (), Text = "Check this out 你", @@ -368,7 +361,7 @@ public class CheckboxTests { AutoSize = false, Width = 25 }; - var win = new Window () { + var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" @@ -409,16 +402,16 @@ public class CheckboxTests { Assert.Equal (new Rect (0, 0, 30, 5), pos); } - [Fact, AutoInitShutdown] + [Fact] [AutoInitShutdown] public void AutoSize_Stays_True_AnchorEnd_Without_HotKeySpecifier () { - var checkBox = new CheckBox () { + var checkBox = new CheckBox { Y = Pos.Center (), Text = "Check this out 你" }; checkBox.X = Pos.AnchorEnd () - Pos.Function (() => checkBox.GetSizeNeededForTextWithoutHotKey ().Width); - var win = new Window () { + var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" @@ -455,16 +448,16 @@ public class CheckboxTests { TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); } - [Fact, AutoInitShutdown] + [Fact] [AutoInitShutdown] public void AutoSize_Stays_True_AnchorEnd_With_HotKeySpecifier () { - var checkBox = new CheckBox () { + var checkBox = new CheckBox { Y = Pos.Center (), Text = "C_heck this out 你" }; checkBox.X = Pos.AnchorEnd () - Pos.Function (() => checkBox.GetSizeNeededForTextWithoutHotKey ().Width); - var win = new Window () { + var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" @@ -501,7 +494,7 @@ public class CheckboxTests { TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); } - [Fact, AutoInitShutdown] + [Fact] [AutoInitShutdown] public void AllowNullChecked_Get_Set () { var checkBox = new CheckBox ("Check this out 你"); @@ -510,25 +503,25 @@ public class CheckboxTests { Application.Begin (top); Assert.False (checkBox.Checked); - Assert.True (checkBox.NewKeyDownEvent (new (KeyCode.Space))); + Assert.True (checkBox.NewKeyDownEvent (new Key (KeyCode.Space))); Assert.True (checkBox.Checked); - Assert.True (checkBox.MouseEvent (new MouseEvent () { X = 0, Y = 0, Flags = MouseFlags.Button1Clicked })); + Assert.True (checkBox.MouseEvent (new MouseEvent { X = 0, Y = 0, Flags = MouseFlags.Button1Clicked })); Assert.False (checkBox.Checked); checkBox.AllowNullChecked = true; - Assert.True (checkBox.NewKeyDownEvent (new (KeyCode.Space))); + Assert.True (checkBox.NewKeyDownEvent (new Key (KeyCode.Space))); Assert.Null (checkBox.Checked); Application.Refresh (); TestHelpers.AssertDriverContentsWithFrameAre (@$" {CM.Glyphs.NullChecked} Check this out 你", _output); - Assert.True (checkBox.MouseEvent (new MouseEvent () { X = 0, Y = 0, Flags = MouseFlags.Button1Clicked })); + Assert.True (checkBox.MouseEvent (new MouseEvent { X = 0, Y = 0, Flags = MouseFlags.Button1Clicked })); Assert.True (checkBox.Checked); - Assert.True (checkBox.NewKeyDownEvent (new (KeyCode.Space))); + Assert.True (checkBox.NewKeyDownEvent (new Key (KeyCode.Space))); Assert.False (checkBox.Checked); - Assert.True (checkBox.MouseEvent (new MouseEvent () { X = 0, Y = 0, Flags = MouseFlags.Button1Clicked })); + Assert.True (checkBox.MouseEvent (new MouseEvent { X = 0, Y = 0, Flags = MouseFlags.Button1Clicked })); Assert.Null (checkBox.Checked); checkBox.AllowNullChecked = false; Assert.False (checkBox.Checked); } -} +} \ No newline at end of file diff --git a/UnitTests/Views/RadioGroupTests.cs b/UnitTests/Views/RadioGroupTests.cs index 652d5229c..d0b50132d 100644 --- a/UnitTests/Views/RadioGroupTests.cs +++ b/UnitTests/Views/RadioGroupTests.cs @@ -170,7 +170,7 @@ public class RadioGroupTests { [Fact] public void KeyBindings_Are_Added_Correctly () { - var rg = new RadioGroup (new string [] { "Left", "Right" }); + var rg = new RadioGroup (new string [] { "_Left", "_Right" }); Assert.NotEmpty (rg.KeyBindings.GetCommands (KeyCode.L)); Assert.NotEmpty (rg.KeyBindings.GetCommands (KeyCode.R)); @@ -185,7 +185,7 @@ public class RadioGroupTests { [Fact] public void KeyBindings_HotKeys () { - var rg = new RadioGroup (new string [] { "Left", "Right", "Cen_tered", "Justified" }); + var rg = new RadioGroup (new string [] { "_Left", "_Right", "Cen_tered", "_Justified" }); Assert.NotEmpty (rg.KeyBindings.GetCommands (KeyCode.L)); Assert.NotEmpty (rg.KeyBindings.GetCommands (KeyCode.L | KeyCode.ShiftMask)); Assert.NotEmpty (rg.KeyBindings.GetCommands (KeyCode.L | KeyCode.AltMask));