diff --git a/src/Microsoft.Tye.Hosting/Ansi2Html/Constants.cs b/src/Microsoft.Tye.Hosting/Ansi2Html/Constants.cs new file mode 100644 index 000000000..10a7243f1 --- /dev/null +++ b/src/Microsoft.Tye.Hosting/Ansi2Html/Constants.cs @@ -0,0 +1,55 @@ +using System.Collections.Generic; + +namespace Microsoft.Tye.Hosting.Ansi2Html +{ + public static class Constants + { + public const string Red = "#800000"; + public const string Black = "#000000"; + public const string Green = "#008000"; + public const string Yellow = "#808000"; + public const string Blue = "#000080"; + public const string Purple = "#800080"; + public const string Cyan = "#008080"; + public const string LightGray = "#c0c0c0"; + public const string DarkGray = "#808080"; + public const string BrightRed = "#ff0000"; + public const string BrightGreen = "#00ff00"; + public const string BrightYellow = "#ffff00"; + public const string BrightBlue = "#0000ff"; + public const string BrightPurple = "#ff00ff"; + public const string BrightCyan = "#00ffff"; + public const string White = "#ffffff"; + + public static Dictionary ColorMap = new Dictionary() + { + { "0", Black }, // Black + { "1", Red }, // Red + { "2", Green }, // Green + { "3", Yellow }, // Yellow + { "4", Blue }, // Blue + { "5", Purple }, // Purple + { "6", Cyan }, // Cyan + { "7", LightGray }, // Light Gray + { "8", DarkGray }, // Dark Gray + { "9", BrightRed }, // Bright Red + { "10", BrightGreen }, // Bright Green + { "11", BrightYellow }, // Bright Yellow + { "12", BrightBlue }, // Bright Blue + { "13", BrightPurple }, // Bright Purple + { "14", BrightCyan }, // Bright Cyan + { "15", White } // White + }; + + public static class SelectGraphicRenditionParameters + { + public const int Reset = 0; + + public static HashSet SetForeground = new HashSet() + { + 30, 31, 32, 33, 34, 35, 36, 37,38 + }; + + } + } +} diff --git a/src/Microsoft.Tye.Hosting/Ansi2Html/Converter.cs b/src/Microsoft.Tye.Hosting/Ansi2Html/Converter.cs new file mode 100644 index 000000000..abb600717 --- /dev/null +++ b/src/Microsoft.Tye.Hosting/Ansi2Html/Converter.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; + +namespace Microsoft.Tye.Hosting.Ansi2Html +{ + public class Converter + { + private readonly Regex _rule = new Regex("\u001b\\[(?\\d+)(?;\\d+)*m", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase); + + public string Parse(string input) + { + var htmlText = _rule.Replace(input, match => + { + var code = Convert.ToInt32(match.Groups["code"].Value); + var args = match.Groups["args"].Value; + List attributes = args.Split(';').ToList(); + + var tagBuilder = new StringBuilder(); + if (code == Constants.SelectGraphicRenditionParameters.Reset) + { + tagBuilder.Append(""); + } + else + { + var color = Constants.White; + if (attributes.Count > 0) + { + string colorCode = attributes.Last(); + if (Constants.ColorMap.ContainsKey(colorCode)) + { + color = Constants.ColorMap[colorCode]; + } + } + + tagBuilder.Append(""); + } + + return tagBuilder.ToString(); + }); + + return htmlText; + } + } +} diff --git a/src/Microsoft.Tye.Hosting/Dashboard/Pages/Index.razor b/src/Microsoft.Tye.Hosting/Dashboard/Pages/Index.razor index cf06ba18b..c63736df1 100644 --- a/src/Microsoft.Tye.Hosting/Dashboard/Pages/Index.razor +++ b/src/Microsoft.Tye.Hosting/Dashboard/Pages/Index.razor @@ -12,13 +12,14 @@ + - + @@ -26,7 +27,11 @@ { var logsPath = $"logs/{service.Description.Name}"; var servicePath = $"services/{service.Description.Name}"; + var serviceState = service.State; + - + } } @@ -102,6 +107,16 @@ private List _subscriptions = new List(); + string GetServiceStateClass(ServiceState serviceState) => serviceState switch + { + ServiceState.Starting => "badge-secondary", + ServiceState.Started => "badge-success", + ServiceState.Degraded => "badge-danger", + ServiceState.Failed => "badge-warning", + ServiceState.Stopped => "badge-light", + _ => "badge-dark" + }; + string GetUrl(ServiceBinding b) { return $"{(b.Protocol ?? "tcp")}://{b.Host ?? "localhost"}:{b.Port}"; diff --git a/src/Microsoft.Tye.Hosting/Dashboard/Pages/Logs.razor b/src/Microsoft.Tye.Hosting/Dashboard/Pages/Logs.razor index 34130514f..f801f10b8 100644 --- a/src/Microsoft.Tye.Hosting/Dashboard/Pages/Logs.razor +++ b/src/Microsoft.Tye.Hosting/Dashboard/Pages/Logs.razor @@ -1,6 +1,8 @@ @page "/logs/{ServiceName}" +@using Microsoft.Tye.Hosting.Ansi2Html; @inject IJSRuntime JS @inject Application application +@inject Converter ansi2HtmlParser @implements IDisposable
Name Type Source Bindings Replicas RestartsLogs
+ @serviceState + @if(service.ServiceType == ServiceType.External) { @@ -34,7 +39,7 @@ } else { - @service.Description.Name + @service.Description.Name } @@ -91,7 +96,7 @@ { @service.Replicas.Count/@service.Description.Replicas @service.RestartsViewLogs | Metrics