mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-27 08:17:53 +01:00
* Added View.DefaultCommand etc... Started on dedicated scenario * Fixed un-shifted hotkeys -> Fixed Key Equals. Fixed WindowsDriver passing wrong key. Etc. * Fixed Key Bindings and HotKeys * Fixed Key Bindings and HotKeys * Label now correctly supports hotkey * Disabled unix hot keys because they are annoying and get in the way * Updated nuget. fixed warnings * Trying to fix ci/ci issue * Trying to fix ci/ci issue * Trying to fix ci/ci issue * Changed TextChangingEventArgs to inherit from CancelEventArgs * TextChangingEventArgs -> TextEventArgs * Simplified Text events by having only on args class * Fixed unit tests fail * Simplified by removing TitleEventArgs * POC of Title being primary for hotkey. Label and Button hacked to work * POC of Title being primary for hotkey. Label and Button hacked to work - all unit tests pass * Dropped Microsoft.NETFramework.ReferenceAssemblies * Fixed Dialogs scenario hotkeys * Fixed build warnings * Fixed Border Title render bug * Regiggering default command handling * Regiggering default command handling * Checkbox clean up * Added StateEventArgs POC * Command.Default -> Command.HotKey * Command.Default -> Command.HotKey - fixed TableView * Command.Default -> Command.HotKey - fixed TableView * Updated reactive example * Fixed Toplevel.BringOverlappedTopToFront - was reordering SubViews when it shouldn't * WIP - broke * Finished impl of StateEventArgs * Deleted ToggleEventArgs.cs. Added StateEventArgs.cs * XML doc fix * Removed old code * Removed commented out code * Label.Clicked -> Label.Accept (missed this before) * Removed Labels as Buttons scenario as it's not really useful * Moved SubView tests to own file * Moved SubView tests to own file * Simplified Text test * Added OnAccept test * Deleted DefaultCommand * Modernized CheckBox * New button test * Cleaned up RadioGroup; added tests * KeyCode->Key in ListView * Added ListView unit tests * ListView now does Accept correctly * TreeView now does Accept correctly * Cleaned up some TextField tests * TextView now handles Accept properly; updated CharMap and Adornments scenarios to test * Fixed ComboBox to deal with TextView now handles Accept properly; updated CharMap and Adornments scenarios to test * Removed un-needed using statement
240 lines
8.3 KiB
C#
240 lines
8.3 KiB
C#
using Xunit.Abstractions;
|
|
|
|
namespace Terminal.Gui.ViewsTests;
|
|
|
|
public class StatusBarTests
|
|
{
|
|
private readonly ITestOutputHelper output;
|
|
public StatusBarTests (ITestOutputHelper output) { this.output = output; }
|
|
|
|
[Fact]
|
|
public void AddItemAt_RemoveItem_Replacing ()
|
|
{
|
|
var sb = new StatusBar (
|
|
new StatusItem []
|
|
{
|
|
new (KeyCode.CtrlMask | KeyCode.Q, "~^O~ Open", null),
|
|
new (KeyCode.CtrlMask | KeyCode.Q, "~^S~ Save", null),
|
|
new (KeyCode.CtrlMask | KeyCode.Q, "~^Q~ Quit", null)
|
|
}
|
|
);
|
|
|
|
sb.AddItemAt (2, new StatusItem (KeyCode.CtrlMask | KeyCode.Q, "~^C~ Close", null));
|
|
|
|
Assert.Equal ("~^O~ Open", sb.Items [0].Title);
|
|
Assert.Equal ("~^S~ Save", sb.Items [1].Title);
|
|
Assert.Equal ("~^C~ Close", sb.Items [2].Title);
|
|
Assert.Equal ("~^Q~ Quit", sb.Items [^1].Title);
|
|
|
|
Assert.Equal ("~^S~ Save", sb.RemoveItem (1).Title);
|
|
|
|
Assert.Equal ("~^O~ Open", sb.Items [0].Title);
|
|
Assert.Equal ("~^C~ Close", sb.Items [1].Title);
|
|
Assert.Equal ("~^Q~ Quit", sb.Items [^1].Title);
|
|
|
|
sb.Items [1] = new StatusItem (KeyCode.CtrlMask | KeyCode.A, "~^A~ Save As", null);
|
|
|
|
Assert.Equal ("~^O~ Open", sb.Items [0].Title);
|
|
Assert.Equal ("~^A~ Save As", sb.Items [1].Title);
|
|
Assert.Equal ("~^Q~ Quit", sb.Items [^1].Title);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void CanExecute_ProcessHotKey ()
|
|
{
|
|
Window win = null;
|
|
|
|
var statusBar = new StatusBar (
|
|
new StatusItem []
|
|
{
|
|
new (
|
|
KeyCode.CtrlMask | KeyCode.N,
|
|
"~^N~ New",
|
|
New,
|
|
CanExecuteNew
|
|
),
|
|
new (
|
|
KeyCode.CtrlMask | KeyCode.C,
|
|
"~^C~ Close",
|
|
Close,
|
|
CanExecuteClose
|
|
)
|
|
}
|
|
);
|
|
Toplevel top = Application.Top;
|
|
top.Add (statusBar);
|
|
|
|
bool CanExecuteNew () { return win == null; }
|
|
|
|
void New () { win = new Window (); }
|
|
|
|
bool CanExecuteClose () { return win != null; }
|
|
|
|
void Close () { win = null; }
|
|
|
|
Application.Begin (top);
|
|
|
|
Assert.Null (win);
|
|
Assert.True (CanExecuteNew ());
|
|
Assert.False (CanExecuteClose ());
|
|
|
|
Assert.True (top.NewKeyDownEvent (Key.N.WithCtrl));
|
|
Application.MainLoop.RunIteration ();
|
|
Assert.NotNull (win);
|
|
Assert.False (CanExecuteNew ());
|
|
Assert.True (CanExecuteClose ());
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Redraw_Output ()
|
|
{
|
|
var sb = new StatusBar (
|
|
new StatusItem []
|
|
{
|
|
new (KeyCode.CtrlMask | KeyCode.O, "~^O~ Open", null),
|
|
new (Application.QuitKey, $"{Application.QuitKey} to Quit!", null)
|
|
}
|
|
);
|
|
Application.Top.Add (sb);
|
|
|
|
sb.OnDrawContent (sb.Bounds);
|
|
|
|
var expected = @$"
|
|
^O Open {
|
|
CM.Glyphs.VLine
|
|
} Ctrl+Q to Quit!
|
|
";
|
|
TestHelpers.AssertDriverContentsAre (expected, output);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Redraw_Output_CTRLQ ()
|
|
{
|
|
var sb = new StatusBar (
|
|
new StatusItem []
|
|
{
|
|
new (KeyCode.CtrlMask | KeyCode.O, "~CTRL-O~ Open", null),
|
|
new (KeyCode.CtrlMask | KeyCode.Q, "~CTRL-Q~ Quit", null)
|
|
}
|
|
);
|
|
Application.Top.Add (sb);
|
|
sb.OnDrawContent (sb.Bounds);
|
|
|
|
var expected = @$"
|
|
CTRL-O Open {
|
|
CM.Glyphs.VLine
|
|
} CTRL-Q Quit
|
|
";
|
|
|
|
TestHelpers.AssertDriverContentsAre (expected, output);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Run_Action_With_Key_And_Mouse ()
|
|
{
|
|
var msg = "";
|
|
|
|
var sb = new StatusBar (
|
|
new StatusItem []
|
|
{
|
|
new (
|
|
Application.QuitKey,
|
|
$"{Application.QuitKey} to Quit",
|
|
() => msg = "Quiting..."
|
|
)
|
|
}
|
|
);
|
|
Application.Top.Add (sb);
|
|
|
|
var iteration = 0;
|
|
|
|
Application.Iteration += (s, a) =>
|
|
{
|
|
if (iteration == 0)
|
|
{
|
|
Assert.Equal ("", msg);
|
|
sb.NewKeyDownEvent (Key.Q.WithCtrl);
|
|
}
|
|
else if (iteration == 1)
|
|
{
|
|
Assert.Equal ("Quiting...", msg);
|
|
msg = "";
|
|
sb.MouseEvent (new MouseEvent { X = 1, Y = 24, Flags = MouseFlags.Button1Clicked });
|
|
}
|
|
else
|
|
{
|
|
Assert.Equal ("Quiting...", msg);
|
|
|
|
Application.RequestStop ();
|
|
}
|
|
|
|
iteration++;
|
|
};
|
|
|
|
Application.Run ();
|
|
}
|
|
|
|
[Fact]
|
|
public void StatusBar_Constructor_Default ()
|
|
{
|
|
var sb = new StatusBar ();
|
|
|
|
Assert.Empty (sb.Items);
|
|
Assert.False (sb.CanFocus);
|
|
Assert.Equal (Colors.ColorSchemes ["Menu"], sb.ColorScheme);
|
|
Assert.Equal (0, sb.X);
|
|
Assert.Equal ("AnchorEnd(1)", sb.Y.ToString ());
|
|
Assert.Equal (Dim.Fill (), sb.Width);
|
|
Assert.Equal (1, sb.Height);
|
|
|
|
var driver = new FakeDriver ();
|
|
Application.Init (driver);
|
|
|
|
sb = new StatusBar ();
|
|
|
|
driver.SetCursorVisibility (CursorVisibility.Default);
|
|
driver.GetCursorVisibility (out CursorVisibility cv);
|
|
Assert.Equal (CursorVisibility.Default, cv);
|
|
Assert.True (FakeConsole.CursorVisible);
|
|
|
|
Application.Iteration += (s, a) =>
|
|
{
|
|
Assert.Equal (24, sb.Frame.Y);
|
|
|
|
driver.SetWindowSize (driver.Cols, 15);
|
|
|
|
Assert.Equal (14, sb.Frame.Y);
|
|
|
|
sb.OnEnter (null);
|
|
driver.GetCursorVisibility (out cv);
|
|
Assert.Equal (CursorVisibility.Invisible, cv);
|
|
Assert.False (FakeConsole.CursorVisible);
|
|
|
|
Application.RequestStop ();
|
|
};
|
|
|
|
Application.Top.Add (sb);
|
|
|
|
Application.Run ();
|
|
|
|
Application.Shutdown ();
|
|
}
|
|
|
|
[Fact]
|
|
public void StatusItem_Constructor ()
|
|
{
|
|
Application.Init ();
|
|
var si = new StatusItem (Application.QuitKey, $"{Application.QuitKey} to Quit", null);
|
|
Assert.Equal (KeyCode.CtrlMask | KeyCode.Q, si.Shortcut);
|
|
Assert.Equal ($"{Application.QuitKey} to Quit", si.Title);
|
|
Assert.Null (si.Action);
|
|
si = new StatusItem (Application.QuitKey, $"{Application.QuitKey} to Quit", () => { });
|
|
Assert.NotNull (si.Action);
|
|
Application.Shutdown ();
|
|
}
|
|
}
|