diff --git a/tool/Cascadium-Utility.csproj b/tool/Cascadium-Utility.csproj index 433475e..a4f1a29 100644 --- a/tool/Cascadium-Utility.csproj +++ b/tool/Cascadium-Utility.csproj @@ -8,13 +8,14 @@ cascadium true - 0.1.2.4 - 0.1.2.4 + 0.4 + 0.4 cascadiumtool + diff --git a/tool/CommandLineParser.cs b/tool/CommandLineParser.cs index 6e5f2d7..43b942f 100644 --- a/tool/CommandLineParser.cs +++ b/tool/CommandLineParser.cs @@ -1,4 +1,5 @@ -using System; +using Spectre.Console; +using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; @@ -194,11 +195,11 @@ public static void PrintHelp string part = parts[i]; if (i == 0) { - Console.WriteLine("{0," + startTrailingSpace + "}{1,-" + (biggestOptionLength + optionGutter) + "}{2}", "", opKp.opText, part); + AnsiConsole.MarkupLine("{0," + startTrailingSpace + "}[grey63]{1,-" + (biggestOptionLength + optionGutter) + "}[/][silver]{2}[/]", "", opKp.opText, part); } else { - Console.WriteLine("{0}{1}", new String(' ', biggestOptionLength + optionGutter + startTrailingSpace), part); + AnsiConsole.MarkupLine("{0}[silver]{1}[/]", new String(' ', biggestOptionLength + optionGutter + startTrailingSpace), part); } } diff --git a/tool/Compiler.cs b/tool/Compiler.cs index 4d4919e..776323b 100644 --- a/tool/Compiler.cs +++ b/tool/Compiler.cs @@ -1,5 +1,6 @@ using Cascadium; using Microsoft.VisualBasic; +using Spectre.Console; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -129,11 +130,13 @@ await Parallel.ForEachAsync(inputFiles, } catch (CascadiumException cex) { - Console.WriteLine($"error at file {file.Substring(smallInputLength + 1)}, line {cex.Line}, col. {cex.Column}:"); - Console.WriteLine(); - Console.WriteLine($"\t{cex.LineText}"); - Console.WriteLine($"\t{new string(' ', cex.Column - 1)}^"); - Console.WriteLine($"\t{cex.Message}"); + string linePadText = cex.Line + "."; + AnsiConsole.MarkupLine($"[grey]cascadium[/] [silver]{DateTime.Now:T}[/] [indianred_1]error[/] at file [white]{file.Substring(smallInputLength + 1)}[/], line [deepskyblue3_1]{cex.Line}[/], col. [deepskyblue3_1]{cex.Column}[/]:"); + AnsiConsole.WriteLine(); + AnsiConsole.MarkupLine($"\t[deepskyblue3_1]{linePadText}[/] [silver]{cex.LineText}[/]"); + AnsiConsole.MarkupLine($"\t[lightpink4]{new string(' ', cex.Column + linePadText.Length)}^[/]"); + AnsiConsole.MarkupLine($"\t[mistyrose3]{cex.Message}[/]"); + AnsiConsole.WriteLine(); errorCanceller.Cancel(); } @@ -145,17 +148,18 @@ await Parallel.ForEachAsync(inputFiles, ; } + string css = string.Join(options.Pretty ? "\n" : "", resultCss); if (outputFile != null) - { - string css = string.Join(options.Pretty ? "\n" : "", resultCss); + { File.WriteAllText(outputFile, css); compiledLength = new FileInfo(outputFile).Length; - Log.Info($"{inputFiles.Count} file(s) -> {Path.GetFileName(args.OutputFile)} ({PathUtils.FileSize(compiledLength)}) in {sw.ElapsedMilliseconds:N0}ms"); + if (!Program.IsWatch) + Log.Info($"{inputFiles.Count} file(s) -> {Path.GetFileName(args.OutputFile)} ({PathUtils.FileSize(compiledLength)}) in {sw.ElapsedMilliseconds:N0}ms"); } else { - Console.Write(resultCss.ToString()); + Console.Write(css); } } } diff --git a/tool/Log.cs b/tool/Log.cs index c515983..4a2c486 100644 --- a/tool/Log.cs +++ b/tool/Log.cs @@ -1,4 +1,5 @@ -using System; +using Spectre.Console; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -14,6 +15,7 @@ public static int ErrorKill(string message) Write("error", message); return 1; } + public static int Info(string message, bool force = false) { if (!force && !LoggingEnabled) return 0; @@ -23,6 +25,17 @@ public static int Info(string message, bool force = false) private static void Write(string level, string message) { - Console.WriteLine("{0,-17} {1}", "cascadium [" + level + "]", message); + if (level == "error") + { + AnsiConsole.MarkupLine($"[grey]cascadium[/] [silver]{DateTime.Now:T}[/] [indianred_1]error[/] [white]{message}[/]"); + } + else if (level == "info") + { + AnsiConsole.MarkupLine($"[grey]cascadium[/] [silver]{DateTime.Now:T}[/] [darkcyan]info[/] [white]{message}[/]"); + } + else if (level == "warn") + { + AnsiConsole.MarkupLine($"[grey]cascadium[/] [silver]{DateTime.Now:T}[/] [darkgoldenrod]info[/] [white]{message}[/]"); + } } } diff --git a/tool/Program.cs b/tool/Program.cs index b89a14c..fe3f849 100644 --- a/tool/Program.cs +++ b/tool/Program.cs @@ -8,11 +8,12 @@ namespace cascadiumtool; internal class Program { - public const string VersionLabel = "v.0.3"; + public const string VersionLabel = "v.0.4"; public static string CurrentDirectory { get; set; } = Directory.GetCurrentDirectory(); public static bool HasRootConfiguration { get; private set; } public static JsonCssCompilerOptions? CompilerOptions { get; set; } public static Dictionary CompilerCache { get; set; } = new Dictionary(StringComparer.OrdinalIgnoreCase); + public static bool IsWatch { get; set; } = false; [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(CommandLineArguments))] static async Task Main(string[] args) @@ -43,6 +44,7 @@ public static async Task RunParsed(CommandLineArguments args) if (args.Watch) { + IsWatch = true; return await Watcher.Watch(args); } else diff --git a/tool/Watcher.cs b/tool/Watcher.cs index 8be61ee..04ae282 100644 --- a/tool/Watcher.cs +++ b/tool/Watcher.cs @@ -14,7 +14,7 @@ internal static class Watcher private static FileSystemWatcher fsWatcher = new FileSystemWatcher(); private static CommandLineArguments watchArgs = null!; private static string[] watchingDirectories = Array.Empty(); - private static bool IsCompilingFile = false; + private static bool IsRunningCompilation = false; public static async Task Watch(CommandLineArguments args) { @@ -54,7 +54,12 @@ public static async Task Watch(CommandLineArguments args) fsWatcher.Path = smallestPath!; fsWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.CreationTime | NotifyFilters.FileName; + fsWatcher.Changed += FsWatcher_Changed; + fsWatcher.Renamed += FsWatcher_Changed; + fsWatcher.Deleted += FsWatcher_Changed; + fsWatcher.Created += FsWatcher_Changed; + fsWatcher.Filter = "*.*"; fsWatcher.IncludeSubdirectories = true; fsWatcher.EnableRaisingEvents = true; @@ -69,12 +74,12 @@ public static async Task Watch(CommandLineArguments args) private static async void FsWatcher_Changed(Object sender, FileSystemEventArgs e) { - if (IsCompilingFile) + if (IsRunningCompilation) { return; } - IsCompilingFile = true; + IsRunningCompilation = true; string outFile = PathUtils.ResolvePath(watchArgs.OutputFile); if (outFile == e.FullPath) @@ -99,9 +104,19 @@ private static async void FsWatcher_Changed(Object sender, FileSystemEventArgs e Program.CompilerCache.Remove(file); + if (e.ChangeType == WatcherChangeTypes.Renamed + || e.ChangeType == WatcherChangeTypes.Deleted + || e.ChangeType == WatcherChangeTypes.Created) + { + Log.Info($"Directory structure modified. Clearing cache."); + Program.CompilerCache.Clear(); + } + try { - Thread.Sleep(300); // prevent the below error giving time to the time to write + await Task.Delay(100); // prevent the below error giving time to the time to write + Log.Info($"Detected {e.ChangeType} on {Path.GetFileName(file)}, building..."); + await Compiler.RunCompiler(watchArgs); ; } @@ -112,8 +127,8 @@ private static async void FsWatcher_Changed(Object sender, FileSystemEventArgs e } finally { - IsCompilingFile = false; - Thread.Sleep(150); + await Task.Delay(400); + IsRunningCompilation = false; } } } diff --git a/tool/etc/build.bat b/tool/etc/build.bat index da45f34..967dbd2 100644 --- a/tool/etc/build.bat +++ b/tool/etc/build.bat @@ -12,4 +12,4 @@ dotnet publish "%~dp0/../Cascadium-Utility.csproj" --nologo ^ -p:PublishReadyToRun=true ^ -p:PublishTrimmed=true ^ -p:PublishSingleFile=true ^ - -o "%~dp0bin/Build/cascadium-v0.3-%NAME%/" \ No newline at end of file + -o "%~dp0bin/Build/cascadium-v0.4-%NAME%/" \ No newline at end of file