Esempio n. 1
0
        private static IRenderable CreatePrettyMessage(string arguments, CommandTreeToken token, string message, string details)
        {
            var composer = new Composer();

            var position = token?.Position ?? 0;
            var value    = token?.Representation ?? arguments;

            // Header
            composer.LineBreak();
            composer.Style("red", "Error:");
            composer.Space().Text(message.EscapeMarkup());
            composer.LineBreak();

            // Template
            composer.LineBreak();
            composer.Spaces(7).Text(arguments.EscapeMarkup());

            // Error
            composer.LineBreak();
            composer.Spaces(7).Spaces(position);

            composer.Style("red", error =>
            {
                error.Repeat('^', value.Length);
                error.Space();
                error.Text(details.TrimEnd('.').EscapeMarkup());
                error.LineBreak();
            });

            composer.LineBreak();

            return(composer);
        }
        private static IRenderable CreatePrettyMessage(string template, TemplateToken?token, string message, string details)
        {
            var composer = new Composer();

            var position = token?.Position ?? 0;
            var value    = token?.Representation ?? template;

            // Header
            composer.LineBreak();
            composer.Style("red", "Error:");
            composer.Space().Text("An error occured when parsing template.");
            composer.LineBreak();
            composer.Spaces(7).Style("yellow", message.EscapeMarkup());
            composer.LineBreak();

            if (string.IsNullOrWhiteSpace(template))
            {
                // Error
                composer.LineBreak();
                composer.Style("red", message.EscapeMarkup());
                composer.LineBreak();
            }
            else
            {
                // Template
                composer.LineBreak();
                composer.Spaces(7).Text(template.EscapeMarkup());

                // Error
                composer.LineBreak();
                composer.Spaces(7).Spaces(position);
                composer.Style("red", error =>
                {
                    error.Repeat('^', value.Length);
                    error.Space();
                    error.Text(details.TrimEnd('.').EscapeMarkup());
                    error.LineBreak();
                });
            }

            composer.LineBreak();

            return(composer);
        }