static void Main(string[] args) { WindowsConsole.TryEnableVirtualTerminalProcessing(); Console.Write(new StringBuilder() .SetTitle("Hello World") .HideCursor() .SaveState() ); for (var i = 0;; i++) { var color = new AnsiColor( (byte)(128 + Math.Sin(i / 200d) * 127), (byte)(128 + Math.Sin(i / 100d) * 127), (byte)(128 + Math.Sin(i / 130d) * 80)); Console.Write(new StringBuilder() .RestoreState() .SaveState() .SetMode(Mode.Reset) .Append("HELLO") .SetMode(Mode.Bold) .SetForegroundColor(color) .Append("WORLD") ); Thread.Sleep(25); } }
private static async Task Main(string[] _) { Console.WriteLine("Welcome! Try typing some fruit names."); Console.WriteLine(); var prompt = new Prompt( persistentHistoryFilepath: "./history-file", callbacks: new FruitPromptCallbacks(), configuration: new PromptConfiguration( prompt: new FormattedString(">>> ", new FormatSpan(0, 1, AnsiColor.Red), new FormatSpan(1, 1, AnsiColor.Yellow), new FormatSpan(2, 1, AnsiColor.Green)), completionItemDescriptionPaneBackground: AnsiColor.Rgb(30, 30, 30), selectedCompletionItemBackground: AnsiColor.Rgb(30, 30, 30), selectedTextBackground: AnsiColor.Rgb(20, 61, 102))); while (true) { var response = await prompt.ReadLineAsync().ConfigureAwait(false); if (response.IsSuccess) { if (response.Text == "exit") { break; } // optionally, use response.CancellationToken so the user can // cancel long-running processing of their response via ctrl-c Console.WriteLine("You wrote " + (response.SubmitKeyInfo.Modifiers.HasFlag(ConsoleModifiers.Control) ? response.Text.ToUpper() : response.Text)); } } }
/// <summary> /// Writes output to the main terminal window. /// </summary> /// <param name="text"></param> /// <param name="foregroundColor"></param> /// <param name="terminal"></param> public void EchoText(string text, AnsiColor foregroundColor, TerminalTarget terminal) { var line = text.ToLine(); line.ForegroundColor = foregroundColor; line.IgnoreLastColor = true; EchoText(line, terminal); }
public AnsiStyle(AnsiColor foregroundColor = AnsiColor.White, AnsiColor backgroundColor = AnsiColor.Black, bool blink = false, bool bold = false, bool italics = false, bool underline = false) { ForegroundColor = foregroundColor; BackgroundColor = backgroundColor; Blink = blink; Bold = bold; Italics = italics; Underline = underline; }
public AnsiText(string text) { _text = text; _color = AnsiColor.White; _bold = false; _italics = false; _underline = false; _strikethrough = false; _clear = false; }
/// <summary> /// Adds a line into the Lines list and appends it's content to the buffer. /// </summary> /// <param name="text"></param> /// <param name="foregroundColor"></param> /// <remarks> /// As the Text property isn't used in this context we are specificity not allocating an /// entry for it. In the past we used to save a collection of the lines received but we /// are no longer doing that for now. /// </remarks> public void Append(string text, AnsiColor foregroundColor) { var line = new Line { FormattedText = text, IgnoreLastColor = true, ForegroundColor = foregroundColor }; Append(line); }
/// <summary> /// Adds a line into the Lines list and appends it's content to the buffer. /// </summary> /// <param name="sb"></param> /// <param name="foregroundColor"></param> /// <remarks> /// As the Text property isn't used in this context we are specificity not allocating an /// entry for it. In the past we used to save a collection of the lines received but we /// are no longer doing that for now. /// </remarks> public void Append(StringBuilder sb, AnsiColor foregroundColor) { var line = new Line { FormattedText = sb.ToString(), IgnoreLastColor = true, ForegroundColor = foregroundColor }; Append(line); }
public static void WriteLogo() { Log.Verbose(AnsiColor.ReplaceColors("{M___________________________________________________________________{n")); Log.Verbose(AnsiColor.ReplaceColors("{M_{Yoo{M____{Yoo{M______________________________{Yooo{M_____{Yooo{M______________{Yoo{M_{n")); Log.Verbose(AnsiColor.ReplaceColors("{M_{Yoo{M___{Yoo{M__{Yoo{M____{Yo{M_{Yoo{M_{Yoo{M_{Yoo{M__{Yoo{M____{Yo{M____{Yoooo{M___{Yoooo{M_{Yoo{M____{Yo{M__{Yoooooo{M_{n")); Log.Verbose(AnsiColor.ReplaceColors("{M_{Yoo{M__{Yoo{M___{Yoo{M____{Yo{M_{Yooo{M_{Yoo{M__{Yo{M_{Yoo{M____{Yo{M____{Yoo{M_{Yoo{M_{Yoo{M_{Yoo{M_{Yoo{M____{Yo{M_{Yoo{M___{Yoo{M_{n")); Log.Verbose(AnsiColor.ReplaceColors("{M_{Yoooooo{M___{Yoo{M____{Yo{M_{Yoo{M__{Yoo{M__{Yo{M_{Yoo{M____{Yo{M____{Yoo{M__{Yooo{M__{Yoo{M_{Yoo{M____{Yo{M_{Yoo{M___{Yoo{M_{n")); Log.Verbose(AnsiColor.ReplaceColors("{M_{Yoo{M___{Yoo{M__{Yooo{M___{Yo{M_{Yoo{M__{Yoo{M__{Yo{M_{Yooo{M___{Yo{M____{Yoo{M_______{Yoo{M_{Yooo{M___{Yo{M_{Yoo{M___{Yoo{M_{n")); Log.Verbose(AnsiColor.ReplaceColors("{M_{Yoo{M____{Yoo{M_{Yoo{M_{Yooo{M__{Yoo{M______{Yo{M_{Yoo{M_{Yooo{M_____{Yoo{M_______{Yoo{M_{Yoo{M_{Yooo{M___{Yoooooo{M_{n")); Log.Verbose(AnsiColor.ReplaceColors("{M___________________________________________________________________{n")); }
/// <summary> /// Process a shutdown with a text message, this fires off a warning since a shutdown is /// essentially warning-worthy in my opinion. Yours may vary ;-) /// </summary> /// <param name="msg">The message to process with exception</param> /// <param name="e">Any exception passed or null</param> /// <param name="level">The level of the message to log</param> public static void Shutdown(string msg, Exception e = null, LogLevel level = LogLevel.Warning) { string smsg = AnsiColor.ReplaceColors(msg + (e == null ? "" : "Exception: " + e.Message)); Core.LogMsg(smsg, level); Environment.Exit(-1); //TODO: Why does this barf? [note from the future: who cares? - km] //var methodInfo = Log.Logger.GetType().GetMethod(level.ToString(), new Type[] { typeof(string) }); //object[] parametersArray = new object[] { smsg }; //methodInfo.Invoke(Log.Logger, parametersArray); }
/// <summary> /// Tells the implementing window or form that it needs to echo some text to it's terminal. /// </summary> /// <param name="text"></param> /// <param name="foregroundColor"></param> public void EchoText(string text, AnsiColor foregroundColor) { var e = new EchoEventArgs { Text = $"{text}\r\n", UseDefaultColors = false, ForegroundColor = foregroundColor, Terminal = TerminalTarget.Main }; this.OnEcho(e); }
/// <summary> /// Adds a line into the Lines list and appends it's content to the buffer. /// </summary> /// <param name="text"></param> /// <param name="foregroundColor"></param> public void Append(string text, AnsiColor foregroundColor) { var line = new Line { FormattedText = text, Text = Colorizer.RemoveAllAnsiCodes(text), IgnoreLastColor = true, ForegroundColor = foregroundColor }; Append(line); }
/// <summary> /// Adds a line into the Lines list and appends it's content to the buffer. /// </summary> /// <param name="text"></param> /// <param name="foregroundColor"></param> /// <param name="reverseColors"></param> /// <remarks> /// As the Text property isn't used in this context we are specificity not allocating an /// entry for it. In the past we used to save a collection of the lines received but we /// are no longer doing that for now. /// </remarks> public void Append(string text, AnsiColor foregroundColor, bool reverseColors) { var line = new Line { FormattedText = text, IgnoreLastColor = true, ForegroundColor = foregroundColor, ReverseColors = reverseColors }; Append(line); }
/// <summary> /// Adds a line into the Lines list and appends it's content to the buffer. /// </summary> /// <param name="sb"></param> /// <param name="foregroundColor"></param> /// <param name="reverseColors"></param> /// <param name="scrollToLastLine">Whether or not the line should cause the terminal to scroll to the last line.</param> /// <remarks> /// As the Text property isn't used in this context we are specificity not allocating an /// entry for it. In the past we used to save a collection of the lines received but we /// are no longer doing that for now. /// </remarks> public void Append(StringBuilder sb, AnsiColor foregroundColor, bool reverseColors, bool scrollToLastLine) { var line = new Line { FormattedText = sb.ToString(), IgnoreLastColor = true, ForegroundColor = foregroundColor, ReverseColors = reverseColors, ScrollToLastLine = scrollToLastLine }; Append(line); }
/// <summary> /// Tells the implementing window or form that it needs to echo some text to it's terminal. /// </summary> /// <param name="text"></param> /// <param name="foregroundColor"></param> /// <param name="reverseColors"></param> /// <param name="terminal">The terminal that the main window should try to echo to.</param> public void EchoText(string text, AnsiColor foregroundColor, bool reverseColors, TerminalTarget terminal) { var e = new EchoEventArgs { Text = $"{text}\r\n", UseDefaultColors = false, ForegroundColor = foregroundColor, ReverseColors = reverseColors, Terminal = terminal }; this.OnEcho(e); }
/// <summary> /// Constructs a player. /// </summary> public Player(PlayerInterfaceControl playerInterface) { CurrentParseState = new ParseState(); Palette = new MudPalette0(); SentCommands = new Queue <string>(); CurrentColor = new AnsiColor() { ForegroundCode = AnsiColorCode.White, BackgroundCode = AnsiColorCode.Black }; StatlineRegex = new Regex("\\[HP=(?<hp>-?\\d+)/(?<mhp>\\d+),MA=(?<mp>\\d+)/(?<mmp>\\d+)]:( \\(Resting\\) )? "); Interface = playerInterface; this.Money = new Wallet(); StartupMessage(); }
/// <summary> /// Processes the ecape sequence. /// </summary> /// <exception cref="InvalidDataException"><c>InvalidDataException</c>.</exception> private void ProcessEcapeSequence() { int sequenceValue = 0; if (_hasFirstEscapeParamChar) { sequenceValue += _firstEscapeParamChar - '0'; } if (_hasSecondEsapeParamChar) { sequenceValue = (sequenceValue * 10) + (_secondEscapeParamChar - '0'); } if (sequenceValue == 0) { _isBright = false; _currentForeColor = AnsiColor.None; _currentBackColor = AnsiColor.None; } else if (sequenceValue == 1) { _isBright = true; } else if (sequenceValue >= _asciBackGroundCodeBase && sequenceValue <= _asciBackGroundCodeBase + (int)AnsiColor.White) { _currentBackColor = (AnsiColor)(sequenceValue - _asciBackGroundCodeBase); } else if (sequenceValue >= _asciForeGroundCodeBase && sequenceValue <= _asciForeGroundCodeBase + (int)AnsiColor.White) { _currentForeColor = (AnsiColor)(sequenceValue - _asciForeGroundCodeBase); } else { throw new InvalidDataException( string.Format( CultureInfo.InvariantCulture, "ASCI escape sequence has invalid parameter - '{0}'", sequenceValue)); } }
static void Main(string[] args) { const string template = "{Timestamp:yy-MM-dd HH:mm:ss} [{Level}] {Indent:l}{Message}{NewLine}{Exception}"; ParseOptions(args); Log.Logger = new LoggerConfiguration() .MinimumLevel.Verbose() .WriteTo.Console() .WriteTo.Logger( x => x.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Fatal) .WriteTo.File($"logs/driver-fatal.log", rollingInterval: RollingInterval.Day, rollOnFileSizeLimit: true, outputTemplate: template) ) .WriteTo.Logger( x => x.Filter.ByIncludingOnly(e => e.Level is LogEventLevel.Warning or LogEventLevel.Error) .WriteTo.File($"logs/driver-errors.log", rollingInterval: RollingInterval.Day, rollOnFileSizeLimit: true, outputTemplate: template) ) .WriteTo.Logger( x => x.Filter.ByExcluding(e => e.Level is LogEventLevel.Warning or LogEventLevel.Error or LogEventLevel.Fatal or LogEventLevel.Verbose) .WriteTo.File($"logs/mud-info.log", rollingInterval: RollingInterval.Day, rollOnFileSizeLimit: true, outputTemplate: template) ).CreateLogger(); // Removed capturing of Ctrl-C since it failed across platforms // evaluate adding back later. Log.Information(AnsiColor.ReplaceColors("{GBringing the hyper-drive systems online...{n")); Core.StartKernel(Uid.Kernel); }
public string GetColor(AnsiColor color, string text) => $"\\x1b[{color}m{text}\\x1b[0m";
public static string AnsiColorEscapeCode(this AnsiColor color) => $"\u001b[{(int)color}m";
public static string Colorize(this string value, AnsiColor color) => $"{color.AnsiColorEscapeCode()}{value}{AnsiColor.None.AnsiColorEscapeCode()}";
public int setColorAnsi(AnsiColor fg, uint bg) { return caca_set_color_ansi(_c_cv, (byte)fg, (byte)bg); }
public int setColorAnsi(AnsiColor fg, uint bg) { return(caca_set_color_ansi(_c_cv, (byte)fg, (byte)bg)); }
private static TextColor ConvertAnsiColorToTextColor(AnsiColor ansiColor, bool isBright) { if (isBright) { switch (ansiColor) { case AnsiColor.Black: return(TextColor.BrightBlack); case AnsiColor.Blue: return(TextColor.BrightBlue); case AnsiColor.Cyan: return(TextColor.BrightCyan); case AnsiColor.Green: return(TextColor.BrightGreen); case AnsiColor.Magenta: return(TextColor.BrightMagenta); case AnsiColor.Red: return(TextColor.BrightRed); case AnsiColor.White: return(TextColor.BrightWhite); case AnsiColor.Yellow: return(TextColor.BrightYellow); } } else { switch (ansiColor) { case AnsiColor.Black: return(TextColor.Black); case AnsiColor.Blue: return(TextColor.Blue); case AnsiColor.Cyan: return(TextColor.Cyan); case AnsiColor.Green: return(TextColor.Green); case AnsiColor.Magenta: return(TextColor.Magenta); case AnsiColor.Red: return(TextColor.Red); case AnsiColor.White: return(TextColor.White); case AnsiColor.Yellow: return(TextColor.Yellow); } } return(TextColor.None); }
public static StringBuilder BeginColor(this StringBuilder builder, AnsiColor color) { return(builder.Append(color.AnsiColorEscapeCode())); }
public static string Color(this string text, AnsiColor color) => Color(text, color.ColorCode);
public static string Color(this string text, AnsiColor color) { return($"\x1B[{(color.ColorType == AnsiColorType.FourBit ? "" : "38;5;") + color.ColorCode}m{text}\x1B[0m"); }
public AnsiText Color(AnsiColor color) { _color = color; return this; }
/// <summary> /// Writes output to the main terminal window. /// </summary> /// <param name="text"></param> /// <param name="foregroundColor"></param> /// <param name="terminal"></param> public void EchoText(string text, AnsiColor foregroundColor, TerminalTarget terminal) { EchoText(text.ToLine().ForegroundColor = foregroundColor, terminal); }