forked from BattlefieldDuck/XtermBlazor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Index.razor
206 lines (167 loc) · 5.81 KB
/
Index.razor
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
@page "/"
@using System.Text.Json;
<h1>Hello, world!</h1>
<p>Welcome to XtermBlazor Demo.</p>
<div class="mb-2">
<input type="button" @onclick="HasSelection" value="HasSelection()" />
<input type="button" @onclick="GetSelection" value="GetSelection()" />
<input type="button" @onclick="GetSelectionPosition" value="GetSelectionPosition()" />
<input type="button" @onclick="ClearSelection" value="ClearSelection()" />
<input type="button" @onclick="SelectAll" value="SelectAll()" />
<input type="button" @onclick="ScrollToTop" value="ScrollToTop()" />
<input type="button" @onclick="ScrollToBottom" value="ScrollToBottom()" />
<input type="button" @onclick="Reset" value="Reset()" />
</div>
<div class="mb-2">
<input type="text" @bind-value="_input">
<input type="button" @onclick="Write" value="Write()" />
<input type="button" @onclick="WriteLine" value="WriteLine()" />
Cols: <input type="number" maxlength="4" size="4" @bind-value="_columns">
Rows: <input type="number" maxlength="4" size="4" @bind-value="_rows">
<input type="button" @onclick="Resize" value="Resize()" />
<input type="button" @onclick="GetRows" value="GetRows()" />
<input type="button" @onclick="GetColumns" value="GetColumns()" />
</div>
<Xterm
@ref="_terminal"
Options="_options"
OnFirstRender="@OnFirstRender"
OnBinary="@OnBinary"
OnCursorMove="@OnCursorMove"
OnData="@OnData"
OnKey="@OnKey"
OnLineFeed="@OnLineFeed"
OnScroll="@OnScroll"
OnSelectionChange="@OnSelectionChange"
OnRender="@OnRender"
OnResize="@OnResize"
OnTitleChange="@OnTitleChange"
OnBell="@OnBell"
/>
<br />
EventCallback Logs:
<Xterm @ref="_terminalEvent" Options="_options2" />
@code {
private Xterm _terminal, _terminalEvent;
private TerminalOptions _options = new TerminalOptions
{
CursorBlink = true,
CursorStyle = CursorStyle.Bar,
Rows = 10,
Theme =
{
Background = "#17615e",
},
};
private TerminalOptions _options2 = new TerminalOptions
{
Columns = 140,
};
private int _eventId = 0, _columns, _rows;
private string _input = "Hello World";
private async Task OnFirstRender()
{
await _terminalEvent.WriteLine($"({++_eventId}) OnFirstRender()");
_columns = await _terminal.GetColumns();
_rows = await _terminal.GetRows();
}
private async Task OnBinary(string data)
{
await _terminalEvent.WriteLine($"({++_eventId}) OnBinary(): {data}");
}
private async Task OnCursorMove()
{
await _terminalEvent.WriteLine($"({++_eventId}) OnCursorMove()");
}
private async Task OnData(string data)
{
await _terminalEvent.WriteLine($"({++_eventId}) OnData(): {data}");
}
private async Task OnKey(KeyboardEventArgs args)
{
await _terminalEvent.WriteLine($"({++_eventId}) OnKey(): {args.Key}");
}
private async Task OnLineFeed()
{
await _terminalEvent.WriteLine($"({++_eventId}) OnLineFeed()");
}
private async Task OnScroll(int newPosition)
{
await _terminalEvent.WriteLine($"({++_eventId}) OnScroll(): newPosition: {newPosition}");
}
private async Task OnSelectionChange()
{
await _terminalEvent.WriteLine($"({++_eventId}) OnSelectionChange()");
}
private async Task OnRender(RenderEventArgs args)
{
await _terminalEvent.WriteLine($"({++_eventId}) OnRender(): {JsonSerializer.Serialize(args)}");
}
private async Task OnResize(ResizeEventArgs args)
{
await _terminalEvent.WriteLine($"({++_eventId}) OnResize(): {JsonSerializer.Serialize(args)}");
}
private async Task OnTitleChange(string title)
{
await _terminalEvent.WriteLine($"({++_eventId}) OnTitleChange(): title: {title}");
}
private async Task OnBell()
{
await _terminalEvent.WriteLine($"({++_eventId}) OnBell()");
}
private async Task Write(MouseEventArgs args)
{
await _terminal.Write(_input);
}
private async Task WriteLine(MouseEventArgs args)
{
await _terminal.WriteLine(_input);
}
private async Task HasSelection(MouseEventArgs args)
{
await _terminalEvent.WriteLine($"({++_eventId}) HasSelection(): {await _terminal.HasSelection()}");
}
private async Task GetSelection(MouseEventArgs args)
{
await _terminalEvent.WriteLine($"({++_eventId}) GetSelection(): {await _terminal.GetSelection()}");
}
private async Task GetSelectionPosition(MouseEventArgs args)
{
var selectionPosition = await _terminal.GetSelectionPosition();
await _terminalEvent.WriteLine($"({++_eventId}) GetSelectionPosition(): {JsonSerializer.Serialize(selectionPosition)}");
}
private async Task ClearSelection(MouseEventArgs args)
{
await _terminal.ClearSelection();
}
private async Task SelectAll(MouseEventArgs args)
{
await _terminal.SelectAll();
}
private async Task ScrollToTop(MouseEventArgs args)
{
await _terminal.ScrollToTop();
}
private async Task ScrollToBottom(MouseEventArgs args)
{
await _terminal.ScrollToBottom();
}
private async Task Reset(MouseEventArgs args)
{
await _terminal.Reset();
}
private async Task Resize(MouseEventArgs args)
{
await _terminal.Resize(_columns, _rows);
}
private async Task GetRows(MouseEventArgs args)
{
var rows = await _terminal.GetRows();
await _terminalEvent.WriteLine($"({++_eventId}) GetRows(): {JsonSerializer.Serialize(rows)}");
}
private async Task GetColumns(MouseEventArgs args)
{
var cols = await _terminal.GetColumns();
await _terminalEvent.WriteLine($"({++_eventId}) GetColumns(): {JsonSerializer.Serialize(cols)}");
}
}