コード例 #1
0
 /// <summary>
 /// Sets the current info about the console (x/y/fg/bg) as a <see cref="PutCharData"/>
 /// </summary>
 /// <param name="putCharData">The state information to set.</param>
 public void SetStateAsPutCharData(PutCharData putCharData)
 {
     X          = putCharData.X;
     Y          = putCharData.Y;
     Background = putCharData.Background;
     Foreground = putCharData.Foreground;
 }
コード例 #2
0
        /// <summary>
        /// Writes a string to the console.
        /// </summary>
        /// <param name="console">The console.</param>
        /// <param name="str">The string.</param>
        /// <param name="putCharData">Data about the string.</param>
        /// <returns>The same console.</returns>
        public static IConsole Write
        (
            [NotNull] this IConsole console,
            [NotNull] string str,
            PutCharData putCharData
        )
        {
            if (console is Console sysConsole)
            {
                var oldState = sysConsole.GetStateAsPutCharData();
                sysConsole.SetStateAsPutCharData(putCharData);
                sysConsole.Write(str);
                sysConsole.SetStateAsPutCharData(oldState);

                return(console);
            }

            var characters = str.ToCharArray();

            for (var chrIndex = 0; chrIndex < characters.Length; chrIndex++)
            {
                var chr = characters[chrIndex];

                console.PutCharWithWrapping(chr, new PutCharData
                {
                    X          = chrIndex + putCharData.X,
                    Y          = putCharData.Y,
                    Background = putCharData.Background,
                    Foreground = putCharData.Foreground
                });
            }

            return(console);
        }
コード例 #3
0
        /// <summary>
        /// Writes a line with the string given to the console.
        /// </summary>
        /// <param name="console">The console.</param>
        /// <param name="str">The string.</param>
        /// <param name="putCharData">Data about the line.</param>
        /// <returns>The same console.</returns>
        public static IConsole WriteLine
        (
            [NotNull] this IConsole console,
            [NotNull] string str,
            PutCharData putCharData
        )
        {
            if (console is Console sysConsole)
            {
                var oldState = sysConsole.GetStateAsPutCharData();
                sysConsole.SetStateAsPutCharData(putCharData);
                sysConsole.WriteLine(str);
                sysConsole.SetStateAsPutCharData(oldState);

                return(console);
            }

            return(console.Write(str, putCharData)
                   .Write(Environment.NewLine, new PutCharData
            {
                X = putCharData.X + str.Length,
                Y = putCharData.Y,
                Background = putCharData.Background,
                Foreground = putCharData.Foreground
            }));
        }
コード例 #4
0
        /// <summary>
        /// Puts a single character on the console
        /// at any given X or Y, negative or positive,
        /// by wrapping the coordinates around until
        /// they're in bounds.
        /// </summary>
        /// <param name="console">The console.</param>
        /// <param name="character">The character to put.</param>
        /// <param name="putCharData">Data about the character.</param>
        /// <returns>The same console.</returns>
        public static IConsole PutCharWithWrapping
        (
            [NotNull] this IConsole console,
            char character,
            PutCharData putCharData
        )
        {
            var boundedX = putCharData.X;
            var boundedY = putCharData.Y;

            WrapValueLower(ref boundedX, 0, console.Width, () => boundedY++);
            WrapValueUpper(ref boundedX, console.Width, console.Width, () => boundedY++);

            WrapValueLower(ref boundedY, 0, console.Height);
            WrapValueUpper(ref boundedY, console.Height, console.Height);

            console.PutChar(character, new PutCharData
            {
                X          = boundedX,
                Y          = boundedY,
                Background = putCharData.Background,
                Foreground = putCharData.Foreground
            });

            return(console);
        }
コード例 #5
0
 /// <inheritdoc/>
 public void PutChar(char character, PutCharData putCharData)
 => _console.PutChar(character, new PutCharData
 {
     X          = putCharData.X + _sourceX,
     Y          = putCharData.Y + _sourceY,
     Background = putCharData.Background,
     Foreground = putCharData.Foreground
 });
コード例 #6
0
        /// <inheritdoc/>
        public void PutChar(char character, PutCharData putCharData)
        {
            var oldPutCharData = GetStateAsPutCharData();

            SetStateAsPutCharData(putCharData);

            Write(character);

            SetStateAsPutCharData(oldPutCharData);
        }
コード例 #7
0
        /// <summary>
        /// Clears the console, by writing a giant blank string to it.
        /// </summary>
        /// <param name="console">The console.</param>
        /// <param name="clearData">Data about the clear.</param>
        /// <param name="clearChar">The character to use when clearing.</param>
        /// <returns>The same console.</returns>
        public static IConsole Clear
        (
            [NotNull] this IConsole console,
            PutCharData clearData,
            char clearChar = ' '
        )
        {
            if (console is Console sysConsole)
            {
                sysConsole.SetStateAsPutCharData(clearData);
                sysConsole.Clear();
            }
            else
            {
                console.Write(new string(clearChar, console.Width * console.Height), clearData);
                console.PutChar(' ', clearData);
            }

            return(console);
        }
コード例 #8
0
 /// <inheritdoc/>
 public void PutChar(char character, PutCharData putCharData)
 => CurrentBuffer[putCharData.X, putCharData.Y] = new BufferState
 {
     Character   = character,
     PutCharData = putCharData
 };
コード例 #9
0
 /// <inheritdoc/>
 public void PutChar(char character, PutCharData putCharData) => _parentConsole.PutChar(character, putCharData);