Skip to content

Can CsConsoleFormat support output chinese words? #27

@wangshuai-007

Description

@wangshuai-007

If I output chinese words,the grid will broken,I think the problem is in the character calculation of Chinese characters.
My code is like this:

static void Main(string[] args)
        {
            var headerThickness = new LineThickness(LineWidth.Double, LineWidth.Single);

            Console.WriteLine("outpt Chinese");
            var doc = new Document(
                new Span("Order #") { Color = Yellow }, "Id", "\n",
                new Span("Customer: ") { Color = Yellow }, "Name",
                new Grid
                {
                    Color = Gray,
                    Columns = { GridLength.Char(10), GridLength.Char(20), GridLength.Char(70) },
                    Children = {
                        new Cell("Id") { Stroke = headerThickness ,TextAlign =TextAlign.Center},
                        new Cell("Name") { Stroke = headerThickness ,TextAlign =TextAlign.Center},
                        new Cell("Assembly") { Stroke = headerThickness,TextAlign =TextAlign.Center },
                        new[] {
                            new Cell("AAAAA"),
                            new Cell("这里是中文,有错误!"),
                            new Cell("BBBBBBBBBBBBBBBBBBBBBBBB"),
                        }
                    }
                }
            );

            ConsoleRenderer.RenderDocument(doc);
            Console.WriteLine("outpt English");
            doc = new Document(
                new Span("Order #") { Color = Yellow }, "Id", "\n",
                new Span("Customer: ") { Color = Yellow }, "Name",
                new Grid
                {
                    Color = Gray,
                    Columns = { GridLength.Char(10), GridLength.Char(20), GridLength.Char(70) },
                    Children = {
                        new Cell("Id") { Stroke = headerThickness ,TextAlign =TextAlign.Center},
                        new Cell("Name") { Stroke = headerThickness ,TextAlign =TextAlign.Center},
                        new Cell("Assembly") { Stroke = headerThickness,TextAlign =TextAlign.Center },
                        new[] {
                            new Cell("AAAAA"),
                            new Cell("This is English,And it is OK"),
                            new Cell("BBBBBBBBBBBBBBBBBBBBBBBB"),
                        }
                    }
                }
            );

            ConsoleRenderer.RenderDocument(doc);
        }

the output is the follow.
image

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions