Skip to content

Commit

Permalink
Merge branch 'develop' into v1_showcase
Browse files Browse the repository at this point in the history
  • Loading branch information
tig authored Sep 29, 2023
2 parents d6a9b2d + bfd8b4e commit 7a0e0d7
Show file tree
Hide file tree
Showing 17 changed files with 271 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/api-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup .NET Core
uses: actions/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup .NET Core
uses: actions/setup-dotnet@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0 # fetch-depth is needed for GitVersion

Expand Down
3 changes: 2 additions & 1 deletion Terminal.Gui/Core/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,8 @@ public static void End (RunState runState)
MdiTop.OnAllChildClosed ();
} else {
SetCurrentAsTop ();
Current.OnEnter (Current);
runState.Toplevel.OnLeave (Current);
Current.OnEnter (runState.Toplevel);
}
Refresh ();
}
Expand Down
32 changes: 17 additions & 15 deletions Terminal.Gui/Core/Border.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public override void Redraw (Rect bounds)
/// <inheritdoc/>
public override void OnCanFocusChanged ()
{
if (Border.Child != null) {
if (Border?.Child != null) {
Border.Child.CanFocus = CanFocus;
}
base.OnCanFocusChanged ();
Expand Down Expand Up @@ -375,8 +375,10 @@ public Thickness BorderThickness {
public Color BorderBrush {
get => borderBrush != null ? (Color)borderBrush : (Color)(-1);
set {
borderBrush = value;
OnBorderChanged ();
if (Enum.IsDefined (typeof (Color), value)) {
borderBrush = value;
OnBorderChanged ();
}
}
}

Expand All @@ -386,8 +388,10 @@ public Color BorderBrush {
public Color Background {
get => background != null ? (Color)background : (Color)(-1);
set {
background = value;
OnBorderChanged ();
if (Enum.IsDefined (typeof (Color), value)) {
background = value;
OnBorderChanged ();
}
}
}

Expand Down Expand Up @@ -445,12 +449,10 @@ public View Child {

private void Parent_Removed (View obj)
{
if (borderBrush != null)
{
if (borderBrush != null) {
BorderBrush = default;
}
if (background != null)
{
if (background != null) {
Background = default;
}
child.Removed -= Parent_Removed;
Expand Down Expand Up @@ -800,7 +802,7 @@ private void DrawParentBorder (Rect frame, bool fill = true)
SetBorderBrush (driver);

// Draw the upper BorderThickness
for (int r = frame.Y;
for (int r = Math.Max (frame.Y, 0);
r < Math.Min (frame.Y + borderThickness.Top, frame.Bottom); r++) {
for (int c = frame.X;
c < Math.Min (frame.Right, driver.Cols); c++) {
Expand All @@ -810,7 +812,7 @@ private void DrawParentBorder (Rect frame, bool fill = true)
}

// Draw the left BorderThickness
for (int r = Math.Min (frame.Y + borderThickness.Top, frame.Bottom);
for (int r = Math.Max (Math.Min (frame.Y + borderThickness.Top, frame.Bottom), 0);
r < Math.Min (frame.Bottom - borderThickness.Bottom, driver.Rows); r++) {
for (int c = frame.X;
c < Math.Min (frame.X + borderThickness.Left, frame.Right); c++) {
Expand All @@ -820,7 +822,7 @@ private void DrawParentBorder (Rect frame, bool fill = true)
}

// Draw the right BorderThickness
for (int r = Math.Min (frame.Y + borderThickness.Top, frame.Bottom);
for (int r = Math.Max (Math.Min (frame.Y + borderThickness.Top, frame.Bottom), 0);
r < Math.Min (frame.Bottom - borderThickness.Bottom, driver.Rows); r++) {
for (int c = Math.Max (frame.Right - borderThickness.Right, frame.X);
c < Math.Min (frame.Right, driver.Cols); c++) {
Expand All @@ -842,7 +844,7 @@ private void DrawParentBorder (Rect frame, bool fill = true)
SetBackground (driver);

// Draw the upper Padding
for (int r = frame.Y + borderThickness.Top;
for (int r = Math.Max (frame.Y + borderThickness.Top, 0);
r < Math.Min (frame.Y + sumThickness.Top, frame.Bottom - borderThickness.Bottom); r++) {
for (int c = frame.X + borderThickness.Left;
c < Math.Min (frame.Right - borderThickness.Right, driver.Cols); c++) {
Expand All @@ -852,7 +854,7 @@ private void DrawParentBorder (Rect frame, bool fill = true)
}

// Draw the left Padding
for (int r = frame.Y + sumThickness.Top;
for (int r = Math.Max (frame.Y + sumThickness.Top, 0);
r < Math.Min (frame.Bottom - sumThickness.Bottom, driver.Rows); r++) {
for (int c = frame.X + borderThickness.Left;
c < Math.Min (frame.X + sumThickness.Left, frame.Right - borderThickness.Right); c++) {
Expand All @@ -862,7 +864,7 @@ private void DrawParentBorder (Rect frame, bool fill = true)
}

// Draw the right Padding
for (int r = frame.Y + sumThickness.Top;
for (int r = Math.Max (frame.Y + sumThickness.Top, 0);
r < Math.Min (frame.Bottom - sumThickness.Bottom, driver.Rows); r++) {
for (int c = Math.Max (frame.Right - sumThickness.Right, frame.X + sumThickness.Left);
c < Math.Max (frame.Right - borderThickness.Right, frame.X + sumThickness.Left); c++) {
Expand Down
1 change: 1 addition & 0 deletions Terminal.Gui/Core/Toplevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ void FocusNearestView (IEnumerable<View> views, Direction direction)
///<inheritdoc/>
public override void Add (View view)
{
CanFocus = true;
AddMenuStatusBar (view);
base.Add (view);
}
Expand Down
3 changes: 0 additions & 3 deletions Terminal.Gui/Core/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -995,9 +995,6 @@ public virtual void Remove (View view)
view.tabIndex = -1;
SetNeedsLayout ();
SetNeedsDisplay ();
if (subviews.Count < 1) {
CanFocus = false;
}
foreach (var v in subviews) {
if (v.Frame.IntersectsWith (touched))
view.SetNeedsDisplay ();
Expand Down
3 changes: 0 additions & 3 deletions Terminal.Gui/Core/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,6 @@ public override void Remove (View view)
SetNeedsDisplay ();
contentView.Remove (view);

if (contentView.InternalSubviews.Count < 1) {
CanFocus = false;
}
RemoveMenuStatusBar (view);
if (view != contentView && Focused == null) {
FocusFirst ();
Expand Down
50 changes: 31 additions & 19 deletions Terminal.Gui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ dotnet-gitversion

The project version (the nuget package and in `Terminal.Gui.dll`) is determined from the latest `git tag`.

The format of version numbers is `vmajor.minor.patch.build.height` and follows the [Semantic Versioning](https://semver.org/) rules.
The format of version numbers is `vmajor.minor.patch.build` and follows the [Semantic Versioning](https://semver.org/) rules.

To define a new version (e.g. with a higher `major`, `minor`, `patch`, or `build` value) tag a commit using `git tag`:

```powershell
git tag v1.3.4-beta.5 -a -m "Release v1.3.4 Beta 5"
git tag v1.2.3 -a -m "Release v1.2.3"
dotnet-gitversion /updateprojectfiles
dotnet build -c Release
```
Expand All @@ -47,23 +47,27 @@ dotnet build -c Release

Doing so will update the `.csproj` files in your branch with version info, which we do not want.

## Automatic Nuget Publishing

The following actions will publish the Terminal.Gui package to Nuget:

* A new version tag is defined and pushed to `main` - this is the normal release process.
* A push to the `main` branch without a new version tag - this is a release-candidate build and will be of the form `1.2.3-rc.4`
* A push to the `develop` branch - this is a pre-release build and will be of the form `1.2.3-pre.4`

## Publishing a Release of Terminal.Gui

First, use the [Semantic Versioning](https://semver.org/) rules.to determine the new verison number.
First, use the [Semantic Versioning](https://semver.org/) rules to determine the new version number.

Given a version number MAJOR.MINOR.PATCH, increment the:

* MAJOR version when you make incompatible API changes
* MINOR version when you add functionality in a backwards compatible manner
* PATCH version when you make backwards compatible bug fixes

Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.
* MINOR version when you add functionality in a backward-compatible manner
* PATCH version when you make backwards-compatible bug fixes

To release a new version (e.g. with a higher `major`, `minor`, or `patch` value) tag a commit using `git tag` and then push that tag directly to the `main` branch on `github.com/gui-cs/Terminal.Gui` (`upstream`).

The `tag` must be of the form `v<major>.<minor>.<patch>`, e.g. `v2.3.4`.

`patch` can indicate pre-release or not (e.g. `pre`, `beta`, `rc`, etc...).
The `tag` must be of the form `v<major>.<minor>.<patch>`, e.g. `v1.2.3`.

### 1) Verify the `develop` branch is ready for release

Expand All @@ -72,20 +76,22 @@ The `tag` must be of the form `v<major>.<minor>.<patch>`, e.g. `v2.3.4`.

### 2) Create a pull request for the release in the `develop` branch

The PR title should be of the form "Release v2.3.4"
The PR title should be of the form "Release v1.2.3"

```powershell
git checkout develop
git pull upstream develop
git checkout -b v2_3_4
git add .
git commit -m "Release v2.3.4"
git commit -m "Release v1.2.3"
git push
```

Go to the link printed by `git push` and fill out the Pull Request.

### 3) On github.com, verify the build action worked on your fork, then merge the PR
### 3) On github.com, verify the build action worked on your fork, then merge the PR to `develop`

* Merging the PR will trigger the publish action on `upstream` (the main repo) and publish the Nuget package as a pre-release (e.g. `1.2.3-pre.1`).

### 4) Pull the merged `develop` from `upstream`

Expand All @@ -104,20 +110,30 @@ git merge develop

Fix any merge errors.

At this point, to release a release candidate, push the `main` branch `upstream` without a new tag.

```powershell
git push upstream main
```

This will publish `1.2.3-rc.1` to Nuget.

### 6) Create a new annotated tag for the release on `main`

```powershell
git tag v2.3.4 -a -m "Release v2.3.4"
git tag v1.2.3 -a -m "Release v1.2.3"
```

### 7) Push the new tag to `main` on `upstream`

```powershell
git push --atomic upstream main v2.3.4
git push --atomic upstream main v1.2.3
```

*See https://stackoverflow.com/a/3745250/297526*

This will publish `1.2.3` to Nuget.

### 8) Monitor Github Actions to ensure the Nuget publishing worked.

https://github.com/gui-cs/Terminal.Gui/actions
Expand All @@ -142,10 +158,6 @@ git push upstream develop

https://www.nuget.org/packages/Terminal.Gui

When a new version tag is defined and merged into `main`, a Nuget package will be generated by a Github Action.

If the version is pre-release (includes a hyphen, e.g. `1.3.4-beta.5`) the Nuget package will be tagged as pre-release.

Miguel & Tig can hide defunct/old Nuget packages.

## Contributing
Expand Down
2 changes: 1 addition & 1 deletion Terminal.Gui/Views/ContextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private void Container_Closing (ToplevelClosingEventArgs obj)
/// </summary>
public void Hide ()
{
menuBar.CleanUp ();
menuBar?.CleanUp ();
Dispose ();
}

Expand Down
6 changes: 3 additions & 3 deletions UICatalog/UICatalog.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>8.0</LangVersion>
<LangVersion>9.0</LangVersion>
<StartupObject>UICatalog.UICatalogApp</StartupObject>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<!-- Version numbers are automatically updated by gitversion when a release is released -->
Expand All @@ -20,8 +20,8 @@
<None Update="./Scenarios/Spinning_globe_dark_small.gif" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.18.1" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.0.2" />
<PackageReference Include="CsvHelper" Version="30.0.1" />
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="3.1.6" />
</ItemGroup>
Expand Down
24 changes: 24 additions & 0 deletions UnitTests/Core/BorderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -619,5 +619,29 @@ public void BorderStyle_And_DrawMarginFrame_Gets_Sets ()
████████████████████
At 0,4 ", output);
}

[Fact]
public void BorderBrush_Background_Only_Is_Set_To_Valid_Color_Enum ()
{
var border = new Border ();
Assert.Equal ((Color)(-1), border.BorderBrush);
Assert.Equal ((Color)(-1), border.Background);
Assert.Null (border.GetFieldValue<string> ("borderBrush"));
Assert.Null (border.GetFieldValue<string> ("background"));

border.BorderBrush = (Color)(-1);
border.Background = (Color)(-1);
Assert.Equal ((Color)(-1), border.BorderBrush);
Assert.Equal ((Color)(-1), border.Background);
Assert.Null (border.GetFieldValue<Color?> ("borderBrush"));
Assert.Null (border.GetFieldValue<Color?> ("background"));

border.BorderBrush = Color.Blue;
border.Background = Color.White;
Assert.Equal (Color.Blue, border.BorderBrush);
Assert.Equal (Color.White, border.Background);
Assert.Equal (Color.Blue, border.GetFieldValue<Color> ("borderBrush"));
Assert.Equal (Color.White, border.GetFieldValue<Color?> ("background"));
}
}
}
Loading

0 comments on commit 7a0e0d7

Please sign in to comment.