Compare commits

5 Commits
v1 ... v3
Author SHA1 Message Date
mahdium ee1650a885 Minor improvements to the TUI 2025-12-31 12:28:43 +03:30
mahdium 6462fa0409 Improved TUI for a better UX 2025-12-31 12:06:37 +03:30
mahdium 9744b2a788 Add a command to remove a file or folder only from the list 2025-02-26 15:23:09 +03:30
mahdium c4e8945371 Add duplicate path check 2025-02-26 15:08:48 +03:30
mahdium 97e564d352 Update README 2025-02-04 17:32:51 +03:30
11 changed files with 382 additions and 115 deletions

No files matched your search

+27 -17
View File
@@ -1,3 +1,4 @@
using System.Diagnostics.Contracts;
using TBDel.Models; using TBDel.Models;
using TBDel.Services; using TBDel.Services;
@@ -7,9 +8,6 @@ namespace TBDel.Commands
{ {
public static async Task AddEntry(string[] args) public static async Task AddEntry(string[] args)
{ {
// TODO: Add duplicate path check
// TODO: Add support for multiple paths
if (args.Length > 1) if (args.Length > 1)
{ {
string workingDirectory = Directory.GetCurrentDirectory(); string workingDirectory = Directory.GetCurrentDirectory();
@@ -18,42 +16,54 @@ namespace TBDel.Commands
if (File.Exists(absolutePath)) if (File.Exists(absolutePath))
{ {
Console.WriteLine($"Adding: {absolutePath}"); TuiHelper.DisplayInfo($"Adding file: {absolutePath}");
if (await dbService.EtryExists(absolutePath))
{
TuiHelper.DisplayWarning("File already exists in the list - No actions performed.");
return;
}
var entry = new FileEntry { Id = GenerateUniqueId(dbService), Path = absolutePath, DateAdded = DateTime.Now }; var entry = new FileEntry { Id = GenerateUniqueId(dbService), Path = absolutePath, DateAdded = DateTime.Now };
if (await dbService.AddFileEntryAsync(entry)) if (await dbService.AddFileEntryAsync(entry))
{ {
Console.ForegroundColor = ConsoleColor.Green; TuiHelper.DisplaySuccess("File added successfully.");
Console.WriteLine("File added successfully.");
Console.ResetColor();
return; return;
} }
else else
{ {
Console.ForegroundColor = ConsoleColor.Red; TuiHelper.DisplayError("Failed to add file.");
Console.WriteLine("Failed to add file.");
Console.ResetColor();
return; return;
} }
} }
else if (Directory.Exists(absolutePath)) else if (Directory.Exists(absolutePath))
{ {
Console.WriteLine($"Adding: {absolutePath}"); TuiHelper.DisplayInfo($"Adding directory: {absolutePath}");
if (await dbService.EtryExists(absolutePath))
{
TuiHelper.DisplayWarning("Folder already exists in the list - No actions performed.");
return;
}
var entry = new FolderEntry() { Id = GenerateUniqueId(dbService), Path = absolutePath, DateAdded = DateTime.Now }; var entry = new FolderEntry() { Id = GenerateUniqueId(dbService), Path = absolutePath, DateAdded = DateTime.Now };
if (await dbService.AddFolderEntryAsync(entry)) if (await dbService.AddFolderEntryAsync(entry))
{ {
Console.ForegroundColor = ConsoleColor.Green; TuiHelper.DisplaySuccess("Directory added successfully.");
Console.WriteLine("Directory added successfully.");
Console.ResetColor();
return; return;
} }
else else
{ {
Console.ForegroundColor = ConsoleColor.Red; TuiHelper.DisplayError("Failed to add directory.");
Console.WriteLine("Failed to add directory.");
Console.ResetColor();
return; return;
} }
} }
else
{
TuiHelper.DisplayError($"Path does not exist: {absolutePath}");
return;
}
}
else
{
TuiHelper.DisplayError("No path provided. Please specify a file or folder to add.");
return;
} }
} }
+44 -33
View File
@@ -12,81 +12,92 @@ public class DeleteAllCommand
if (allFiles.Count == 0 && allFolders.Count == 0) if (allFiles.Count == 0 && allFolders.Count == 0)
{ {
Console.WriteLine("No files or folders found."); TuiHelper.DisplayInfo("No files or folders found.");
return; return;
} }
Console.ForegroundColor = ConsoleColor.Yellow; TuiHelper.DisplayHeader("TBDel - Delete All Entries");
Console.Write(
$"Are you sure you want to permanently delete {allFiles.Count} file(s) and {allFolders.Count} folder(s)? (y/N) "); // Display summary before confirmation
Console.ResetColor(); TuiHelper.DisplaySummary("Deletion Summary",
var input = Console.ReadLine(); ("Files to delete", allFiles.Count.ToString()),
if (input != "y") ("Folders to delete", allFolders.Count.ToString()),
("Total items", (allFiles.Count + allFolders.Count).ToString())
);
if (!TuiHelper.GetConfirmation("Permanently delete ALL entries?"))
{ {
Console.ForegroundColor = ConsoleColor.Red; TuiHelper.DisplayInfo("Operation cancelled.");
Console.WriteLine("Operation cancelled.");
Console.ResetColor();
return; return;
} }
int deletedFiles = 0;
int deletedFolders = 0;
int failedDeletions = 0;
foreach (var file in allFiles) foreach (var file in allFiles)
{ {
if (!File.Exists(file.Path)) if (!File.Exists(file.Path))
{ {
Console.ForegroundColor = ConsoleColor.Yellow; TuiHelper.DisplayWarning($"File {file.Path} does not exist, removing from list.");
Console.WriteLine($"File {file.Path} does not exist, removing from list.");
Console.ResetColor();
await dbService.RemoveFileEntryAsync(file.Id); await dbService.RemoveFileEntryAsync(file.Id);
continue; continue;
} }
Console.WriteLine($"Deleting file: {file.Path}"); TuiHelper.DisplayInfo($"Deleting file: {file.Path}");
try try
{ {
File.Delete(file.Path); File.Delete(file.Path);
await dbService.RemoveFileEntryAsync(file.Id);
deletedFiles++;
} }
catch (Exception e) catch (Exception e)
{ {
Console.ForegroundColor = ConsoleColor.Red; TuiHelper.DisplayError("Something went wrong while deleting the file.");
Console.WriteLine("Something went wrong while deleting the file.");
Console.WriteLine(e.Message); Console.WriteLine(e.Message);
Console.ResetColor(); failedDeletions++;
return;
} }
await dbService.RemoveFileEntryAsync(file.Id);
} }
foreach (var folder in allFolders) foreach (var folder in allFolders)
{ {
if (!Directory.Exists(folder.Path)) if (!Directory.Exists(folder.Path))
{ {
Console.ForegroundColor = ConsoleColor.Yellow; TuiHelper.DisplayWarning($"Directory {folder.Path} does not exist, removing from list.");
Console.WriteLine($"Directory {folder.Path} does not exist, removing from list.");
Console.ResetColor();
await dbService.RemoveFolderEntryAsync(folder.Id); await dbService.RemoveFolderEntryAsync(folder.Id);
continue; continue;
} }
Console.WriteLine($"Deleting directory: {folder.Path}"); TuiHelper.DisplayInfo($"Deleting directory: {folder.Path}");
try try
{ {
Directory.Delete(folder.Path, true); Directory.Delete(folder.Path, true);
await dbService.RemoveFolderEntryAsync(folder.Id);
deletedFolders++;
} }
catch (Exception e) catch (Exception e)
{ {
Console.ForegroundColor = ConsoleColor.Red; TuiHelper.DisplayError("Something went wrong while deleting the directory.");
Console.WriteLine("Something went wrong while deleting the directory.");
Console.WriteLine(e.Message); Console.WriteLine(e.Message);
Console.ResetColor(); failedDeletions++;
return;
} }
await dbService.RemoveFolderEntryAsync(folder.Id);
} }
Console.ForegroundColor = ConsoleColor.Green; // Display final results
Console.WriteLine("All files and folders deleted successfully."); TuiHelper.DisplayHeader("Deletion Results");
Console.ResetColor(); TuiHelper.DisplaySummary("Summary",
("Files deleted", deletedFiles.ToString()),
("Folders deleted", deletedFolders.ToString()),
("Failed deletions", failedDeletions.ToString())
);
if (failedDeletions == 0)
{
TuiHelper.DisplaySuccess("All files and folders deleted successfully.");
}
else
{
TuiHelper.DisplayWarning("Some items could not be deleted.");
}
} }
} }
+30 -32
View File
@@ -8,21 +8,26 @@ namespace TBDel.Commands
public static async Task DeleteEntry(string[] args) public static async Task DeleteEntry(string[] args)
{ {
var dbService = new DbService(); var dbService = new DbService();
if (args.Length > 1 && uint.TryParse(args[1], out uint id)) if (args.Length > 1 && uint.TryParse(args[1], out uint id))
{ {
var filePath = await dbService.GetEntryPath(id); var filePath = await dbService.GetEntryPath(id);
Console.ForegroundColor = ConsoleColor.Yellow; if (string.IsNullOrEmpty(filePath))
Console.Write($"Are you sure you want to permanently delete entry with ID {id}? (y/N) ");
Console.ResetColor();
var input = Console.ReadLine();
if (input != "y")
{ {
Console.ForegroundColor = ConsoleColor.Red; TuiHelper.DisplayError($"No entry found with ID {id}.");
Console.WriteLine("Operation cancelled."); return;
Console.ResetColor(); }
// Display entry details before confirmation
TuiHelper.DisplayHeader("TBDel - Delete Entry");
Console.WriteLine($"Entry ID: {id}");
Console.WriteLine($"Path: {filePath}");
Console.WriteLine();
if (!TuiHelper.GetConfirmation($"Permanently delete this entry?"))
{
TuiHelper.DisplayInfo("Operation cancelled.");
return; return;
} }
@@ -31,15 +36,11 @@ namespace TBDel.Commands
File.Delete(filePath); File.Delete(filePath);
if (await dbService.RemoveFileEntryAsync(id)) if (await dbService.RemoveFileEntryAsync(id))
{ {
Console.ForegroundColor = ConsoleColor.Green; TuiHelper.DisplaySuccess("File deleted successfully.");
Console.WriteLine("File deleted successfully.");
Console.ResetColor();
} }
else else
{ {
Console.ForegroundColor = ConsoleColor.Red; TuiHelper.DisplayError("Something went wrong while deleting the file.");
Console.WriteLine("Something went wrong while deleting the file.");
Console.ResetColor();
} }
} }
else if (Directory.Exists(filePath)) else if (Directory.Exists(filePath))
@@ -50,34 +51,31 @@ namespace TBDel.Commands
} }
catch (Exception e) catch (Exception e)
{ {
Console.ForegroundColor = ConsoleColor.Red;
if (e.Message.Contains("Directory not empty")) if (e.Message.Contains("Directory not empty"))
{ {
Console.WriteLine("Directory is not empty. It must be empty before it can be deleted or deleted manually."); TuiHelper.DisplayError("Directory is not empty. It must be empty before it can be deleted or deleted manually.");
}
else
{
TuiHelper.DisplayError("Something went wrong while deleting the directory.");
Console.WriteLine(e.Message);
} }
Console.WriteLine("Something went wrong while deleting the directory.");
Console.ResetColor();
Console.WriteLine(e.Message);
return; return;
} }
if (await dbService.RemoveFolderEntryAsync(id)) if (await dbService.RemoveFolderEntryAsync(id))
{ {
Console.ForegroundColor = ConsoleColor.Green; TuiHelper.DisplaySuccess("Directory deleted successfully.");
Console.WriteLine("Directory deleted successfully.");
Console.ResetColor();
} }
else else
{ {
Console.ForegroundColor = ConsoleColor.Red; TuiHelper.DisplayError("Something went wrong while deleting the directory.");
Console.WriteLine("Something went wrong while deleting the directory.");
Console.ResetColor();
} }
} }
}
else
{
TuiHelper.DisplayError("Invalid ID provided. Please provide a valid numeric ID.");
} }
} }
} }
+42 -9
View File
@@ -1,4 +1,6 @@
using TBDel.Services;
namespace TBDel.Commands; namespace TBDel.Commands;
public static class HelpCommand public static class HelpCommand
@@ -13,16 +15,47 @@ public static class HelpCommand
{ {
if (showOnWrongCommand) if (showOnWrongCommand)
{ {
Console.ForegroundColor = ConsoleColor.Red; TuiHelper.DisplayError("Invalid command. Use 'tbdel help' for help.");
Console.Error.WriteLine("Invalid command. Use 'tbdel help' for help.");
Console.ResetColor();
} }
TuiHelper.DisplayHeader("TBDel - Help");
Console.WriteLine("Usage: tbdel <command> [arguments]"); Console.WriteLine("Usage: tbdel <command> [arguments]");
Console.WriteLine("Available commands:"); Console.WriteLine();
Console.WriteLine(" add <path to file or folder> Add a file or folder to the list");
Console.WriteLine(" delete <file or folder ID> Deletes a file or folder"); TuiHelper.DisplayInfo("Available commands:");
Console.WriteLine(" deleteall Deletes all items in the list"); Console.WriteLine();
Console.WriteLine(" list Lists all items in the list");
Console.WriteLine(" help Shows this help message"); Console.WriteLine(" add <path to file or folder> │ Add a file or folder to the list");
Console.WriteLine(" │ Example: tbdel add ./myfile.txt");
Console.WriteLine();
Console.WriteLine(" delete <file or folder ID> │ Delete a file or folder permanently");
Console.WriteLine(" │ Example: tbdel delete 12345");
Console.WriteLine();
Console.WriteLine(" deleteall │ Delete all items in the list");
Console.WriteLine(" │ Example: tbdel deleteall");
Console.WriteLine();
Console.WriteLine(" rmflist <entry ID> │ Remove an entry ONLY from the list");
Console.WriteLine(" │ Example: tbdel rmflist 12345");
Console.WriteLine();
Console.WriteLine(" list │ List all items in the list");
Console.WriteLine(" │ Example: tbdel list");
Console.WriteLine();
Console.WriteLine(" list files │ List only files in the list");
Console.WriteLine(" │ Example: tbdel list files");
Console.WriteLine();
Console.WriteLine(" list folders │ List only folders in the list");
Console.WriteLine(" │ Example: tbdel list folders");
Console.WriteLine();
Console.WriteLine(" help │ Show this help message");
Console.WriteLine(" │ Example: tbdel help");
Console.WriteLine();
} }
} }
+20 -19
View File
@@ -9,26 +9,27 @@ namespace TBDel.Commands
{ {
if (args.Length > 2) if (args.Length > 2)
{ {
Console.WriteLine("Too many arguments."); TuiHelper.DisplayError("Too many arguments.");
return; return;
} }
if (args.Length == 1) if (args.Length == 1)
{ {
Console.WriteLine("Listing both files and folders."); TuiHelper.DisplayHeader("TBDel - List All Items");
TuiHelper.DisplayInfo("Listing both files and folders.");
await ListFiles(); await ListFiles();
for (int i = 0; i < 110; i++) TuiHelper.DisplaySectionSeparator();
{
Console.Write("-");
}
Console.Write("\n");
await ListFolders(); await ListFolders();
} }
else if (args[1] == "files") else if (args[1] == "files")
{ {
TuiHelper.DisplayHeader("TBDel - List Files");
await ListFiles(); await ListFiles();
} }
else if (args[1] == "folders") else if (args[1] == "folders")
{ {
TuiHelper.DisplayHeader("TBDel - List Folders");
await ListFolders(); await ListFolders();
} }
} }
@@ -40,17 +41,17 @@ namespace TBDel.Commands
if (filesList.Count == 0) if (filesList.Count == 0)
{ {
Console.WriteLine("No files found."); TuiHelper.DisplayInfo("No files found.");
return; return;
} }
Console.ForegroundColor = ConsoleColor.Green; TuiHelper.DisplayInfo($"Found {filesList.Count} file(s):");
Console.WriteLine("Found {0} file(s):\n", filesList.Count); Console.WriteLine();
Console.WriteLine("{0,-10} {1,-90} {2,10}\n", "ID", "Path", "Date added"); TuiHelper.DisplayTableHeader("ID", "Path", "Date Added", 10, 60, 20);
Console.ResetColor();
foreach (var file in filesList) foreach (var file in filesList)
{ {
Console.WriteLine("{0,-10} {1,-90} {2,10}", file.Id, file.Path, file.DateAdded); TuiHelper.DisplayTableRow(file.Id, file.Path, file.DateAdded, 10, 60, 20);
} }
} }
@@ -61,17 +62,17 @@ namespace TBDel.Commands
if (foldersList.Count == 0) if (foldersList.Count == 0)
{ {
Console.WriteLine("No folders found."); TuiHelper.DisplayInfo("No folders found.");
return; return;
} }
Console.ForegroundColor = ConsoleColor.Green; TuiHelper.DisplayInfo($"Found {foldersList.Count} folder(s):");
Console.WriteLine("Found {0} folder(s):\n", foldersList.Count); Console.WriteLine();
Console.WriteLine("{0,-10} {1,-90} {2,10}\n", "ID", "Path", "Date added"); TuiHelper.DisplayTableHeader("ID", "Path", "Date Added", 10, 60, 20);
Console.ResetColor();
foreach (var folder in foldersList) foreach (var folder in foldersList)
{ {
Console.WriteLine("{0,-10} {1,-90} {2,10}", folder.Id, folder.Path, folder.DateAdded); TuiHelper.DisplayTableRow(folder.Id, folder.Path, folder.DateAdded, 10, 60, 20);
} }
} }
} }
+45
View File
@@ -0,0 +1,45 @@
using TBDel.Services;
namespace TBDel.Commands;
public class RemoveFromListCommand
{
public static async Task DeleteEntryFromList(String[] args)
{
var dbService = new DbService();
if (args.Length > 1 && uint.TryParse(args[1], out uint id))
{
var filePath = await dbService.GetEntryPath(id);
if (string.IsNullOrEmpty(filePath))
{
TuiHelper.DisplayError($"No entry found with ID {id}.");
return;
}
TuiHelper.DisplayHeader("TBDel - Remove from List");
Console.WriteLine($"Entry ID: {id}");
Console.WriteLine($"Path: {filePath}");
Console.WriteLine();
if (!TuiHelper.GetConfirmation("Remove this entry ONLY from the list?"))
{
TuiHelper.DisplayInfo("Operation cancelled.");
return;
}
if (await dbService.RemoveFileEntryAsync(id) || await dbService.RemoveFolderEntryAsync(id))
{
TuiHelper.DisplaySuccess("Entry removed from the list.");
}
else
{
TuiHelper.DisplayError("Something went wrong while removing the entry from list.");
}
}
else
{
TuiHelper.DisplayError("Invalid ID provided. Please provide a valid numeric ID.");
}
}
}
+3 -2
View File
@@ -4,8 +4,6 @@ namespace TBDel
{ {
internal class Program internal class Program
{ {
// TODO: Add a command to show the Db path
// TODO: Add a command to remove a file or folder only from the list
static async Task Main(string[] args) static async Task Main(string[] args)
{ {
// Show the help message if no arguments are provided // Show the help message if no arguments are provided
@@ -28,6 +26,9 @@ namespace TBDel
case "deleteall": case "deleteall":
await DeleteAllCommand.DeleteAll(); await DeleteAllCommand.DeleteAll();
break; break;
case "rmflist":
await RemoveFromListCommand.DeleteEntryFromList(args);
break;
case "list": case "list":
await ListCommand.List(args); await ListCommand.List(args);
break; break;
+11 -2
View File
@@ -3,7 +3,10 @@
## Installation ## Installation
Soon... - Install on Arch Linux (aur)
```shell
paru -S tbdel
```
## Usage ## Usage
@@ -13,6 +16,7 @@ Usage: tbdel <command> [arguments]
Available commands: Available commands:
add <path to file or folder> Add a file or folder to the list add <path to file or folder> Add a file or folder to the list
delete <file or folder ID> Deletes a file or folder delete <file or folder ID> Deletes a file or folder
rmflist Remove an entry ONLY from the list
deleteall Deletes all items in the list deleteall Deletes all items in the list
list Lists all items in the list list Lists all items in the list
help Shows this help message help Shows this help message
@@ -33,6 +37,11 @@ help Shows this help message
```shell ```shell
tbdel list tbdel list
``` ```
* Remove an entry ONLY from the list: **(Assuming '12345' is the ID of the entry you want to remove from the list)**
```shell
tbdel rmflist 12345
```
* Delete an entry (using its ID): **(Assuming '12345' is the ID of the entry you want to delete)** * Delete an entry (using its ID): **(Assuming '12345' is the ID of the entry you want to delete)**
```shell ```shell
@@ -55,4 +64,4 @@ help Shows this help message
## License ## License
This project is licensed under the GNU Affero General Public License v3.0 - see the [LICENSE](LICENSE) file for details. This project is licensed under the GNU Affero General Public License v3.0 - see the [LICENSE](LICENSE) file for details.
+10
View File
@@ -106,6 +106,16 @@ namespace TBDel.Services
return String.Empty; return String.Empty;
} }
public async Task<bool> EtryExists(String path)
{
if (_fileCollection.Find(f => f.Path == path) is not null || _folderCollection.Find(f => f.Path == path) is not null)
{
return await Task.FromResult(true);
}
return await Task.FromResult(false);
}
} }
public class DatabaseContent public class DatabaseContent
+149
View File
@@ -0,0 +1,149 @@
using System;
using TBDel.Models;
namespace TBDel.Services
{
public static class TuiHelper
{
// Color constants for consistent styling
public static readonly ConsoleColor HeaderColor = ConsoleColor.Cyan;
public static readonly ConsoleColor SuccessColor = ConsoleColor.Green;
public static readonly ConsoleColor WarningColor = ConsoleColor.Yellow;
public static readonly ConsoleColor ErrorColor = ConsoleColor.Red;
public static readonly ConsoleColor InfoColor = ConsoleColor.White;
public static readonly ConsoleColor BorderColor = ConsoleColor.DarkGray;
// Display a styled header
public static void DisplayHeader(string title)
{
var borderLength = Math.Max(title.Length + 4, 30); // Ensure minimum length
var border = new string('═', borderLength);
Console.ForegroundColor = HeaderColor;
Console.WriteLine($"\n╔{border}╗");
// Center the title within the border
var padding = (borderLength - title.Length) / 2;
var leftPadding = padding;
var rightPadding = borderLength - title.Length - leftPadding;
var paddedTitle = new string(' ', leftPadding) + title + new string(' ', rightPadding);
Console.WriteLine($"║{paddedTitle}║");
Console.WriteLine($"╚{border}╝");
Console.ResetColor();
}
// Display a styled section separator
public static void DisplaySectionSeparator(int length = 80)
{
Console.ForegroundColor = BorderColor;
Console.WriteLine(new string('─', length));
Console.ResetColor();
}
// Display a styled table header
public static void DisplayTableHeader(string idLabel, string pathLabel, string dateLabel, int idWidth = 10, int pathWidth = 70, int dateWidth = 20)
{
Console.ForegroundColor = HeaderColor;
Console.WriteLine("{0,-" + idWidth + "} │ {1,-" + pathWidth + "} │ {2,-" + dateWidth + "}", idLabel, pathLabel, dateLabel);
DisplayTableSeparator(idWidth, pathWidth, dateWidth);
Console.ResetColor();
}
// Display a table separator line
public static void DisplayTableSeparator(int idWidth = 10, int pathWidth = 60, int dateWidth = 20)
{
Console.ForegroundColor = BorderColor;
// Calculate total width: idWidth + " │ " + pathWidth + " │ " + dateWidth
var totalWidth = idWidth + 3 + pathWidth + 3 + dateWidth; // 3 chars for " │ " separator
Console.WriteLine(new string('─', totalWidth));
Console.ResetColor();
}
// Display a table row
public static void DisplayTableRow(uint id, string path, DateTime dateAdded, int idWidth = 10, int pathWidth = 70, int dateWidth = 20)
{
var formattedDate = dateAdded.ToString("yyyy-MM-dd HH:mm");
var truncatedPath = path.Length > pathWidth ? path.Substring(0, pathWidth - 3) + "..." : path;
Console.WriteLine("{0,-" + idWidth + "} │ {1,-" + pathWidth + "} │ {2,-" + dateWidth + "}", id, truncatedPath, formattedDate);
}
// Display a confirmation prompt with styled formatting
public static bool GetConfirmation(string message)
{
Console.ForegroundColor = WarningColor;
Console.Write($"⚠ {message} (y/N): ");
Console.ResetColor();
var input = Console.ReadLine();
return input?.ToLowerInvariant() == "y";
}
// Display a success message
public static void DisplaySuccess(string message)
{
Console.ForegroundColor = SuccessColor;
Console.WriteLine($"✓ {message}");
Console.ResetColor();
}
// Display an error message
public static void DisplayError(string message)
{
Console.ForegroundColor = ErrorColor;
Console.WriteLine($"✗ {message}");
Console.ResetColor();
}
// Display an info message
public static void DisplayInfo(string message)
{
Console.ForegroundColor = InfoColor;
Console.WriteLine($"ℹ {message}");
Console.ResetColor();
}
// Display a warning message
public static void DisplayWarning(string message)
{
Console.ForegroundColor = WarningColor;
Console.WriteLine($"⚠ {message}");
Console.ResetColor();
}
// Display a styled summary box
public static void DisplaySummary(string title, params (string label, string value)[] items)
{
// Calculate the max width needed for the content
int contentWidth = Math.Max(title.Length + 2, 28); // +2 for the ─ ─ spacing around title, minimum 30 total
foreach (var (label, value) in items)
{
int itemLength = (label + ": " + value).Length;
if (itemLength > contentWidth) contentWidth = itemLength;
}
Console.ForegroundColor = HeaderColor;
var topBorder = $"┌─ {title} ─{'─'.Repeat(Math.Max(0, contentWidth - title.Length - 2))}┐";
Console.WriteLine($"\n{topBorder}");
Console.ResetColor();
foreach (var (label, value) in items)
{
var content = $"│ {label}: {value}";
var padding = contentWidth - (label.Length + value.Length + 2); // 2 for ": "
var paddedContent = content + new string(' ', padding) + "│";
Console.WriteLine(paddedContent);
}
Console.ForegroundColor = HeaderColor;
var bottomBorder = $"└{'─'.Repeat(contentWidth + 2)}┘"; // +2 for the │ │ borders
Console.WriteLine(bottomBorder);
Console.ResetColor();
}
}
// Extension method to repeat a character
public static class StringExtensions
{
public static string Repeat(this char c, int count)
{
return new string(c, count);
}
}
}
+1 -1
View File
@@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework> <TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<PublishAot>true</PublishAot> <PublishAot>true</PublishAot>