This repository was archived by the owner on Apr 15, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathConsolePositioning.cs
More file actions
109 lines (87 loc) · 1.8 KB
/
ConsolePositioning.cs
File metadata and controls
109 lines (87 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System;
namespace MultiAdmin.ConsoleTools
{
public static class ConsolePositioning
{
#region Console Point Properties
public static BufferPoint BufferCursor
{
get => new(Console.CursorLeft, Console.CursorTop);
set => Console.SetCursorPosition(value.x, value.y);
}
public static ConsolePoint ConsoleCursor
{
get => BufferCursor.ConsolePoint;
set => BufferCursor = value.BufferPoint;
}
public static BufferPoint BufferLeft
{
get => new(0, 0);
}
public static BufferPoint BufferRight
{
get => new(Console.BufferWidth - 1, 0);
}
public static BufferPoint BufferTop
{
get => new(0, 0);
}
public static BufferPoint BufferBottom
{
get => new(0, Console.BufferHeight - 1);
}
#endregion
}
public readonly struct ConsolePoint
{
public readonly int x, y;
public BufferPoint BufferPoint => new(this);
public ConsolePoint(int x, int y)
{
this.x = x;
this.y = y;
}
public ConsolePoint(BufferPoint bufferPoint) : this(bufferPoint.x - Console.WindowLeft,
bufferPoint.y - Console.WindowTop)
{
}
public void SetAsCursor()
{
BufferPoint.SetAsCursor();
}
public void SetAsCursorX()
{
BufferPoint.SetAsCursorX();
}
public void SetAsCursorY()
{
BufferPoint.SetAsCursorY();
}
}
public readonly struct BufferPoint
{
public readonly int x, y;
public ConsolePoint ConsolePoint => new(this);
public BufferPoint(int x, int y)
{
this.x = x;
this.y = y;
}
public BufferPoint(ConsolePoint consolePoint) : this(consolePoint.x + Console.WindowLeft,
consolePoint.y + Console.WindowTop)
{
}
public void SetAsCursor()
{
ConsolePositioning.BufferCursor = this;
}
public void SetAsCursorX()
{
Console.CursorLeft = x;
}
public void SetAsCursorY()
{
Console.CursorTop = y;
}
}
}