public static void ShowRichTextInput(ConsoleString message, Action<ConsoleString> resultCallback, Action cancelCallback = null, bool allowEscapeToCancel = true, int maxHeight = 12, TextBox inputBox = null) { if (ConsoleApp.Current == null) { throw new InvalidOperationException("There is no console app running"); } ConsolePanel content = new ConsolePanel(); content.Width = ConsoleApp.Current.LayoutRoot.Width / 2; content.Height = ConsoleApp.Current.LayoutRoot.Height / 2; var dialog = new Dialog(content); dialog.MaxHeight = maxHeight; dialog.AllowEscapeToCancel = allowEscapeToCancel; dialog.Cancelled.SubscribeForLifetime(() => { if (cancelCallback != null) cancelCallback(); }, dialog.LifetimeManager); Label messageLabel = content.Add(new Label() { Text = message, X = 2, Y = 2 }); if (inputBox == null) { inputBox = new TextBox() { Foreground = ConsoleColor.Black, Background = ConsoleColor.White }; } content.Add(inputBox).CenterHorizontally(); inputBox.Y = 4; content.SynchronizeForLifetime(nameof(Bounds), () => { inputBox.Width = content.Width - 4; }, content.LifetimeManager); inputBox.KeyInputReceived.SubscribeForLifetime((k) => { if (k.Key == ConsoleKey.Enter) { resultCallback(inputBox.Value); ConsoleApp.Current.LayoutRoot.Controls.Remove(dialog); } }, inputBox.LifetimeManager); ConsoleApp.Current.LayoutRoot.Controls.Add(dialog); inputBox.TryFocus(); }
private void SetFilterTextBox(TextBox value) { if(_filterTextBox != null) { throw new ArgumentException("Grid is already bound to a text box"); } _filterTextBox = value; _filterTextBox.SubscribeForLifetime(nameof(TextBox.Value), FilterTextValueChanged, value.LifetimeManager); _filterTextBox.KeyInputReceived.SubscribeForLifetime(FilterTextKeyPressed, value.LifetimeManager); FilteringEnabled = true; }