Skip to content

Commit

Permalink
Merge pull request #25 from MorganKryze/dev
Browse files Browse the repository at this point in the history
dotnet 6 | corners | banners
  • Loading branch information
MorganKryze authored Dec 11, 2023
2 parents 3a7643d + 609c1cc commit 631a105
Show file tree
Hide file tree
Showing 17 changed files with 782 additions and 51 deletions.
1 change: 1 addition & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

| Version | Supported |
| ------- | ------------------ |
| 2.6.x | :white_check_mark: |
| 2.5.x | :white_check_mark: |
| 2.4.x | :white_check_mark: |
| 2.3.x | :white_check_mark: |
Expand Down
33 changes: 30 additions & 3 deletions docs/articles/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The tool used to generate the documentation is [DocFX](https://dotnet.github.io/
To install it, or update it,open any terminal and run the following command:

```bash
dotnet tool install -g docfx
dotnet tool update -g docfx
```

## The structure
Expand Down Expand Up @@ -82,11 +82,28 @@ Open the file "docfx.json" and modify the following lines:

To look like this:

```json
"metadata": [{
"src": [{
"files": ["bin/**/*.dll"],
"src": "../TheNameOfYourProjectFolder"
}],
"dest": "api",
"properties": {
"TargetFramework": "net7.0"
}
}],
```

### Optional

If you want to generate the documentation for the Release version only:

```json
"metadata": [{
"src": [{
"files": ["**/bin/Release/**.dll"],
"src": "../"
"src": "../StillTheNameOfYourProjectFolder"
}],
"dest": "api",
"properties": {
Expand All @@ -95,6 +112,12 @@ To look like this:
}],
```

Now when you want to build your project and update your xml file, type:

```bash
dotnet build -c Release
```

## Preview your doc

Now, back on your terminal from the root, run the following command:
Expand Down Expand Up @@ -123,7 +146,7 @@ To ensure that the documentation is generated correctly (your /// comments are t
Now your documentation is ready to be generated in the section "Api Documentation" in the generated site.

> [!NOTE]
> For more customization, you may want update the "index.md" file in the "docfx_project" folder, and create wonderful articles in the "articles" folder to explain how to use your library.
> For more customization, you may want update the "index.md" file in the "docfx_project" folder, and create wonderful articles in the "articles" folder to explain how to use your library. And **DO NOT** forget to update the "toc.yml" file to add your articles in the table of contents (else they will not be displayed).
## Deploy the doc

Expand Down Expand Up @@ -156,6 +179,10 @@ jobs:
publish_dir: docs/_site
```
> [!NOTE]
> I you renamed your "docfx_project" folder, you will have to update the line :
> run: docfx docfx_project/docfx.json -> run: docfx TheNameOfYourDocFxProjectFolder/docfx.json
Push on your branch, and create a pull request to merge it with the main branch if it is not already on the main.
Now, on every push on the main branch, the documentation will be generated and deployed on GitHub Pages.
Expand Down
19 changes: 9 additions & 10 deletions docs/articles/homescreen.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,27 @@ Now that we have seen the title, let's see how to display a banner. You may use
Core.SetTitle("Example", 2);
Core.WriteTitle();

Core.WriteBanner(true);
Core.WriteHeader();

Console.ReadKey(); //[optional]: just to keep the console clean
```

![banner](../images/banner.png)
*Demo with default arguments for the header*

To customize the banner, you can change the arguments or change the default header and footer with the `SetDefaultBanner` method.
To customize the banner, you can change the arguments or change the default header and footer with the `SetDefaultHeader` or `SetDefaultFooter` methods.

```csharp
Core.SetDefaultBanner(("Left", "Top", "Right"), ("Left", "Top", "Right"));
Core.WriteBanner(true);
Core.SetDefaultHeader(("Left", "Top", "Right"));
Core.WriteHeader(true);
Core.WriteFooter(true, ("Left", "Top", "Right"));

Console.ReadKey();
```

![banner2](../images/banner_customize.png)
*Demo with custom arguments for the header*

> [!NOTE]
> To display a footer, you may use the `WriteBanner` method with the `header` argument set to `false`.
## Easy display

The `WriteFullScreen` method is the easiest way to display a banner and a title. It will display the banner and the title with the default arguments. Here is an example of what this method replaces:
Expand All @@ -56,9 +54,10 @@ Core.WriteFullScreen("Example");
// Core.SetTitle("Example", 2);
// Core.WriteTitle();
//
// Core.SetDefaultBanner(("Left", "Top", "Right"), ("Left", "Bottom", "Right"));
// Core.WriteBanner(true);
// Core.WriteBanner(false);
// Core.SetDefaultHeader(("Left", "Top", "Right"));
// Core.SetDefaultFooter(("Left", "Top", "Right"));
// Core.WriteHeader();
// Core.WriteFooter();
//
// Core.ClearContent();
```
8 changes: 8 additions & 0 deletions docs/articles/write.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ Core.SetFont("/path/to/your/font/folder/");
> [!WARNING]
> By default, the font is only used for the title. If you want other text to use the font, you have to do it manually using the `WritePositionedStyledText` method (for an array) or a simple `Console.WriteLine` is enough for a styled string.
### Rounded corners

You may also use the `SetRoundedCorners` method to set the rounded corners to true or false for the tables.

```csharp
Core.SetRoundedCorners(true);
```

### Color panel

Finally, you may use the `GetColorPanel` property to get the color panel of the console.
Expand Down
5 changes: 3 additions & 2 deletions example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ static void Main()

Core.SetTitle("Example");
Core.WriteTitle();
Core.WriteBanner(true, true);
Core.WriteBanner(false, true);
Core.WriteHeader(true);
Core.WriteFooter(true);
Core.ClearContent();
Core.LoadingBar("[ Some example loading... ]");
Core.UpdateScreen();
Expand Down Expand Up @@ -56,6 +56,7 @@ static void Main()
List<string> student3 = new () {"03", "Maxime", "Physics", "92"};
List<string> student4 = new () {"04", "Charles", "Computer Science", "100"};
Table<string> students = new (headers, new () {student1, student2, student3, student4});
students.SetRoundedCorners(true);
students.ScrollingTableSelector(true, false, "Add student");
Core.ClearContent();
break;
Expand Down
2 changes: 1 addition & 1 deletion src/ConsoleAppVisuals/ConsoleAppVisuals.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
51 changes: 48 additions & 3 deletions src/ConsoleAppVisuals/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public static class Core
/// </summary>
/// <param name="header">The default header input.</param>
/// <param name="footer">The default footer input.</param>
[Obsolete("This method is deprecated. Use SetDefaultHeader and SetDefaultFooter instead. This method will be removed in a future release.", true)]
public static void SetDefaultBanner((string, string, string)? header = null, (string, string, string)? footer = null)
{
header ??= DefaultHeader;
Expand All @@ -99,6 +100,20 @@ public static void SetDefaultBanner((string, string, string)? header = null, (st
DefaultFooter = footer ?? DefaultFooter;
}
/// <summary>
/// This method is used to set the default header.
/// </summary>
/// <param name="left">The default header left input.</param>
/// <param name="center">The default header center input.</param>
/// <param name="right">The default header right input.</param>
public static void SetDefaultHeader(string left, string center, string right) => DefaultHeader = (left, center, right);
/// <summary>
/// This method is used to set the default footer.
/// </summary>
/// <param name="left">The default footer left input.</param>
/// <param name="center">The default footer center input.</param>
/// <param name="right">The default footer right input.</param>
public static void SetDefaultFooter(string left, string center, string right) => DefaultFooter = (left, center, right);
/// <summary>
/// This method changes the font and background colors of the console in order to apply
/// a negative to highlight the text or not.
/// </summary>
Expand Down Expand Up @@ -272,6 +287,7 @@ public static void WritePositionedStyledText(string[]? text = null, int? line =
/// <param name="banner">The banner to print.</param>
/// <param name="header">If true, the banner is printed at the top of the console. If false, the banner is printed at the bottom of the console.</param>
/// <param name="continuous">If true, the title is not continuously printed.</param>
[Obsolete("This method is deprecated. Use WriteHeader and WriteFooter instead. This method will be removed in a future release.", true)]
public static void WriteBanner(bool header = true, bool continuous = true, (string, string, string)? banner = null)
{
(string, string, string) _banner = banner ?? (header ? DefaultHeader : DefaultFooter); // If banner is null, _banner is set to the default header or footer.
Expand All @@ -282,6 +298,35 @@ public static void WriteBanner(bool header = true, bool continuous = true, (stri
WritePositionedString(_banner.BannerToString(), default, true, header ? HeaderHeight : FooterHeight);
ApplyNegative(default);
}
/// <summary>
/// This method prints a header in the console.
/// </summary>
/// <param name="continuous">If true, the header is not continuously printed.</param>
/// <param name="header">The header to print.</param>
public static void WriteHeader(bool continuous = true, (string, string, string)? header = null)
{
(string, string, string) _banner = header ?? DefaultHeader;
ApplyNegative(true);
if (continuous)
WriteContinuousString(_banner.BannerToString(), HeaderHeight, true);
else
WritePositionedString(_banner.BannerToString(), default, true, HeaderHeight);
ApplyNegative(default);
}
/// <summary>
/// This method prints a footer in the console.
/// </summary>
/// <param name="continuous">If true, the footer is not continuously printed.</param>
/// <param name="footer">The footer to print.</param>
public static void WriteFooter(bool continuous = true, (string, string, string)? footer = null)
{
(string, string, string) _banner = footer ?? DefaultFooter;
ApplyNegative(true);
if (continuous)
WriteContinuousString(_banner.BannerToString(), FooterHeight, true);
else
WritePositionedString(_banner.BannerToString(), default, true, FooterHeight);
}
/// <summary>
/// This method prints a paragraph in the console.
/// </summary>
Expand Down Expand Up @@ -519,10 +564,10 @@ public static void WriteFullScreen(string? title = null, bool continuous = false
SetTitle(title);
WriteTitle();
}
else if (Core.s_title.Item1 is not null)
else if (s_title.Item1 is not null)
WriteTitle();
WriteBanner(true, continuous, header);
WriteBanner(false, continuous, footer);
WriteHeader(continuous, header);
WriteFooter(continuous, footer);
ClearContent();
}
/// <summary>
Expand Down
24 changes: 17 additions & 7 deletions src/ConsoleAppVisuals/Table.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class Table<T>
private readonly List<string>? rawHeaders;
private List<List<T>>? rawLines;
private string[]? displayArray;
private bool roundedCorners = true;
#endregion

#region Constructor
Expand Down Expand Up @@ -76,8 +77,8 @@ private void BuildTable()
}
stringList.Add(line);
}
stringList.Insert(0, "┌".PadRight(stringList[0].Length - 1, '─') + "┐");
stringList.Add("└".PadRight(stringList[0].Length - 1, '─') + "┘");
stringList.Insert(0, corners[0].ToString().PadRight(stringList[0].Length - 1, '─') + corners[1]);
stringList.Add(corners[2].ToString().PadRight(stringList[0].Length - 1, '─') + corners[3]);
displayArray = stringList.ToArray();

}
Expand All @@ -104,11 +105,11 @@ private void BuildTable()
}
stringList.Add(header);

string border = "┌";
string border = corners[0].ToString();
for (int i = 0; i < rawHeaders.Count; i++)
{
border += new string('─', localMax[i] + 2);
border += (i != rawHeaders.Count - 1) ? "┬" : "┐";
border += (i != rawHeaders.Count - 1) ? "┬" : corners[1].ToString();
}
stringList.Insert(0, border);

Expand All @@ -134,11 +135,11 @@ private void BuildTable()
stringList.Add(line);
}

border = "└";
border = corners[2].ToString();
for (int i = 0; i < rawHeaders.Count; i++)
{
border += new string('─', localMax[i] + 2);
border += (i != rawHeaders.Count - 1) ? "┴" : "┘";
border += (i != rawHeaders.Count - 1) ? "┴" : corners[3].ToString();
}
stringList.Add(border);

Expand All @@ -148,6 +149,15 @@ private void BuildTable()
#endregion

#region Properties
private string corners => roundedCorners ? "╭╮╰╯" : "┌┐└┘";
/// <summary>
/// Toggles the rounded corners of the table.
/// </summary>
public void SetRoundedCorners(bool value = true)
{
roundedCorners = value;
BuildTable();
}
/// <summary>
/// This property returns the number of lines in the table.
/// </summary>
Expand Down Expand Up @@ -243,7 +253,7 @@ public void UpdateLine(int index, List<T> line)
array[j] = displayArray[j];
Core.WritePositionedString(array[j], Placement.Center, false, startContentHeight + j);
if (j == index)
Core.WritePositionedString(j == displayArray.Length - 1 ? array[j].InsertString($"┤ {footerText} ├", Placement.Center, true)[1..^1] : array[j][1..^1], Placement.Center, true, startContentHeight + j);
Core.WritePositionedString(j == displayArray.Length - 1 ? array[j].InsertString($"┤ {footerText} ├", Placement.Center, true)[2..^2] : array[j][1..^1], Placement.Center, true, startContentHeight + j);
}
switch (Console.ReadKey(intercept: true).Key)
{
Expand Down
Loading

0 comments on commit 631a105

Please sign in to comment.