feat: add differential renderer

- track previous rendered lines and terminal size

- redraw only changed rows after the initial full render

- expose redraw counters in the example
This commit is contained in:
chuan
2026-06-03 22:19:47 +08:00
parent 7103f8acc0
commit 9ec681b724
2 changed files with 108 additions and 3 deletions
+5 -3
View File
@@ -11,10 +11,10 @@ using var terminalInput = new ConsoleTerminalInput();
var terminalOutput = new ConsoleTerminalOutput();
var parser = new DefaultInputParser();
var textMeasurer = new TerminalTextMeasurer();
var renderer = new FullScreenRenderer(terminalOutput, textMeasurer);
var renderer = new DifferentialRenderer(terminalOutput, textMeasurer);
using var runtime = new TuiRuntime(terminalInput, parser, renderer);
var component = new EchoComponent(runtime, textMeasurer);
var component = new EchoComponent(runtime, textMeasurer, renderer);
runtime.Add(component);
runtime.SetFocus(component);
@@ -36,7 +36,7 @@ finally
/// <summary>
/// 用于手动验证 Runtime 的示例组件
/// </summary>
file sealed class EchoComponent(ITuiRuntime runtime, ITextMeasurer textMeasurer) : IInputComponent
file sealed class EchoComponent(ITuiRuntime runtime, ITextMeasurer textMeasurer, DifferentialRenderer renderer) : IInputComponent
{
private readonly ManualResetEventSlim _done = new();
private readonly List<string> _events = [];
@@ -49,6 +49,8 @@ file sealed class EchoComponent(ITuiRuntime runtime, ITextMeasurer textMeasurer)
"TinyTUI Runtime 示例",
"====================",
$"当前渲染宽度: {width}",
$"全量重绘次数: {renderer.FullRedrawCount}",
$"差分重绘次数: {renderer.DifferentialRedrawCount}",
string.Empty,
"测试方式:",
"- 输入普通字符 验证 Text 事件会进入焦点组件",