Skip to content

Commit

Permalink
Merge pull request #295 from gui-cs/v2_true_color
Browse files Browse the repository at this point in the history
Designer Alpha Release
  • Loading branch information
tznind authored Aug 23, 2024
2 parents ce6233d + 3704070 commit df51563
Show file tree
Hide file tree
Showing 7 changed files with 319 additions and 158 deletions.
19 changes: 12 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ on: push

jobs:
package:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Build
run: cd src && dotnet build

- name: Test
run: |
cd tests && dotnet test --configuration Debug --verbosity normal --collect:'XPlat Code Coverage' --settings coverlet.runsettings
- name: Move test results to accessible directory
run: |
mkdir TestResults
mv -v --backup=numbered tests/TestResults/*/*.* TestResults/
# Note: this step is currently not writing to the gist for some reason
mkdir -p TestResults
find tests/TestResults -type f -name "*.xml" -exec mv -v --backup=numbered {} TestResults/ \;
- name: Create Test Coverage Badge
uses: simon-k/[email protected]
id: create_coverage_badge
Expand All @@ -33,8 +36,10 @@ jobs:
run: |
echo "Code coverage percentage: ${{steps.create_coverage_badge.outputs.percentage}}%"
echo "Badge data: ${{steps.create_coverage_badge.outputs.badge}}"
- name: Pack
run: cd src && dotnet pack
- name: Publish to Nuget
run: cd src && dotnet pack --configuration Debug --output ./nupkg

- name: Publish to NuGet
if: contains(github.ref, 'refs/tags/v')
run: dotnet nuget push ./src/nupkg/TerminalGuiDesigner.$(fgrep \<Version\> ./src/TerminalGuiDesigner.csproj | grep -oEi '[-0-9.rc]{5,}').nupkg --api-key ${{ secrets.NUGET_KEY }} --source https://api.nuget.org/v3/index.json
run: dotnet nuget push ./src/nupkg/*.nupkg --api-key ${{ secrets.NUGET_KEY }} --source https://api.nuget.org/v3/index.json
2 changes: 1 addition & 1 deletion src/DimExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static bool IsPercent(this Dim d, out int percent)
if (d != null && d.IsPercent())
{
var dp = (DimPercent)d;
percent = dp.Percent;
percent = dp.Percentage;
return true;
}

Expand Down
6 changes: 4 additions & 2 deletions src/TerminalGuiDesigner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<PackageOutputPath>./nupkg</PackageOutputPath>
<ImplicitUsings>enable</ImplicitUsings>
<PackageId>TerminalGuiDesigner</PackageId>
<Version>1.1.0-rc1</Version>
<Version>2.0.0-alpha.2189</Version>
<Authors>Thomas Nind</Authors>
<Nullable>enable</Nullable>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand All @@ -33,6 +33,8 @@
<PackageIcon>logo.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageReleaseNotes>
2.0.0-alpha.2189
* Support for targetting v2 pre-release Terminal.Gui packages. Note that v2 is not backwards compatible with v1.
v1.1.0-rc1
* Prototype dual targeting dotnet 8 and 7
v1.0.25
Expand Down Expand Up @@ -146,7 +148,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="NetEscapades.Configuration.Yaml" Version="3.1.0" />
<PackageReference Include="Terminal.Gui" Version="2.0.0-v2-develop.2168" />
<PackageReference Include="Terminal.Gui" Version="2.0.0-v2-develop.2189" />
<PackageReference Include="nlog" Version="5.2.7" />
<PackageReference Include="Basic.Reference.Assemblies.Net80" Version="1.4.5" />
<PackageReference Include="System.CodeDom" Version="8.0.0" />
Expand Down
168 changes: 165 additions & 3 deletions src/UI/Editor.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System.Collections.ObjectModel;
using System.Reflection;
using System.Text;
using Microsoft.Extensions.Configuration;
using Terminal.Gui;
using TerminalGuiDesigner.FromCode;
using TerminalGuiDesigner.Operations;
using TerminalGuiDesigner.ToCode;
using TerminalGuiDesigner.UI.Windows;
using Attribute = Terminal.Gui.Attribute;

namespace TerminalGuiDesigner.UI;

Expand Down Expand Up @@ -238,8 +240,159 @@ public override void OnDrawContent(Rectangle bounds)

return;
}
else
{
var top = new Rectangle(0, 0, bounds.Width, rootCommandsListView.Frame.Top - 1);
RenderTitle(top);
}
}

private void RenderTitle(Rectangle inArea)
{
var assembly = typeof(Label).Assembly;
var informationalVersion = assembly
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion
?? "unknown";

if (informationalVersion.Contains("+"))
{
informationalVersion = informationalVersion.Substring(0, informationalVersion.IndexOf('+'));
}

// The main ASCII art text block
string artText = """
___________ .__ .__
\__ ___/__________ _____ |__| ____ _____ | |
| |_/ __ \_ __ \/ \| |/ \\__ \ | |
| |\ ___/| | \/ Y Y \ | | \/ __ \| |__
|____| \___ >__| |__|_| /__|___| (____ /____/
\/ \/ \/ \/
________ .__ ________ .__
/ _____/ __ __|__| \______ \ ____ _____|__| ____ ____ ___________
/ \ ___| | \ | | | \_/ __ \ / ___/ |/ ___\ / \_/ __ \_ __ \
\ \_\ \ | / | | ` \ ___/ \___ \| / /_/ > | \ ___/| | \/
\______ /____/|__| /_______ /\___ >____ >__\___ /|___| /\___ >__|
\/ \/ \/ \/ /_____/ \/ \/
""";

// Standardize the text
artText = artText.Replace("\r\n", "\n");

// The version information line
string versionLine = $"(Alpha - {informationalVersion} )";

// Split the ASCII art into lines
var artLines = artText.Split('\n');

// Calculate the starting point for centering the art text
int artHeight = artLines.Length;
int artWidth = artLines.Max(line => line.Length);

// Check if there's enough space for the ASCII art and the version line
if (inArea.Width < artWidth || inArea.Height < (artHeight + 2)) // +2 allows space for version line
{
// Not enough space, render the simpler title

// Simple title and version
string simpleTitle = "Terminal Gui Designer";
int simpleTitleX = inArea.X + (inArea.Width - simpleTitle.Length) / 2;
int versionLineX = inArea.X + (inArea.Width - versionLine.Length) / 2;

// Create the gradient
var gradient = new Gradient(
new[]
{
new Color("#FF0000"), // Red
new Color("#FF7F00"), // Orange
new Color("#FFFF00"), // Yellow
new Color("#00FF00"), // Green
new Color("#00FFFF"), // Cyan
new Color("#0000FF"), // Blue
new Color("#8B00FF") // Violet
},
new[] { 10 }
);
var fill = new GradientFill(inArea, gradient, GradientDirection.Diagonal);

// Render the simple title
for (int i = 0; i < simpleTitle.Length; i++)
{
int x = simpleTitleX + i;
int y = inArea.Y + inArea.Height / 2 - 1; // Center the title vertically

var colorAtPoint = fill.GetColor(new Point(x, y));
Driver.SetAttribute(new Attribute(new Color(colorAtPoint), new Color(ColorName.Black)));
this.AddRune(x, y, (Rune)simpleTitle[i]);
}

// Render the version line below the simple title
for (int i = 0; i < versionLine.Length; i++)
{
int x = versionLineX + i;
int y = inArea.Y + inArea.Height / 2; // Line below the title

var colorAtPoint = fill.GetColor(new Point(x, y));
Driver.SetAttribute(new Attribute(new Color(colorAtPoint), new Color(ColorName.Black)));
this.AddRune(x, y, (Rune)versionLine[i]);
}
}
else
{
// Enough space, render the ASCII art block

int artStartX = inArea.X + (inArea.Width - artWidth) / 2;
int artStartY = inArea.Y + (inArea.Height - artHeight - 1) / 2; // -1 for the version line below

// Create the gradient
var gradient = new Gradient(
new[]
{
new Color("#FF0000"), // Red
new Color("#FF7F00"), // Orange
new Color("#FFFF00"), // Yellow
new Color("#00FF00"), // Green
new Color("#00FFFF"), // Cyan
new Color("#0000FF"), // Blue
new Color("#8B00FF") // Violet
},
new[] { 10 }
);
var fill = new GradientFill(inArea, gradient, GradientDirection.Diagonal);

// Render the ASCII art block
for (int i = 0; i < artLines.Length; i++)
{
string line = artLines[i];
for (int j = 0; j < line.Length; j++)
{
int x = artStartX + j;
int y = artStartY + i;

var colorAtPoint = fill.GetColor(new Point(x, y));
Driver.SetAttribute(new Attribute(new Color(colorAtPoint), new Color(ColorName.Black)));
this.AddRune(x, y, (Rune)line[j]);
}
}

// Render the version line below the ASCII art
int versionLineX = inArea.X + (inArea.Width - versionLine.Length) / 2;
int versionLineY = artStartY + artHeight;

for (int i = 0; i < versionLine.Length; i++)
{
int x = versionLineX + i;
int y = versionLineY;

var colorAtPoint = fill.GetColor(new Point(x, y));
Driver.SetAttribute(new Attribute(new Color(colorAtPoint), new Color(ColorName.Black)));
this.AddRune(x, y, (Rune)versionLine[i]);
}
}
}




/// <summary>
/// Event handler for <see cref="Application.KeyDown"/>.
/// </summary>
Expand Down Expand Up @@ -516,7 +669,7 @@ private string GetHelp()
{this.keyMap.Delete} - Delete selected View
Shift+Cursor - Move focused View
Ctrl+Cursor - Move focused View quickly
Ctrl+Q - Quit
Esc - Quit
{this.keyMap.Undo} - Undo
{this.keyMap.Redo} - Redo
""";
Expand Down Expand Up @@ -547,12 +700,21 @@ private void BuildRootMenu()
this.rootCommandsListView = new ListView()
{
X = Pos.Center(),
Y = Pos.Center(),
Y = Pos.Percent(75),
Width = maxWidth,
Height = 3,
ColorScheme = new DefaultColorSchemes().GetDefaultScheme("greyOnBlack").Scheme,
ColorScheme = new ColorScheme
(
new Attribute(new Color(Color.White),new Color(Color.Black)),
new Attribute(new Color(Color.Black),new Color(Color.White)),
new Attribute(new Color(Color.White), new Color(Color.Black)),
new Attribute(new Color(Color.White), new Color(Color.Black)),
new Attribute(new Color(Color.Black), new Color(Color.White))
),
};
this.rootCommandsListView.SetSource(rootCommands);
this.rootCommandsListView.SelectedItem = 0;

this.rootCommandsListView.KeyDown += (_, e) =>
{
if (e == Key.Enter)
Expand Down
Loading

0 comments on commit df51563

Please sign in to comment.