public ConsoleAppKeyboardInputManager(ConsoleApp app) { this.Application = app; this.handlers = new Stack<Dictionary<string, KeyboardEventHandler>>(); this.currentStackDepth = app.FocusManager.StackDepth; app.FocusManager.SubscribeForLifetime(nameof(FocusManager.StackDepth), StackDepthChanged, app.LifetimeManager); }
public void EnsureCantReuseControls() { ConsoleProvider.Current = new CliUnitTestConsole(); ConsoleApp app = new ConsoleApp(0, 0, 80, 10); var panel = app.LayoutRoot.Add(new ConsolePanel()); var button = panel.Add(new Button()); panel.Controls.Remove(button); try { app.LayoutRoot.Add(button); Assert.Fail("An exception should have been thrown"); } catch (ObjectDisposedException ex) { Console.WriteLine(ex.Message); } }
public void ConsoleAppLifecycleTestBasic() { ConsoleProvider.Current = new CliUnitTestConsole(); ConsoleApp app = new ConsoleApp(0, 0, 80, 10); int addCounter = 0, removeCounter = 0; app.ControlAdded.SubscribeForLifetime((c) => { addCounter++; }, app.LifetimeManager); app.ControlRemoved.SubscribeForLifetime((c) => { removeCounter++; }, app.LifetimeManager); app.LayoutRoot.Id = "LayoutRoot"; ConsolePanel panel = app.LayoutRoot.Add(new ConsolePanel() { Id = "First panel" }); // direct child Assert.AreEqual(1, addCounter); Assert.AreEqual(0, removeCounter); var button = panel.Add(new Button() { Id = "Button on first panel" }); // grandchild Assert.AreEqual(2, addCounter); Assert.AreEqual(0, removeCounter); var innerPanel = new ConsolePanel() { Id="InnerPanel" }; var innerInnerPanel = innerPanel.Add(new ConsolePanel() { Id = "Inner Inner Panel"}); // no change since not added to the app yet Assert.AreEqual(2, addCounter); Assert.AreEqual(0, removeCounter); panel.Add(innerPanel); // both child and grandchild found on add Assert.AreEqual(4, addCounter); Assert.AreEqual(0, removeCounter); // remove a nested child innerPanel.Controls.Remove(innerInnerPanel); Assert.AreEqual(4, addCounter); Assert.AreEqual(1, removeCounter); app.LayoutRoot.Controls.Clear(); Assert.AreEqual(4, addCounter); Assert.AreEqual(4, removeCounter); }
public void Basic() { var testCli = new CliUnitTestConsole(80,1); ConsoleProvider.Current = testCli; var app = new ConsoleApp(0, 0, 80, 1); app.LayoutRoot.Add(new TextBox()).Fill(); var task = app.Start(); testCli.Input.Enqueue(new ConsoleKeyInfo('a', ConsoleKey.A, false, false, false)); string result = null; app.Stopping.SubscribeForLifetime(() => { result = testCli.Buffer.ToString(); }, app.LifetimeManager); testCli.Input.Enqueue(new ConsoleKeyInfo('*', ConsoleKey.Escape, false, false, false)); task.Wait(); Assert.AreEqual(80, result.Length); Console.WriteLine(result); }
/// <summary> /// Starts the app, asynchronously. /// </summary> /// <returns>A task that will complete when the app exits</returns> public override Task Start() { QueueAction(() => { if (_current != null) { throw new NotSupportedException("An application is already running on this thread."); } // ensures that the current app is set on the message pump thread _current = this; }); if (SetFocusOnStart) { QueueAction(() => { FocusManager.TryMoveFocus(); }); } Paint(); Task pumpTask = base.Start(); var cleanupTask = pumpTask.ContinueWith((t) => { ExitInternal(); }); return cleanupTask; }
public void Init() { console = new CliUnitTestConsole(); ConsoleProvider.Current = console; app = new ConsoleApp(0, 0, 80, 80); }
public static void Run() { var app = new ConsoleApp(0, 0, 75, 22); var chart = new CpuAndMemoryChart(); var list = new Grid() { Size = new Size(30, 5) }; var source = new MemoryDataSource(); list.DataSource = source; Action syncChartToListAction = () => { source.Items.Clear(); if (chart.ViewModel.FocusedDataSeries != null && chart.ViewModel.FocusedDataPointIndex >= 0 && chart.ViewModel.FocusedDataPointIndex < chart.ViewModel.FocusedDataSeries.DataPoints.Count && chart.ViewModel.FocusedDataSeries.DataPoints.Count > 0) { source.Items.Add(new { Value = ContextAssistSearchResult.FromString(chart.ViewModel.FocusedDataSeries.DataPoints[chart.ViewModel.FocusedDataPointIndex].Y + "") }); } }; chart.ViewModel.FocusedDataPointChanged += syncChartToListAction; chart.ViewModel.FocusedSeriesChanged += syncChartToListAction; syncChartToListAction(); app.LayoutRoot.Controls.Add(chart); app.LayoutRoot.Controls.Add(list); app.Start(); }
public static void Run() { var app = new ConsoleApp(0, 0, 75, 22); var chart = new CpuAndMemoryChart(); var list = new ListView() { Size = new Size(30, 5) }; Action syncChartToListAction = () => { list.ViewModel.Items.Clear(); if (chart.ViewModel.FocusedDataSeries != null && chart.ViewModel.FocusedDataPointIndex >= 0 && chart.ViewModel.FocusedDataPointIndex < chart.ViewModel.FocusedDataSeries.DataPoints.Count && chart.ViewModel.FocusedDataSeries.DataPoints.Count > 0) { list.ViewModel.Items.Add(ContextAssistSearchResult.FromString(chart.ViewModel.FocusedDataSeries.DataPoints[chart.ViewModel.FocusedDataPointIndex].Y + "")); } }; chart.ViewModel.FocusedDataPointChanged += syncChartToListAction; chart.ViewModel.FocusedSeriesChanged += syncChartToListAction; syncChartToListAction(); app.Controls.Add(chart); app.Controls.Add(list); app.Run(); }
protected override void OnThredStart() { _current = this; }
public static IDisposable SynchronizeProxiedUnmanaged(this IObservableObject obj, ConsoleApp app, string propertyName, Action handler) { return(obj.SynchronizeUnmanaged(propertyName, () => { app.QueueAction(handler); })); }
private static ConsoleApp ParseApp(ParserContext context) { context.CurrentElement = context.RootElement; var x = context.CurrentElement.Attribute<int>("X"); var y = context.CurrentElement.Attribute<int>("Y"); var w = context.CurrentElement.Attribute<int>("Width"); var h = context.CurrentElement.Attribute<int>("Height"); ConsoleApp app; if (x.HasValue | y.HasValue | w.HasValue | h.HasValue) { var xV = x.HasValue ? x.Value : 0; var yV = y.HasValue ? y.Value : 0; var wV = w.HasValue ? w.Value : ConsoleProvider.Current.BufferWidth - xV; var hV = h.HasValue ? h.Value : ConsoleProvider.Current.WindowHeight - yV; app = new ConsoleApp(xV, yV, wV, hV); } else { app = new ConsoleApp(); } ParsePanel(context, app.LayoutRoot); return app; }