diff --git a/src/Consolonia.Core/Drawing/DrawingContextImpl.cs b/src/Consolonia.Core/Drawing/DrawingContextImpl.cs index f091900e..00c6811c 100644 --- a/src/Consolonia.Core/Drawing/DrawingContextImpl.cs +++ b/src/Consolonia.Core/Drawing/DrawingContextImpl.cs @@ -210,8 +210,7 @@ public void DrawGlyphRun(IBrush foreground, IGlyphRunImpl glyphRun) return; } - var shapedBuffer = glyphRunImpl.GlyphInfos as ShapedBuffer; - ArgumentNullException.ThrowIfNull(shapedBuffer); + var shapedBuffer = (ShapedBuffer)glyphRunImpl.GlyphInfos; string text = shapedBuffer.Text.ToString(); DrawStringInternal(foreground, text, glyphRun.GlyphTypeface); } diff --git a/src/Consolonia.Core/Infrastructure/InputLessDefaultNetConsole.cs b/src/Consolonia.Core/Infrastructure/InputLessDefaultNetConsole.cs index d94589c1..a97e9f59 100644 --- a/src/Consolonia.Core/Infrastructure/InputLessDefaultNetConsole.cs +++ b/src/Consolonia.Core/Infrastructure/InputLessDefaultNetConsole.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Text; using System.Threading.Tasks; using Avalonia; @@ -53,27 +54,18 @@ public bool SupportsComplexEmoji { if (_supportEmoji == null) { -#pragma warning disable CA1031 // Do not catch general exception types - try - { - // Detect complex emoji support by writing a complex emoji and checking cursor position. - // If the cursor moves 2 positions, it indicates proper rendering of composite surrogate pairs. - (int left, int top) = Console.GetCursorPosition(); - WriteText( - $"{Esc.Foreground(Colors.Transparent)}{Esc.Background(Colors.Transparent)}{TestEmoji}"); - - // TODO, escape sequence - (int left2, _) = Console.GetCursorPosition(); - _supportEmoji = left2 - left == 2; - Console.SetCursorPosition(left, top); - } - catch (Exception) - { - _supportEmoji = true; - } + // Detect complex emoji support by writing a complex emoji and checking cursor position. + // If the cursor moves 2 positions, it indicates proper rendering of composite surrogate pairs. + (int left, int top) = Console.GetCursorPosition(); + WriteText( + $"{Esc.Foreground(Colors.Transparent)}{Esc.Background(Colors.Transparent)}{TestEmoji}"); + + // TODO, escape sequence + (int left2, _) = Console.GetCursorPosition(); + _supportEmoji = left2 - left == 2; + Console.SetCursorPosition(left, top); WriteText(Esc.ClearScreen); -#pragma warning restore CA1031 // Do not catch general exception types } return _supportEmoji ?? true; @@ -82,16 +74,7 @@ public bool SupportsComplexEmoji public void SetTitle(string title) { -#pragma warning disable CA1031 // Do not catch general exception types - try - { - Console.Title = title; - } - catch (Exception) - { - // ignored - } -#pragma warning restore CA1031 // Do not catch general exception types + Console.Title = title; } public void SetCaretPosition(PixelBufferCoordinate bufferPoint) diff --git a/src/Consolonia.Designer/ConsolePreview.cs b/src/Consolonia.Designer/ConsolePreview.cs index 8ddb6856..1412a507 100644 --- a/src/Consolonia.Designer/ConsolePreview.cs +++ b/src/Consolonia.Designer/ConsolePreview.cs @@ -1,6 +1,7 @@ #nullable enable using Avalonia; using Avalonia.Controls; + #if DEBUG using Consolonia.PreviewHost; using System; @@ -161,7 +162,12 @@ private void LoadXaml() xaml = File.ReadAllText(xamlPath); ArgumentNullException.ThrowIfNull(xaml); } - catch (Exception ex) + catch (UnauthorizedAccessException ex) + { + Content = new TextBlock { Text = $"Unable to access XAML file. {ex.Message}", Foreground = Brushes.Red }; + return; + } + catch (IOException ex) { Content = new TextBlock { Text = $"Unable to load XAML file. {ex.Message}", Foreground = Brushes.Red }; return; @@ -239,7 +245,7 @@ private void ListenForChanges() var buffer = JsonConvert.DeserializeObject(line)!; Dispatcher.UIThread.Invoke(() => Content = RenderPixelBuffer(buffer)); } - catch (Exception ex) + catch (JsonException ex) { // process was probably shut down, we continue to check the proces. Debug.WriteLine($"Error deserializing pixel buffer: {ex.Message}"); diff --git a/src/Tools/Consolonia.PreviewHost/Properties/launchSettings.json b/src/Tools/Consolonia.PreviewHost/Properties/launchSettings.json index b6106030..75d4abbf 100644 --- a/src/Tools/Consolonia.PreviewHost/Properties/launchSettings.json +++ b/src/Tools/Consolonia.PreviewHost/Properties/launchSettings.json @@ -6,6 +6,7 @@ }, "Consolonia.PreviewHost": { "commandName": "Project", + "commandLineArgs": ".", "workingDirectory": "S:\\github\\Consolonia\\src\\Consolonia.Gallery" } }