Example #1
0
        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);
            }
        }
Example #2
0
    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));
            }
        }
    }
Example #3
0
        /// <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);
        }
Example #4
0
 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;
 }
Example #5
0
        public AnsiText(string text)
        {
            _text = text;
            _color = AnsiColor.White;

            _bold = false;
            _italics = false;
            _underline = false;
            _strikethrough = false;
            _clear = false;
        }
Example #6
0
        /// <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);
        }
Example #7
0
        /// <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);
        }
Example #8
0
 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"));
 }
Example #9
0
        /// <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);
        }
Example #10
0
        /// <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);
        }
Example #11
0
        /// <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);
        }
Example #12
0
        /// <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);
        }
Example #13
0
        /// <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);
        }
Example #14
0
        /// <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);
        }
Example #15
0
        /// <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));
            }
        }
Example #17
0
        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);
        }
Example #18
0
 public string GetColor(AnsiColor color, string text) => $"\\x1b[{color}m{text}\\x1b[0m";
Example #19
0
 public static string AnsiColorEscapeCode(this AnsiColor color) => $"\u001b[{(int)color}m";
Example #20
0
 public static string Colorize(this string value, AnsiColor color) =>
 $"{color.AnsiColorEscapeCode()}{value}{AnsiColor.None.AnsiColorEscapeCode()}";
Example #21
0
 public int setColorAnsi(AnsiColor fg, uint bg)
 {
     return caca_set_color_ansi(_c_cv, (byte)fg, (byte)bg);
 }
Example #22
0
 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);
        }
Example #24
0
 public static StringBuilder BeginColor(this StringBuilder builder, AnsiColor color)
 {
     return(builder.Append(color.AnsiColorEscapeCode()));
 }
Example #25
0
 public static string Color(this string text, AnsiColor color) => Color(text, color.ColorCode);
Example #26
0
 public static string Color(this string text, AnsiColor color)
 {
     return($"\x1B[{(color.ColorType == AnsiColorType.FourBit ? "" : "38;5;") + color.ColorCode}m{text}\x1B[0m");
 }
Example #27
0
 public AnsiText Color(AnsiColor color)
 {
     _color = color;
     return this;
 }
Example #28
0
 /// <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);
 }