Skip to content

Commit

Permalink
Merge pull request #28 from MorganKryze/dev
Browse files Browse the repository at this point in the history
Added working Matrix class and docs
  • Loading branch information
MorganKryze authored Dec 11, 2023
2 parents 9a1ee91 + 84c6e05 commit db8003a
Show file tree
Hide file tree
Showing 8 changed files with 405 additions and 59 deletions.
45 changes: 44 additions & 1 deletion docs/documentation/specific.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,50 @@ students.UpdateLine(3, new () {"04", "Charles", "Computer Science", "55"});
You may also use the `SetRoundedCorners` method to set the rounded corners to true or false for the tables.

```csharp
Table.SetRoundedCorners(true);
students.SetRoundedCorners(true);
```

## Matrix display

First, you need to create a `Matrix` object giving the data just as in the example below.

```csharp
List<int?> firstRow = new() { 1, null, 2, 7, 9, 3 };
List<int?> secondRow = new() { 4, 5, 6, 8, null, 2 };
List<int?> thirdRow = new() { 7, 8, null, 3, 4, 5 };
List<int?> fourthRow = new() { null, 2, 3, 4, 5, 6 };
List<List<int?>> data = new() { firstRow, secondRow, thirdRow, fourthRow };
Matrix<int?> matrix = new(data);
```

The `WriteMatrix` is a special block that allows you to display the matrix. This is only visual, you can't select any element.

```csharp
matrix.WriteMatrix(Placement.Center);

Console.ReadKey();
```

![matrix](../images/matrix.png)

> [!NOTE]
> Once you created the matrix, you can add, remove or update the lines using the methods provided by the `Matrix` class (`AddLine`, `RemoveLine`, `UpdateLine`) but also the elements using the `RemoveElement` and `UpdateElement` methods.
Here is an example of a matrix of how to use them:

```csharp

matrix.AddLine(new () {2, 5, 7, 9, 3, 6});
matrix.RemoveLine(3);
matrix.UpdateLine(2, new () {3, 6, 8, 9, null, 2});
matrix.RemoveElement(new Position(2, 2));
matrix.UpdateElement(new Position(3,1), 7);
```

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

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

## Loading bar
Expand Down
5 changes: 5 additions & 0 deletions docs/documentation/started.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ ConsoleAppVisuals
│ └───FontYamlFile.cs
├───Core.cs
├───Extensions.cs
├───Matrix.cs
├───Table.cs
├───TextStyler.cs
└───Usings.cs
Expand Down Expand Up @@ -60,6 +61,10 @@ This class is used to style the text. It contains the methods to apply a specifi

This class is used to create a table. It may be useful to display data in a table on the screen.

### Matrix.cs

This class is used to create a matrix. It may be useful to display data in a matrix on the screen.

### Position.cs

This class is used to define any position defined by an X and Y coordinate. It may be used in cases like matrix selectors for example.
Expand Down
Binary file added docs/images/matrix.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
165 changes: 118 additions & 47 deletions example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,59 +9,35 @@ static void Main()
Console.Clear();
Console.CursorVisible = false;

Test();
Debugging();

Core.SetTitle("Example");
Core.WriteTitle();
Core.WriteHeader(true);
Core.WriteFooter(true);
Core.WriteHeader(false);
Core.WriteFooter(false);
Core.ClearContent();
Core.LoadingBar("[ Some example loading... ]");
Core.UpdateScreen();
Core.ClearContent();

Menu:

