Skip to content

Commit

Permalink
Automated JetBrains cleanup
Browse files Browse the repository at this point in the history
Co-authored-by:  <[email protected]>
  • Loading branch information
github-actions[bot] committed Nov 10, 2024
1 parent d858667 commit 2e4dd41
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,46 +56,46 @@ private static char GetBoxSymbol(byte upRightDownLeft)
return horizontal ? '╪' : '╫';

default:
{
return upRightDownLeft switch
{
return upRightDownLeft switch
{
EmptySymbol => char.MinValue,
BoldSymbol => '█',
0b0000_1001 => '┘',
0b1000_1001 => '╜',
0b0001_1001 => '╛',
0b1001_1001 => '╝',
0b0000_0011 => '┐',
0b0010_0011 => '╖',
0b0001_0011 => '╕',
0b0011_0011 => '╗',
0b0000_0110 => '┌',
0b0100_0110 => '╒',
0b0010_0110 => '╓',
0b0110_0110 => '╔',
0b0000_1100 => '└',
0b0100_1100 => '╘',
0b1000_1100 => '╙',
0b1100_1100 => '╚',
0b0000_1110 => '├',
0b1000_1110 or 0b0010_1110 or 0b1010_1110 => '╟',
0b0100_1110 => '╞',
0b1100_1110 or 0b0110_1110 or 0b1110_1110 => '╠',
0b0000_1011 => '┤',
0b1000_1011 or 0b0010_1011 or 0b1010_1011 => '╢',
0b0001_1011 => '╡',
0b1001_1011 or 0b0011_1011 or 0b1011_1011 => '╣',
0b0000_1101 => '┴',
0b1000_1101 => '╨',
0b0100_1101 or 0b0001_1101 or 0b0101_1101 => '╧',
0b1100_1101 or 0b1001_1101 or 0b1101_1101 => '╩',
0b0000_0111 => '┬',
0b0010_0111 => '╥',
0b0100_0111 or 0b0001_0111 or 0b0101_0111 => '╤',
0b0110_0111 or 0b0011_0111 or 0b0111_0111 => '╦',
_ => throw new InvalidOperationException()
};
}
EmptySymbol => char.MinValue,
BoldSymbol => '█',
0b0000_1001 => '┘',
0b1000_1001 => '╜',
0b0001_1001 => '╛',
0b1001_1001 => '╝',
0b0000_0011 => '┐',
0b0010_0011 => '╖',
0b0001_0011 => '╕',
0b0011_0011 => '╗',
0b0000_0110 => '┌',
0b0100_0110 => '╒',
0b0010_0110 => '╓',
0b0110_0110 => '╔',
0b0000_1100 => '└',
0b0100_1100 => '╘',
0b1000_1100 => '╙',
0b1100_1100 => '╚',
0b0000_1110 => '├',
0b1000_1110 or 0b0010_1110 or 0b1010_1110 => '╟',
0b0100_1110 => '╞',
0b1100_1110 or 0b0110_1110 or 0b1110_1110 => '╠',
0b0000_1011 => '┤',
0b1000_1011 or 0b0010_1011 or 0b1010_1011 => '╢',
0b0001_1011 => '╡',
0b1001_1011 or 0b0011_1011 or 0b1011_1011 => '╣',
0b0000_1101 => '┴',
0b1000_1101 => '╨',
0b0100_1101 or 0b0001_1101 or 0b0101_1101 => '╧',
0b1100_1101 or 0b1001_1101 or 0b1101_1101 => '╩',
0b0000_0111 => '┬',
0b0010_0111 => '╥',
0b0100_0111 or 0b0001_0111 or 0b0101_0111 => '╤',
0b0110_0111 or 0b0011_0111 or 0b0111_0111 => '╦',
_ => throw new InvalidOperationException()
};
}
}
}

Expand Down Expand Up @@ -135,18 +135,28 @@ public static DrawingBoxSymbol UpRightDownLeftFromPattern(byte pattern, LineStyl
}

public bool Equals(DrawingBoxSymbol other)
=> _upRightDownLeft == other._upRightDownLeft;
{
return _upRightDownLeft == other._upRightDownLeft;
}

