Skip to content

Commit 56ff312

Browse files
j4587698ArgoZhang
andauthored
feat(Term): add Term component (#7549)
* doc: 更新参数表格 * Please provide the file changes to generate a commit message. * Revert "Please provide the file changes to generate a commit message." This reverts commit aa97c6b. * Reapply "Please provide the file changes to generate a commit message." This reverts commit 50376ff. * refactor: 更新多语言 * doc: 更新资源文件 * test: 更新单元测试 * test: 增加文件尾部新行 * feat: 增加支持是否为组件参数 * doc: 使用新方法自动生成参数说明 * doc: 更新注释 * doc: 删除冗余多语言配置 * doc: 调整列宽 * refactor: 重构资源文件检查单元测试 * feat: add BootstrapBlazor.Term sample page and menu integration * chore: 增加 term 路由配置信息 * doc: 更新示例 * doc: 更新项目依赖 * wip: 临时提交 * doc: 更新示例文档 * chore: 增加依赖 --------- Co-authored-by: Argo Zhang <argo@live.ca>
1 parent e79aede commit 56ff312

7 files changed

Lines changed: 157 additions & 1 deletion

File tree

src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
<PackageReference Include="BootstrapBlazor.SummerNote" Version="10.0.2" />
7878
<PackageReference Include="BootstrapBlazor.TableExport" Version="10.0.1" />
7979
<PackageReference Include="BootstrapBlazor.Tasks.Dashboard" Version="10.0.0" />
80+
<PackageReference Include="BootstrapBlazor.Term" Version="10.0.0" />
8081
<PackageReference Include="BootstrapBlazor.Topology" Version="10.0.0" />
8182
<PackageReference Include="BootstrapBlazor.UniverIcon" Version="10.0.0" />
8283
<PackageReference Include="BootstrapBlazor.UniverSheet" Version="10.0.8" />
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@page "/term"
2+
@using Microsoft.AspNetCore.Components.Sections
3+
@inject IStringLocalizer<Terms> Localizer
4+
5+
<h3>@Localizer["Title"]</h3>
6+
<h4>@Localizer["SubTitle"]</h4>
7+
8+
<Tips>
9+
<p>@((MarkupString)Localizer["Tips"].Value)</p>
10+
</Tips>
11+
12+
<DemoBlock Title="@Localizer["BasicUsageTitle"]" Introduction="@Localizer["BasicUsageIntro"]" Name="Normal">
13+
<section ignore>
14+
<div>@((MarkupString)Localizer["TermDesc"].Value)</div>
15+
</section>
16+
<Term @ref="_term" OnReceivedAsync="OnReceivedAsync" />
17+
<section ignore>
18+
<div class="col-12">
19+
<Button OnClickWithoutRender="OnCheck">@Localizer["CheckText"]</Button>
20+
<Button OnClickWithoutRender="OnTest">@Localizer["TestText"]</Button>
21+
<Button OnClickWithoutRender="OnClean">@Localizer["CleanText"]</Button>
22+
</div>
23+
</section>
24+
</DemoBlock>
25+
26+
<DemoBlock Title="@Localizer["StreamUsageTitle"]" Introduction="@Localizer["StreamUsageIntro"]" Name="Stream">
27+
<Term @ref="_termStream" />
28+
</DemoBlock>
29+
30+
<AttributeTable Type="typeof(Term)"></AttributeTable>
31+
32+
<AttributeTable Type="typeof(TermOptions)"></AttributeTable>
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
using System.Text;
2+
3+
namespace BootstrapBlazor.Server.Components.Samples;
4+
5+
/// <summary>
6+
/// Term 示例
7+
/// </summary>
8+
public partial class Terms : IDisposable
9+
{
10+
private Term _term = default!;
11+
private Term _termStream = default!;
12+
private MemoryStream _ms = new MemoryStream();
13+
private CancellationTokenSource? _cancellationTokenSource;
14+
15+
private async Task OnReceivedAsync(byte[] data)
16+
{
17+
var str = System.Text.Encoding.UTF8.GetString(data);
18+
await _term.Write(str.Replace("\r", "\r\n"));
19+
}
20+
21+
private async Task OnCheck()
22+
{
23+
await _term.WriteLine($"Check\r\n{DateTime.Now}");
24+
}
25+
26+
private async Task OnTest()
27+
{
28+
await _term.WriteLine($"Test\r\n{DateTime.Now}");
29+
}
30+
31+
private async Task OnClean()
32+
{
33+
await _term.Clear();
34+
}
35+
36+
/// <summary>
37+
/// <inheritdoc/>
38+
/// </summary>
39+
/// <param name="firstRender"></param>
40+
protected override async Task OnAfterRenderAsync(bool firstRender)
41+
{
42+
if (firstRender)
43+
{
44+
await _termStream.Open(_ms);
45+
46+
_ = Task.Run(async () =>
47+
{
48+
_cancellationTokenSource ??= new();
49+
while (_cancellationTokenSource is { IsCancellationRequested: false })
50+
{
51+
try
52+
{
53+
// 模拟流内数据变化
54+
_ms.SetLength(0);
55+
await _ms.WriteAsync(Encoding.UTF8.GetBytes($"{DateTime.Now}\r\n"), _cancellationTokenSource.Token);
56+
_ms.Seek(0, SeekOrigin.Begin);
57+
await Task.Delay(2000);
58+
}
59+
catch { }
60+
}
61+
});
62+
}
63+
}
64+
65+
private void Dispose(bool disposing)
66+
{
67+
if (disposing)
68+
{
69+
if (_cancellationTokenSource is { IsCancellationRequested: false })
70+
{
71+
_cancellationTokenSource.Cancel();
72+
_cancellationTokenSource.Dispose();
73+
_cancellationTokenSource = null;
74+
}
75+
76+
_ms.Close();
77+
_ms.Dispose();
78+
}
79+
}
80+
81+
/// <summary>
82+
/// <inheritdoc/>
83+
/// </summary>
84+
public void Dispose()
85+
{
86+
Dispose(true);
87+
GC.SuppressFinalize(this);
88+
}
89+
}

src/BootstrapBlazor.Server/Extensions/MenusLocalizerExtensions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,11 @@ void AddNotice(DemoMenuItem item)
14061406
Url = "sweet-alert"
14071407
},
14081408
new()
1409+
{
1410+
Text = Localizer["Terms"],
1411+
Url = "term"
1412+
},
1413+
new()
14091414
{
14101415
Text = Localizer["Timer"],
14111416
Url = "timer"

src/BootstrapBlazor.Server/Locales/en-US.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@
428428
"Tag": "Tag",
429429
"TaskDashBoard": "TaskDashBoard",
430430
"TcpSocketFactory": "ITcpSocketFactory",
431+
"Terms": "Terminal",
431432
"Textarea": "Textarea",
432433
"Theme": "Theme",
433434
"ThemeProvider": "IThemeProvider",
@@ -5306,6 +5307,19 @@
53065307
"TaskBoardNormalTitle": "Basic usage",
53075308
"TaskBoardTitle": "Task DashBoard"
53085309
},
5310+
"BootstrapBlazor.Server.Components.Samples.Terms": {
5311+
"BasicUsageIntro": "Output text by calling the <code>Write</code> method",
5312+
"BasicUsageTitle": "Basic Usage",
5313+
"CheckText": "Check",
5314+
"CleanText": "Clean",
5315+
"StreamUsageIntro": "Connect various streams by calling the <code>Open</code> method, this example simulates <b>Shell</b> and verifies input characters",
5316+
"StreamUsageTitle": "Stream Usage",
5317+
"SubTitle": "Terminal Component",
5318+
"TermDesc": "The <code>Term</code> component is a terminal component that establishes a connection with the stream via <code>C#</code> code. The <code>Term</code> component is then responsible for displaying interactive content. In this example, after establishing a connection with a simulated <code>Stream</code> instance in the backend, data is automatically displayed within the component when it is written. When the user enters a command within the component and presses Enter, the backend processes it and displays the result in the component.",
5319+
"TestText": "Test",
5320+
"Tips": "This component depends on the <code>BootstrapBlazor.Term</code> extension package. You need to reference it as follows",
5321+
"Title": "Terminal"
5322+
},
53095323
"BootstrapBlazor.Server.Components.Samples.TextAreas": {
53105324
"TextAreaAutoScroll": "Automatic scrolling",
53115325
"TextAreaBindWayBindValue": "The binding value",

src/BootstrapBlazor.Server/Locales/zh-CN.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@
428428
"Tag": "标签 Tag",
429429
"TaskDashBoard": "任务管理器 TaskDashBoard",
430430
"TcpSocketFactory": "套接字服务 ITcpSocketFactory",
431+
"Terms": "终端 Terminal",
431432
"Textarea": "多行文本框 Textarea",
432433
"Theme": "组件主题",
433434
"ThemeProvider": "主题服务 IThemeProvider",
@@ -5306,6 +5307,19 @@
53065307
"TaskBoardNormalTitle": "基本用法",
53075308
"TaskBoardTitle": "Task DashBoard 任务管理器"
53085309
},
5310+
"BootstrapBlazor.Server.Components.Samples.Terms": {
5311+
"BasicUsageIntro": "通过调用 <code>Write</code> 方法输出文本",
5312+
"BasicUsageTitle": "基础用法",
5313+
"CheckText": "查询命令(Check)",
5314+
"CleanText": "清空",
5315+
"StreamUsageIntro": "通过调用 <code>Open</code> 方法连接各种流,本例模拟 <b>Shell</b> 并回显输入字符",
5316+
"StreamUsageTitle": "流式处理",
5317+
"SubTitle": "命令行终端显示组件",
5318+
"TermDesc": "<code>Term</code> 组件是一个终端组件,通过 <code>C#</code> 代码与流建立联系,然后组件 <code>Term</code> 负责显示交互内容;本例中,与后台一个模拟 <code>Stream</code> 实例建立联系后,当有数据写入时自动显示在组件内,用户在组件内录入命令回车后,由后端处理回显在组件中",
5319+
"TestText": "测试命令 (Test)",
5320+
"Tips": "本组件依赖 <code>BootstrapBlazor.Term</code> 扩展包,需要依照下面步骤进行引用",
5321+
"Title": "Term 命令行"
5322+
},
53095323
"BootstrapBlazor.Server.Components.Samples.TextAreas": {
53105324
"TextAreaAutoScroll": "自动滚屏",
53115325
"TextAreaBindWayBindValue": "绑定值",

src/BootstrapBlazor.Server/docs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@
260260
"select-city": "SelectCities",
261261
"select-province": "SelectProvinces",
262262
"hik-vision": "HikVisions",
263-
"embed-pdf": "EmbedPDFs"
263+
"embed-pdf": "EmbedPDFs",
264+
"term": "Terms"
264265
},
265266
"video": {
266267
"table": "BV1ap4y1x7Qn?p=1",

0 commit comments

Comments
 (0)