Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/190-strange-coloring-ega-mode' i…
Browse files Browse the repository at this point in the history
…nto 190-strange-coloring-ega-mode
  • Loading branch information
jinek committed Dec 26, 2024
2 parents 1bedda1 + febcb3b commit f105ff3
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 37 deletions.
8 changes: 5 additions & 3 deletions src/Consolonia.Core/ApplicationStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public static class ApplicationStartup
StartConsolonia<TApp>(new DefaultNetConsole(), new EgaConsoleColorMode(), args);
}

public static void StartConsolonia<TApp>(IConsole console, IConsoleColorMode consoleColorMode, params string[] args) where TApp : Application, new()
public static void StartConsolonia<TApp>(IConsole console, IConsoleColorMode consoleColorMode,
params string[] args) where TApp : Application, new()
{
ClassicDesktopStyleApplicationLifetime lifetime = BuildLifetime<TApp>(console, consoleColorMode, args);

Expand Down Expand Up @@ -56,7 +57,8 @@ public static AppBuilder UseConsolonia(this AppBuilder builder)
}, nameof(ConsoloniaRenderInterface));
}

public static ClassicDesktopStyleApplicationLifetime BuildLifetime<TApp>(IConsole console, IConsoleColorMode consoleColorMode, string[] args)
public static ClassicDesktopStyleApplicationLifetime BuildLifetime<TApp>(IConsole console,
IConsoleColorMode consoleColorMode, string[] args)
where TApp : Application, new()
{
AppBuilder consoloniaAppBuilder = AppBuilder.Configure<TApp>()
Expand All @@ -76,7 +78,7 @@ private static ClassicDesktopStyleApplicationLifetime CreateLifetime(AppBuilder
ShutdownMode = ShutdownMode.OnMainWindowClose
};
builder.SetupWithLifetime(lifetime);

return lifetime;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// ReSharper disable once CheckNamespace

namespace Consolonia
{
public enum EgaColorMode : byte
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void SetAttributes(InputLessDefaultNetConsole console, Color background,
(ConsoleColor backgroundConsoleColor, EgaColorMode mode) = ConvertToConsoleColorMode(background);
if (mode is not EgaColorMode.Colored)
ConsoloniaPlatform.RaiseNotSupported(62144, foreground);


(ConsoleColor foregroundConsoleColor, _) = ConvertToConsoleColorMode(foreground);
//todo: if mode is transparent, don't print foreground. if shaded - shade it
Expand Down Expand Up @@ -108,7 +108,7 @@ static string GetAnsiCode(ConsoleColor color, bool isBackground)
$"\x1b[{(isBackground ? 100 + (ansiCode - 8) : 90 + (ansiCode - 8))}m";
}
}

public static (ConsoleColor, EgaColorMode) ConvertToConsoleColorMode(Color color)
{
ConsoleColor consoleColor = MapToConsoleColor(color);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Text;
using Avalonia.Media;
using Consolonia.Core.Infrastructure;
Expand Down
3 changes: 2 additions & 1 deletion src/Consolonia.Core/Drawing/RenderTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ private void RenderToDevice()
{
_console.SetCaretPosition((PixelBufferCoordinate)caretPosition);
_console.WriteText(pixelBuffer.CaretStyle switch
{//todo: may be better to move low level stuff to IConsole
{
//todo: may be better to move low level stuff to IConsole
CaretStyle.BlinkingBar => Esc.BlinkingBarCursor,
CaretStyle.SteadyBar => Esc.SteadyBarCursor,
CaretStyle.BlinkingBlock => Esc.BlinkingBlockCursor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void Print(PixelBufferCoordinate bufferPoint, Color background, Color for
sb.Clear();

consoleColorMode.SetAttributes(this, background, foreground, weight);

sb.Append(str);
sb.Append(Esc.Reset);

Expand Down
1 change: 0 additions & 1 deletion src/Consolonia.Gallery/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public App()
Styles.Add(new MaterialTheme());
//todo: automatically switch to turbovision if only 16 colors are supported
/*Styles.Add(new TurboVisionTheme());*/

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -468,26 +468,26 @@
Foreground="YellowGreen"
Text="YellowGreen" />
</WrapPanel>

<ItemsControl Grid.Row="2"
Height="16"
x:Name="FourBitControl">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Background="{DynamicResource ThemeBackgroundBrush}"
Orientation="Vertical"/>
Orientation="Vertical" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="galleryViews:ConsoleColorItem">
<DockPanel LastChildFill="True" Margin="1,1,0,0">
<DockPanel LastChildFill="True"
Margin="1,1,0,0">
<Rectangle Width="2"
Margin="0,0,1,0"
Height="1"
DockPanel.Dock="Left"
Fill="{Binding Brush}" />
<TextBlock Text="{Binding Name}"

Foreground="{Binding Brush}" />
</DockPanel>
</DataTemplate>
Expand Down
3 changes: 2 additions & 1 deletion src/Consolonia.Gallery/View/ControlsListView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
IsTabStop="false"
SelectedIndex="0"
HorizontalContentAlignment="Stretch">
<ComboBoxItem Content="Material" IsSelected="True" />
<ComboBoxItem Content="Material"
IsSelected="True" />
<ComboBoxItem Content="Fluent" />
<ComboBoxItem Content="TurboVision" />
<ComboBoxItem Content="TurboVisionDark" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static AppBuilder UseAutoDetectConsoleColorMode(this AppBuilder builder)
result = new EgaConsoleColorMode();
break;
}

return builder.UseConsoleColorMode(result);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,42 @@ namespace Consolonia.Core.Tests.WithLifetimeFixture
[SetUpFixture]
public class LifetimeSetupFixture : IDisposable
{
private class ContextApp2 : Application;

private bool _disposedValue;
private ClassicDesktopStyleApplicationLifetime _lifetime;

private IDisposable _scope;

// // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
// ~DrawingContextImplTests()
// {
// // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
// Dispose(disposing: false);
// }

public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(true);
SuppressFinalize(this);
}

[OneTimeSetUp]
public void Setup()
{
AvaloniaLocator.Current = new AvaloniaLocator()
.Bind<IConsole>().ToConstant(new UnitTestConsole(new PixelBufferSize(100, 100)));

_scope = AvaloniaLocator.EnterScope();
_lifetime = ApplicationStartup.BuildLifetime<ContextApp2>(new DummyConsole(), new RgbConsoleColorMode(), []);
_lifetime = ApplicationStartup.BuildLifetime<ContextApp2>(new DummyConsole(), new RgbConsoleColorMode(),
[]);
}

[OneTimeTearDown]
public void TearDown()
{
Dispose();
}

private IDisposable _scope;
private ClassicDesktopStyleApplicationLifetime _lifetime;
private bool _disposedValue;


protected virtual void Dispose(bool disposing)
{
if (!_disposedValue)
Expand All @@ -54,18 +68,6 @@ protected virtual void Dispose(bool disposing)
}
}

// // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
// ~DrawingContextImplTests()
// {
// // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
// Dispose(disposing: false);
// }

public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(true);
SuppressFinalize(this);
}
private class ContextApp2 : Application;
}
}

0 comments on commit f105ff3

Please sign in to comment.