/// <summary> /// Writes a filename /// </summary> /// <typeparam name="T">Writer type</typeparam> /// <param name="output">Output</param> /// <param name="filename">Filename</param> /// <returns></returns> public static T WriteFilename <T>(this T output, string?filename) where T : ITextColorWriter { if (filename is null) { return(output); } filename = NameUtilities.CleanName(filename) !; var s = filename.Replace('\\', '/'); var parts = s.Split('/'); int slashIndex = 0; for (int i = 0; i < parts.Length - 1; i++) { output.Write(BoxedTextColor.DirectoryPart, parts[i]); slashIndex += parts[i].Length; output.Write(BoxedTextColor.Text, filename[slashIndex].ToString()); slashIndex++; } var fn = parts[parts.Length - 1]; int index = fn.LastIndexOf('.'); if (index < 0) { output.Write(BoxedTextColor.FileNameNoExtension, fn); } else { string ext = fn.Substring(index + 1); fn = fn.Substring(0, index); output.Write(BoxedTextColor.FileNameNoExtension, fn); output.Write(BoxedTextColor.Text, "."); output.Write(BoxedTextColor.FileExtension, ext); } return(output); }
/// <summary> /// Writes a module name /// </summary> /// <typeparam name="T">Writer type</typeparam> /// <param name="output">Output</param> /// <param name="name">Module name</param> /// <returns></returns> public static T WriteModule <T>(this T output, string name) where T : ITextColorWriter { output.Write(BoxedTextColor.AssemblyModule, NameUtilities.CleanName(name)); return(output); }