コード例 #1
0
ファイル: BaCon.cs プロジェクト: jazmatician/BizArk3
        /***
         * BaCon does not support Write (as opposed to WriteLine) because BaCon needs to have full control over the line
         * that it is printing on in order for line wrapping to work correctly.
         */

        /// <summary>
        /// Writes the value to the console using the given options.
        /// </summary>
        /// <param name="value">The value to write.</param>
        /// <param name="color">The color to print the value in. Only works when using the Console.</param>
        /// <param name="indent1">Number of spaces to put in front of first line of text.</param>
        /// <param name="indentN">Number of spaces to put in front of following lines of text if the value must be wrapped to additional lines.</param>
        public static void WriteLine(string value = null, ConsoleColor?color = null, string indent1 = "", string indentN = "")
        {
            if (value.IsEmpty())
            {
                (Out ?? Console.Out).WriteLine();
                return;
            }

            using (var clr = new BaConColor(color ?? Console.ForegroundColor))
            {
                var displayVal = value;

                if (indent1.HasValue())
                {
                    displayVal = indent1 + displayVal;
                }

                var options = new StringWrapOptions()
                {
                    MaxWidth = ConsoleWidth, TabWidth = ConsoleTabWidth, Prefix = indentN
                };
                displayVal = displayVal.Wrap(options);

                (Out ?? Console.Out).WriteLine(displayVal);
            }
        }
コード例 #2
0
ファイル: BaCon.cs プロジェクト: jazmatician/BizArk3
        /// <summary>
        /// Displays the exception to the console.
        /// </summary>
        /// <param name="ex"></param>
        public static void WriteError(Exception ex)
        {
            var curEx = ex;

            if (curEx == null)
            {
                return;
            }

            if (ErrorMessageTitle.HasValue())
            {
                using (var clr = new BaConColor(BaCon.Theme.ErrorTitleText, BaCon.Theme.ErrorTitleBackground))
                    WriteLine(ErrorMessageTitle);
            }

            while (curEx != null)
            {
                WriteLine(new string('*', ConsoleWidth));
                WriteLine("{0} - {1}".Fmt(curEx.GetType().FullName, curEx.Message), Theme.ErrorColor);
                WriteLine(curEx.StackTrace, indentN: "\t");
                WriteLine();
                curEx = curEx.InnerException;
            }
        }