1 // =================================
 2 // Copyright (c) 2022 Seppo Laakko
 3 // Distributed under the MIT license
 4 // =================================
 5 
 6 using System;
 7 using System.Collections;
 8 
 9 namespace System.Screen
10 {
11     public void Clear(const Rect& rectConsoleColor foreColorConsoleColor backColor)
12     {
13         Terminal.Out() << SetColors(foreColorbackColor);
14         ustring blankLine(' 'rect.size.w);
15         for (int i = 0; i < rect.size.h; ++i;)
16         {
17             SetCursorPos(rect.location.xrect.location.y + i);
18             Terminal.Out() << blankLine;
19         }
20     }
21     
22     public const uchar boxLeftTop = cast<uchar>(0x250c);
23     public const uchar boxRightTop = cast<uchar>(0x2510);
24     public const uchar boxHorizontal = cast<uchar>(0x2500);
25     public const uchar boxVertical = cast<uchar>(0x2502);
26     public const uchar boxLeftBottom = cast<uchar>(0x2514);
27     public const uchar boxRightBottom = cast<uchar>(0x2518);
28     
29     public void WriteBox(const Rect& rectConsoleColor foreColorConsoleColor backColor)
30     {
31         Clear(rectforeColorbackColor);
32         SetCursorPos(rect.location.xrect.location.y);
33         Terminal.Out() << boxLeftTop;
34         for (int i = 1; i < rect.size.w - 1; ++i;)
35         {
36             Terminal.Out() << boxHorizontal;
37         }
38         Terminal.Out() << boxRightTop;
39         for (int i = 1; i < rect.size.h - 1; ++i;)
40         {
41             SetCursorPos(rect.location.xrect.location.y + i);
42             Terminal.Out() << boxVertical;
43             SetCursorPos(rect.location.x + rect.size.w - 1rect.location.y + i);
44             Terminal.Out() << boxVertical;
45         }
46         SetCursorPos(rect.location.xrect.location.y + rect.size.h - 1);
47         Terminal.Out() << boxLeftBottom;
48         for (int i = 1; i < rect.size.w - 1; ++i;)
49         {
50             Terminal.Out() << boxHorizontal;
51         }
52         Terminal.Out() << boxRightBottom;
53     }
54     
55     public List<ustring> SplitIntoLines(const ustring& textint width)
56     {
57         List<ustring> lines;
58         List<ustring> words = text.Split(' ');
59         ustring line;
60         bool first = true;
61         for (const ustring& word : words)
62         {
63             if (first)
64             {
65                 first = false;
66             }
67             else
68             {
69                 line.Append(' ');
70             }
71             if (line.Length() + word.Length() > width)
72             {
73                 lines.Add(line);
74                 line.Clear();
75             }
76             line.Append(word);
77         }
78         if (!line.IsEmpty())
79         {
80             lines.Add(line);
81         }
82         return lines;
83     }
84 }