public override bool Equals([NotNullWhen(true)] object obj)
=> obj is DrawingBoxSymbol other && this.Equals(other);
{
return obj is DrawingBoxSymbol other && Equals(other);
}

public override int GetHashCode()
=> _upRightDownLeft.GetHashCode();
{
return _upRightDownLeft.GetHashCode();
}

public static bool operator ==(DrawingBoxSymbol left, DrawingBoxSymbol right)
=> left.Equals(right);

{
return left.Equals(right);
}

public static bool operator !=(DrawingBoxSymbol left, DrawingBoxSymbol right)
=> !left.Equals(right);
{
return !left.Equals(right);
}
}
}
24 changes: 17 additions & 7 deletions src/Consolonia.Core/Drawing/PixelBufferImplementation/Pixel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,30 @@ private static Color MergeColors(Color target, Color source)
}

public bool Equals(Pixel other)
=> Foreground.Equals(other.Foreground) &&
Background.Equals(other.Background) &&
IsCaret.Equals(IsCaret);
{
return Foreground.Equals(other.Foreground) &&
Background.Equals(other.Background) &&
IsCaret.Equals(IsCaret);
}

public override bool Equals([NotNullWhen(true)] object obj)
=> obj is Pixel other && this.Equals(other);
{
return obj is Pixel other && Equals(other);
}

public override int GetHashCode()
=> HashCode.Combine(Foreground, Background, IsCaret);
{
return HashCode.Combine(Foreground, Background, IsCaret);
}

public static bool operator ==(Pixel left, Pixel right)
=> left.Equals(right);
{
return left.Equals(right);
}

public static bool operator !=(Pixel left, Pixel right)
=> !left.Equals(right);
{
return !left.Equals(right);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,30 @@ public PixelBackground Shade()

return new PixelBackground(newMode, newColor);
}

public bool Equals(PixelBackground other)
=> Color.Equals(other.Color) && Mode == other.Mode;
{
return Color.Equals(other.Color) && Mode == other.Mode;
}

public override bool Equals([NotNullWhen(true)] object obj)
=> obj is PixelBackground other && this.Equals(other);
{
return obj is PixelBackground other && Equals(other);
}

public override int GetHashCode()
=> HashCode.Combine(Color, Mode);
{
return HashCode.Combine(Color, Mode);
}

public static bool operator ==(PixelBackground left, PixelBackground right)
=> left.Equals(right);
{
return left.Equals(right);
}

public static bool operator !=(PixelBackground left, PixelBackground right)
=> !left.Equals(right);
{
return !left.Equals(right);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,32 @@ public PixelForeground Blend(PixelForeground pixelAboveForeground)
}

public bool Equals(PixelForeground other)
=> Symbol.Equals(other.Symbol) &&
Color.Equals(other.Color) &&
Weight == other.Weight &&
Style == other.Style &&
Equals(TextDecorations, other.TextDecorations);
{
return Symbol.Equals(other.Symbol) &&
Color.Equals(other.Color) &&
Weight == other.Weight &&
Style == other.Style &&
Equals(TextDecorations, other.TextDecorations);
}

public override bool Equals([NotNullWhen(true)] object obj)
=> obj is PixelForeground other && this.Equals(other);
{
return obj is PixelForeground other && Equals(other);
}

public override int GetHashCode()
=> HashCode.Combine(Symbol, Color, (int)Weight, (int)Style, TextDecorations);
{
return HashCode.Combine(Symbol, Color, (int)Weight, (int)Style, TextDecorations);
}

public static bool operator ==(PixelForeground left, PixelForeground right)
=> left.Equals(right);
{
return left.Equals(right);
}

public static bool operator !=(PixelForeground left, PixelForeground right)
=> !left.Equals(right);
{
return !left.Equals(right);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,28 @@ public ISymbol Blend(ref ISymbol symbolAbove)
}

public bool Equals(SimpleSymbol other)
=> Text.Equals(other.Text, StringComparison.Ordinal);
{
return Text.Equals(other.Text, StringComparison.Ordinal);
}

public override bool Equals([NotNullWhen(true)] object obj)
=> obj is SimpleSymbol other && this.Equals(other);
{
return obj is SimpleSymbol other && Equals(other);
}

public override int GetHashCode()
=> Text.GetHashCode(StringComparison.Ordinal);
{
return Text.GetHashCode(StringComparison.Ordinal);
}

