public static void Print(StyledString msg, Color color) { if (!Silent) { Console.WriteLine(msg, color); } }
public GridMutation WriteText(int x, int y, string text) { Figlet figlet = new Figlet(); StyledString f = figlet.ToAscii(text); var mutation = new GridMutation(); for (int _y = 0; _y < f.CharacterGeometry.GetLength(0); _y++) { for (int _x = 0; _x < f.CharacterGeometry.GetLength(1); _x++) { mutation.AddTarget(new DrawablePoint(_x + x, _y + y, f.CharacterGeometry[_y, _x])); } } return(mutation); }
public StyledString ToAscii(string value) { if (value == null) { throw new ArgumentNullException(nameof(value)); } StringBuilder stringBuilder = new StringBuilder(); int stringWidth = GetStringWidth(font, value); char[,] characterGeometry = new char[font.Height + 1, stringWidth]; int[,] characterIndexGeometry = new int[font.Height + 1, stringWidth]; Color[,] colorGeometry = new Color[font.Height + 1, stringWidth]; for (int line = 1; line <= font.Height; line++) { int runningWidthTotal = 0; for (int c = 0; c < value.Length; c++) { char character = value[c]; string fragment = GetCharacter(this.font, character, line); stringBuilder.Append(fragment); CalculateCharacterGeometries(fragment, c, runningWidthTotal, line, characterGeometry, characterIndexGeometry); runningWidthTotal += fragment.Length; } stringBuilder.AppendLine(); } StyledString styledString = new StyledString(value, stringBuilder.ToString()); styledString.CharacterGeometry = characterGeometry; styledString.CharacterIndexGeometry = characterIndexGeometry; styledString.ColorGeometry = colorGeometry; return styledString; }
private void SceneGraph_ScreenBufferDirtyEvent(string buffer) { string[] lines = buffer.Split(new string[] { Environment.NewLine }, StringSplitOptions.None).ToArray(); bufferLines = new StyledString[lines.Length]; StyleSheet styleDefault = new StyleSheet(Color.White); for (int i = 0; i < bufferLines.Length; i++) { string line = lines[i]; Match m = preprocessRegex.Match(line); if (!m.Success) { bufferLines[i] = new StyledString(line) { ColorGeometry = new Color[, ] { { Color.White, Color.Black } } }; } else { string[] parts = preprocessRegex.Split(line); for (int j = 1; j < m.Groups.Count; j++) { string[] command = m.Groups[j].Value.Split('|'); string font = command[0]; string text = command[1]; string fg = command[2]; string bg = command[3]; StyledString s; if (command[0].IsNotEmpty()) { bufferLines[i] = figlet["ANSI Shadow"].ToAscii(text); } else { bufferLines[i] = new StyledString(line) { ColorGeometry = new Color[, ] { { Color.White, Color.Black } } }; } } } } Console.SetCursorPosition(0, 0); for (int i = 0; i < bufferLines.Length; i++) { if (oldBufferLines.Length > i && oldBufferLines[i] == bufferLines[i]) { continue; } else { if (bufferLines[i].CharacterGeometry == null) { Console.Write(bufferLines[i].AbstractValue + Environment.NewLine); } else { Console.WriteLineStyled(bufferLines[i], styleDefault); } } } oldBufferLines = bufferLines; }