1
2
3
4
5
6 using System;
7 using System.Collections;
8
9 namespace System.Screen
10 {
11 public void Clear(const Rect& rect, ConsoleColor foreColor, ConsoleColor backColor)
12 {
13 Terminal.Out() << SetColors(foreColor, backColor);
14 ustring blankLine(' ', rect.size.w);
15 for (int i = 0; i < rect.size.h; ++i;)
16 {
17 SetCursorPos(rect.location.x, rect.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& rect, ConsoleColor foreColor, ConsoleColor backColor)
30 {
31 Clear(rect, foreColor, backColor);
32 SetCursorPos(rect.location.x, rect.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.x, rect.location.y + i);
42 Terminal.Out() << boxVertical;
43 SetCursorPos(rect.location.x + rect.size.w - 1, rect.location.y + i);
44 Terminal.Out() << boxVertical;
45 }
46 SetCursorPos(rect.location.x, rect.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& text, int 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 }