Skip to content

Commit

Permalink
changes from jinek code review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlm committed Nov 29, 2024
1 parent 1f07aee commit b04dd60
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 33 deletions.
3 changes: 1 addition & 2 deletions src/Consolonia.Core/Drawing/DrawingContextImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
41 changes: 12 additions & 29 deletions src/Consolonia.Core/Infrastructure/InputLessDefaultNetConsole.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Avalonia;
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions src/Consolonia.Designer/ConsolePreview.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#nullable enable
using Avalonia;
using Avalonia.Controls;

#if DEBUG
using Consolonia.PreviewHost;
using System;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -239,7 +245,7 @@ private void ListenForChanges()
var buffer = JsonConvert.DeserializeObject<PixelBuffer>(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}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
},
"Consolonia.PreviewHost": {
"commandName": "Project",
"commandLineArgs": ".",
"workingDirectory": "S:\\github\\Consolonia\\src\\Consolonia.Gallery"
}
}
Expand Down

0 comments on commit b04dd60

Please sign in to comment.