public static bool operator ==(SimpleSymbol left, SimpleSymbol right)
=> left.Equals(right);
{
return left.Equals(right);
}

public static bool operator !=(SimpleSymbol left, SimpleSymbol right)
=> !left.Equals(right);
{
return !left.Equals(right);
}
}
}
}
50 changes: 25 additions & 25 deletions src/Consolonia.Core/Drawing/RenderTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,38 +109,38 @@ private void RenderToDevice()
var flushingBuffer = new FlushingBuffer(_console);

for (ushort y = 0; y < pixelBuffer.Height; y++)
for (ushort x = 0; x < pixelBuffer.Width;)
{
Pixel pixel = pixelBuffer[(PixelBufferCoordinate)(x, y)];
for (ushort x = 0; x < pixelBuffer.Width;)
{
Pixel pixel = pixelBuffer[(PixelBufferCoordinate)(x, y)];

if (pixel.IsCaret)
{
if (caretPosition != null)
throw new InvalidOperationException("Caret is already shown");
caretPosition = new PixelBufferCoordinate(x, y);
}
if (pixel.IsCaret)
{
if (caretPosition != null)
throw new InvalidOperationException("Caret is already shown");
caretPosition = new PixelBufferCoordinate(x, y);
}

/* todo: There is not IWindowImpl.Invalidate anymore.
if (!_consoleWindow.InvalidatedRects.Any(rect =>
rect.ContainsExclusive(new Point(x, y)))) continue;*/
if (pixel.Background.Mode != PixelBackgroundMode.Colored)
throw new InvalidOperationException(
"All pixels in the buffer must have exact console color before rendering");
/* todo: There is not IWindowImpl.Invalidate anymore.
if (!_consoleWindow.InvalidatedRects.Any(rect =>
rect.ContainsExclusive(new Point(x, y)))) continue;*/
if (pixel.Background.Mode != PixelBackgroundMode.Colored)
throw new InvalidOperationException(
"All pixels in the buffer must have exact console color before rendering");


//todo: indexOutOfRange during resize
if (_cache[x, y] == pixel)
{
x++;
continue;
}
//todo: indexOutOfRange during resize
if (_cache[x, y] == pixel)
{
x++;
continue;
}

_cache[x, y] = pixel;
_cache[x, y] = pixel;

flushingBuffer.WritePixel(new PixelBufferCoordinate(x, y), pixel);
flushingBuffer.WritePixel(new PixelBufferCoordinate(x, y), pixel);

x += pixel.Foreground.Symbol.Width;
}
x += pixel.Foreground.Symbol.Width;
}

flushingBuffer.Flush();

Expand Down
19 changes: 9 additions & 10 deletions src/Tests/Consolonia.Core.Tests/DrawingBoxSymbolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ public void BlendAllSymbols()
};

foreach ((byte code1, string _) in symbols)
foreach ((byte code2, string _) in symbols)
{
ISymbol symbol1 = new DrawingBoxSymbol(code1);
ISymbol symbol2 = new DrawingBoxSymbol(code2);
ISymbol blendedSymbol = symbol1.Blend(ref symbol2);
if (symbol1.Text != symbol2.Text)
Debug.WriteLine($"{symbol1.Text} + {symbol2.Text} => {blendedSymbol.Text}");
Assert.That(blendedSymbol.Text, Is.Not.Null);
}
foreach ((byte code2, string _) in symbols)
{
ISymbol symbol1 = new DrawingBoxSymbol(code1);
ISymbol symbol2 = new DrawingBoxSymbol(code2);
ISymbol blendedSymbol = symbol1.Blend(ref symbol2);
if (symbol1.Text != symbol2.Text)
Debug.WriteLine($"{symbol1.Text} + {symbol2.Text} => {blendedSymbol.Text}");
Assert.That(blendedSymbol.Text, Is.Not.Null);
}
}

[Test]
Expand Down Expand Up @@ -112,6 +112,5 @@ public void Hash()
set2.Add(new DrawingBoxSymbol(0b0000_1111));
Assert.That(set2.Count, Is.EqualTo(1));
}

}
}
Loading

0 comments on commit 2e4dd41

Please sign in to comment.