public static ShowMessage ( ConsoleString message, System.Action doneCallback = null, int maxHeight = 12 ) : void | ||
message | ConsoleString | |
doneCallback | System.Action | |
maxHeight | int | |
Résultat | void |
public ProgressOperationControl(ProgressOperationsManager manager, ProgressOperation operation) { this.Tag = operation; this.Operation = operation; this.manager = manager; this.Height = 2; messageAndOperationsPanel = Add(new StackPanel() { Orientation = Orientation.Vertical }).Fill(); messageLabel = messageAndOperationsPanel.Add(new Label() { Mode = LabelRenderMode.ManualSizing }).FillHorizontally(); messageLabel.CanFocus = true; messageLabel.KeyInputReceived.SubscribeForLifetime((k) => { if (k.Key == ConsoleKey.Enter) { var msg = operation.Message; if (operation.Details != null) { msg += "\n" + operation.Details; } Dialog.ShowMessage(msg); } else if (k.Key == ConsoleKey.Delete) { var app = Application; manager.Operations.Remove(operation); app.FocusManager.TryMoveFocus(); } }, this); actionPanel = messageAndOperationsPanel.Add(new StackPanel() { Orientation = Orientation.Horizontal, Height = 1, Margin = 2 }).FillHorizontally(messageAndOperationsPanel); spinner = actionPanel.Add(new Spinner() { CanFocus = false }); timeLabel = actionPanel.Add(new Label() { Mode = LabelRenderMode.SingleLineAutoSize, Text = operation.StartTime.ToFriendlyPastTimeStamp().ToConsoleString() }); spinner.IsSpinning = operation.State == OperationState.InProgress; foreach (var action in operation.Actions) { BindActionToActionPanel(action); } AddedToVisualTree.SubscribeForLifetime(OnAddedToVisualTree, this); }
private void EscapeKeyHandler(ConsoleKeyInfo escape) { var consolePageApp = (Application as ConsolePageApp); if (PageStack.GetSegments(PageStack.CurrentPath).Length > 1) { PageStack.TryUp(); } else if (consolePageApp.AllowEscapeToExit && consolePageApp.PromptBeforeExit) { Dialog.ShowMessage("Are you sure you want to quit?".ToConsoleString(), (choice) => { if (choice != null && choice.DisplayText == "Yes") { Application.Stop(); } }, true, 10, new DialogButton() { DisplayText = "Yes" }, new DialogButton() { DisplayText = "No" }); } else if (consolePageApp.AllowEscapeToExit) { Application.Stop(); } }
public PickerControl(PickerControlOptions <T> options) { this.Options = options; this.idMap = new Dictionary <string, T>(); this.reverseIdMap = new Dictionary <T, string>(); for (var i = 0; i < this.Options.Options.Count; i++) { idMap.Add(i.ToString(), this.Options.Options[i]); reverseIdMap.Add(this.Options.Options[i], i.ToString()); } this.innerLabel = Add(new Label()).Fill(); // When the selected item changes make sure we update the label this.SubscribeForLifetime(nameof(SelectedItem), () => { this.innerLabel.Text = FormatItem(this.SelectedItem); this.Options.SelectionChanged?.Invoke(this.SelectedItem); }, this); this.innerLabel.CanFocus = true; this.innerLabel.KeyInputReceived.SubscribeForLifetime((key) => { if (key.Key == ConsoleKey.Enter) { Dialog.ShowMessage(new DialogButtonOptions() { Message = this.Options.PromptMessage, Mode = DialogButtonsPresentationMode.Grid, Options = this.Options.Options.Select(o => new DialogOption() { DisplayText = FormatItem(o), Id = reverseIdMap[o] }).ToList(), }).Then((selectedOption) => { if (selectedOption != null) { this.SelectedItem = idMap[selectedOption.Id]; } }); } }, this); if (options.HasDefaultSelection) { this.SelectedItem = options.DefaultSelection; } }
private async void NewCommandImpl() { if (await ConfirmOkToProceedWithPendingChanges("Are you sure you want to start a new project?") == false) { return; } var w = await Dialog.ShowRichTextInput(new RichTextDialogOptions() { Message = "Width".ToYellow() }); if (w == null) { return; } if (string.IsNullOrWhiteSpace(w?.StringValue) || int.TryParse(w.StringValue, out int width) == false) { await Dialog.ShowMessage($"Invalid width: '{w.StringValue}'"); return; } var h = await Dialog.ShowRichTextInput(new RichTextDialogOptions() { Message = "Height".ToYellow() }); if (h == null) { return; } if (string.IsNullOrWhiteSpace(h?.StringValue) || int.TryParse(h.StringValue, out int height) == false) { await Dialog.ShowMessage($"Invalid height: '{h.StringValue}'"); return; } currentlyOpenedFile = null; animation.Frames.Clear(); animation.Frames.Add(new InMemoryConsoleBitmapFrame() { Bitmap = new ConsoleBitmap(width, height), FrameTime = TimeSpan.Zero }); CurrentFrameIndex = 0; undoRedo.Clear(); undoRedo.Do(new ClearPendingChangesAction(this)); Refresh(); }
/// <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"); } ConsoleApp.Current.Invoke(PlayLoop); } 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); } }
private async void OpenCommandImpl() { if (await ConfirmOkToProceedWithPendingChanges("Are you sure you want to open another project?") == false) { return; } var tb = new TextBox() { Value = lastOpenDialogInput?.ToConsoleString() ?? ConsoleString.Empty }; var input = await Dialog.ShowRichTextInput(new RichTextDialogOptions() { TextBox = tb, Message = "Enter file path".ToYellow(), }); if (input == null) { return; } lastOpenDialogInput = input.StringValue; if (File.Exists(lastOpenDialogInput) == false) { await Dialog.ShowMessage($"File not found: {lastOpenDialogInput}".ToRed()); OpenCommandImpl(); return; } if (TryOpenConsoleBitmapReaderFormat(lastOpenDialogInput) == false && TryOpenVisualFormat(lastOpenDialogInput) == false) { await Dialog.ShowMessage($"Failed to load file: {lastOpenDialogInput}".ToRed()); } else { currentlyOpenedFile = lastOpenDialogInput; Refresh(); } }
/// <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; lastFrameIndex = 0; // start a play loop for as long as the state remains unchanged this.playLifetime = this.GetPropertyValueLifetime(nameof(State)); playLifetime.OnDisposed(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(); InMemoryConsoleBitmapFrame seekedFrame; if ((lastFrameIndex = inMemoryVideo.Seek(newPlayerPosition, out seekedFrame, lastFrameIndex >= 0 ? lastFrameIndex : 0)) < 0) { State = PlayerState.Buffering; } else { CurrentFrame = seekedFrame.Bitmap; OnFramePlayed.Fire(seekedFrame.FrameTime); } if (newPlayerPosition > duration) { State = PlayerState.Stopped; } }, 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); } }
private async void SaveCommon(string destination) { if (saveInProgress) { return; } try { saveInProgress = true; ConsoleBitmapVideoWriter writer = null; var tempFile = Path.GetTempFileName(); bool tempWriteSuccess = false; try { writer = new ConsoleBitmapVideoWriter(s => File.WriteAllText(tempFile, s)); foreach (var frame in animation.Frames) { writer.WriteFrame(frame.Bitmap, desiredFrameTime: frame.FrameTime); } tempWriteSuccess = true; } catch (Exception) { await Dialog.ShowMessage($"Failed to save file to {destination}".ToRed()); return; } finally { writer?.Finish(); if (tempWriteSuccess == false) { try { File.Delete(tempFile); } catch (Exception) { } } } try { // If we can't read this back then don't finalize the save. // This ensures that if we wrote garbage (which should never happen) // then we won't corrupt whatever was on disk. using (var testStream = File.OpenRead(tempFile)) { var testReader = new ConsoleBitmapStreamReader(testStream); testReader.ReadToEnd(); } } catch (Exception) { try { File.Delete(tempFile); } catch (Exception) { } await Dialog.ShowMessage($"Failed to save file to {destination}".ToRed()); return; } File.Delete(destination); File.Move(tempFile, destination); currentlyOpenedFile = destination; undoRedo.Do(new ClearPendingChangesAction(this)); } finally { saveInProgress = false; } }