var index = Core.ScrollingMenuSelector("What do you want to do?", default, default, "Select a number", "Answer some prompt","Display trivia", "Display table", "Change color", "Quit the app");
switch (index.Item1){
var index = Core.ScrollingMenuSelector("What will be your next action?", default, default,
"Change Console color",
"Display paragraph",
"Display a styled text",
"Display a matrix",
"Answer some prompt",
"Select a number",
"Display table",
"Quit the app");
Core.ClearContent();
switch (index.Item1)
{
case Output.Select:
switch (index.Item2){
switch (index.Item2)
{
case 0:
Core.ClearContent();
Core.UpdateScreen();
var answerNumber = Core.ScrollingNumberSelector("Select a number", 10, 50, 25, 5);
float number = answerNumber.Item2;
Core.ClearContent();
break;
case 1:
Core.ClearContent();
Core.UpdateScreen();
var answerPrompt = Core.WritePrompt("Hey! What is your name?");
string name = answerPrompt.Item2;
Core.ClearContent();
break;
case 2:
Core.ClearContent();
Core.UpdateScreen();
Core.WriteParagraph(default, default, "C# is a general-purpose, multi-paradigm programming language encompassing strong typing,","lexically scoped, imperative, declarative, functional, generic, object-oriented (class-based),"," and component-oriented programming disciplines.", "", "Press [Enter] to continue...");
Console.ReadKey();
Core.ClearContent();
break;
case 3:
Core.ClearContent();
Core.UpdateScreen();
List<string> headers = new () {"id", "name", "major", "grades"};
List<string> student1 = new () {"01", "Theo", "Technology", "97"};
List<string> student2 = new () {"02", "Paul", "Mathematics", "86"};
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;
case 4:
Core.ClearContent();
Core.UpdateScreen();
var indexColor = Core.ScrollingMenuSelector("What color do you want to change?", default, default, "White", "Gray", "Red", "Green", "Blue", "Yellow", "Magenta", "Cyan");
switch(indexColor.Item2){
Expand Down Expand Up @@ -92,38 +68,133 @@ static void Main()
default:
break;
}
Core.ClearContent();
break;

case 1:
Core.UpdateScreen();

Core.WriteMultiplePositionedLines(default, default, default, "C# is a general-purpose, multi-paradigm programming language encompassing strong typing,","lexically scoped, imperative, declarative, functional, generic, object-oriented (class-based),"," and component-oriented programming disciplines.", "", "Press [Enter] to continue...");

Console.ReadKey();
Core.ClearContent();
break;
default:

case 2:
Core.UpdateScreen();

Core.WritePositionedStyledText(Core.StyleText("Hello World!"));

Console.ReadKey();
Core.ClearContent();

Core.WritePositionedStyledText(Core.StyleText("Welcome Aboard!"));

Console.ReadKey();
Core.ClearContent();
break;

case 3:
Core.UpdateScreen();
Core.WriteParagraph(true, default, "You have selected to quit the app. Press [Enter] to continue...");

List<int?> firstRow = new() { 1, null, 2, 7, 9, 3 };
List<int?> secondRow = new() { 4, 5, 6, 8, null, 2 };
List<int?> thirdRow = new() { 7, 8, null, 3, 4, 5 };
List<int?> fourthRow = new() { null, 2, 3, 4, 5, 6 };
List<List<int?>> data = new() { firstRow, secondRow, thirdRow, fourthRow };
Matrix<int?> matrix = new(data);
matrix.SetRoundedCorners(false);
matrix.WriteMatrix(Placement.Center);

Console.ReadKey();
Core.ClearContent();

matrix.Remove(new Position(0, 0));
matrix.Remove(new Position(3, 5));
matrix.WriteMatrix(Placement.Center);

Console.ReadKey();
Core.ClearContent();

matrix.UpdateElement(new Position(0, 0), 1);
matrix.UpdateElement(new Position(3, 5), 6);
matrix.WriteMatrix(Placement.Center);

Console.ReadKey();
Core.ClearContent();
break;

case 4:
Core.UpdateScreen();

var answerPrompt = Core.WritePrompt("Hey! What is your name?", "Theo");
string name = answerPrompt.Item2;

Core.ClearContent();
break;
case 5:
Core.UpdateScreen();

var answerNumber = Core.ScrollingNumberSelector("Select a number", 10, 50, 25, 5);
float number = answerNumber.Item2;

Core.ClearContent();
break;
case 6:
Core.UpdateScreen();

List<string> headers = new () {"id", "name", "major", "grades"};
List<string> student1 = new () {"01", "Theo", "Technology", "97"};
List<string> student2 = new () {"02", "Paul", "Mathematics", "86"};
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(false);
students.ScrollingTableSelector(true, false, "Add student");

students.UpdateLine(0, new () {"01", "Theo", "Biology", "100"});
students.RemoveLine(3);
students.ScrollingTableSelector(true, true);

Core.ClearContent();
break;

default:
Core.ClearContent();
Core.UpdateScreen();

Core.ExitProgram();
break;
}
break;

case Output.Exit:
Core.ClearContent();
Core.UpdateScreen();
Core.WriteParagraph(true, default, "You have selected to quit the app. Press [Enter] to continue...");

Core.WriteMultiplePositionedLines(default, true, default, "You have selected to quit the app. Press [Enter] to continue...");

Console.ReadKey();
Core.ExitProgram();
break;

case Output.Delete:
Core.ClearContent();
Core.UpdateScreen();
Core.WriteParagraph(true, default, "You have selected the backspace tile. Press [Enter] to continue...");

Core.WriteMultiplePositionedLines(default, true, default, "You have selected the backspace tile. Press [Enter] to continue...");

Console.ReadKey();
break;

default:
break;
}
goto Menu;
}
public static void Test()
public static void Debugging()
{
// Test code placeholder
// Debug code placeholder
}
}
}
21 changes: 21 additions & 0 deletions src/ConsoleAppVisuals/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ public static void WriteFooter(bool continuous = true, (string, string, string)?
/// <param name="negative">If true, the paragraph is printed in the negative colors.</param>
/// <param name="line">The height of the paragraph.</param>
/// <param name="text">The lines of the paragraph.</param>
[Obsolete("This method is deprecated. Use WriteParagraph with the placement attribute instead. This method will be removed in a future release.", true)]
public static void WriteParagraph(bool negative = false, int? line = null, params string[] text)
{
line ??= ContentHeight;
Expand All @@ -352,6 +353,26 @@ public static void WriteParagraph(bool negative = false, int? line = null, param
}
ApplyNegative(default);
}
/// <summary>
/// This method prints a paragraph in the console.
/// </summary>
/// <param name="placement">The placement of the paragraph.</param>
/// <param name="negative">If true, the paragraph is printed in the negative colors.</param>
/// <param name="line">The height of the paragraph.</param>
/// <param name="text">The lines of the paragraph.</param>
public static void WriteMultiplePositionedLines(Placement placement = Placement.Center , bool negative = false, int? line = null, params string[] text)
{
line ??= ContentHeight;
ApplyNegative(negative);
int maxLength = text.Length > 0 ? text.Max(s => s.Length) : 0;
foreach (string str in text)
{
WritePositionedString(str.ResizeString(maxLength, placement), placement, negative, line++);
if (line >= Console.WindowHeight - 1)
break;
}
ApplyNegative(default);
}
/// <summary>
/// This method prints a message in the console and gets a string written by the user.
/// </summary>
Expand Down
Loading

0 comments on commit db8003a

Please sign in to comment.