Inheritance: PowerArgs.Cli.ConsolePanel
コード例 #1
0
ファイル: Dialog.cs プロジェクト: adamabdelhamed/PowerArgs
        public static void ShowMessage(ConsoleString message, Action<DialogButton> resultCallback, bool allowEscapeToCancel = true, int maxHeight = 6, params DialogButton [] buttons)
        {
            if(buttons.Length == 0)
            {
                throw new ArgumentException("You need to specify at least one button");
            }

            ConsolePanel dialogContent = new ConsolePanel();

            Dialog dialog = new Dialog(dialogContent);
            dialog.MaxHeight = maxHeight;
            dialog.AllowEscapeToCancel = allowEscapeToCancel;
            dialog.Cancelled.SubscribeForLifetime(() => { resultCallback(null); }, dialog.LifetimeManager);

            ScrollablePanel messagePanel = dialogContent.Add(new ScrollablePanel()).Fill(padding: new Thickness(0, 0, 1, 3));
            Label messageLabel = messagePanel.ScrollableContent.Add(new Label() { Mode = LabelRenderMode.MultiLineSmartWrap, Text = message }).FillHoriontally(padding: new Thickness(3,3,0,0) );

            StackPanel buttonPanel = dialogContent.Add(new StackPanel() { Margin = 1, Height = 1, Orientation = Orientation.Horizontal }).FillHoriontally(padding: new Thickness(1,0,0,0)).DockToBottom(padding: 1);

            Button firstButton = null;
            foreach (var buttonInfo in buttons)
            {
                var myButtonInfo = buttonInfo;
                Button b = new Button() { Text = buttonInfo.DisplayText };
                b.Pressed.SubscribeForLifetime(() =>
                {
                    ConsoleApp.Current.LayoutRoot.Controls.Remove(dialog);
                    resultCallback(myButtonInfo);
                }, dialog.LifetimeManager);
                buttonPanel.Controls.Add(b);
                firstButton = firstButton ?? b;
            }
            ConsoleApp.Current.LayoutRoot.Controls.Add(dialog);
        }
コード例 #2
0
        /// <summary>
        /// The state change handler that defines what happens whenever the player changes state
        /// </summary>
        private void StateChanged()
        {
            if (State != PlayerState.Playing)
            {
                playLifetime = null;
            }

            if (State == PlayerState.Playing)
            {
                if (duration.HasValue == false)
                {
                    throw new InvalidOperationException("Playback is not permitted before a video is loaded");
                }

                playStartPosition = TimeSpan.FromSeconds(playerProgressBar.PlayCursorPosition * duration.Value.TotalSeconds);
                playStartTime     = DateTime.UtcNow;

                // start a play loop for as long as the state remains unchanged
                this.playLifetime = this.GetPropertyValueLifetime(nameof(State));
                playLifetime.LifetimeManager.Manage(Application.SetInterval(() =>
                {
                    if (State != PlayerState.Playing)
                    {
                        return;
                    }

                    var now                              = DateTime.UtcNow;
                    var delta                            = now - playStartTime;
                    var newPlayerPosition                = playStartPosition + delta;
                    var videoLocationPercentage          = Math.Round(100.0 * newPlayerPosition.TotalSeconds / duration.Value.TotalSeconds, 1);
                    videoLocationPercentage              = Math.Min(videoLocationPercentage, 100);
                    playerProgressBar.PlayCursorPosition = videoLocationPercentage / 100.0;
                    playButton.Text                      = $"Pause".ToConsoleString();

                    ConsoleBitmap seekedImage;
                    if (newPlayerPosition > duration)
                    {
                        State = PlayerState.Stopped;
                    }
                    else if (inMemoryVideo.TrySeek(newPlayerPosition, out seekedImage) == false)
                    {
                        State = PlayerState.Buffering;
                    }
                    else
                    {
                        CurrentFrame = seekedImage;
                    }
                }, TimeSpan.FromMilliseconds(1)));
            }
            else if (State == PlayerState.Stopped)
            {
                pictureFrame.BorderColor = ConsoleColor.Yellow;
                playButton.Text          = "Play".ToConsoleString();
            }
            else if (State == PlayerState.Paused)
            {
                playButton.Text = "Play".ToConsoleString();
            }
            else if (State == PlayerState.NotLoaded)
            {
                playButton.Text     = "Play".ToConsoleString();
                playButton.CanFocus = false;
            }
            else if (State == PlayerState.Buffering)
            {
                playButton.Text = "Play".ToConsoleString();
            }
            else if (State == PlayerState.Failed)
            {
                pictureFrame.BorderColor = ConsoleColor.Red;
                Dialog.ShowMessage(failedMessage.ToRed());
            }
            else
            {
                throw new Exception("Unknown state: " + State);
            }
        }
コード例 #3
0
ファイル: Dialog.cs プロジェクト: adamabdelhamed/PowerArgs
        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();
        }
コード例 #4
0
ファイル: Page.cs プロジェクト: adamabdelhamed/PowerArgs
        public void ShowProgressOperationsDialog()
        {
            if (PageStack.CurrentPage != this)
            {
                throw new InvalidOperationException("Not the current page");
            }

            if (progressOperationManagerDialog != null && Application.LayoutRoot.Controls.Contains(progressOperationManagerDialog))
            {
                return;
            }

            var progressOperationManagerControl = new ProgressOperationManagerControl(this.ProgressOperationManager);
            progressOperationManagerDialog = new Dialog(progressOperationManagerControl) { MaxHeight = 40 };
            progressOperationManagerDialog.AllowEscapeToCancel = true;

            Application.LayoutRoot.Add(progressOperationManagerDialog);
        }