Explorar el Código

feat(ui/prompt): 为 prompt 增加 cache,减少不必要的刷新,减少闪烁

dzp hace 1 año
padre
commit
9ea2425348
Se han modificado 1 ficheros con 9 adiciones y 0 borrados
  1. 9 0
      plugins/lib/ui/prompt.tin

+ 9 - 0
plugins/lib/ui/prompt.tin

@@ -224,6 +224,9 @@ VAR {命令输入提示符} prompt-prompt {Input};
     };
 };
 
+#nop 备份的之前的内容,只有新内容与当前正在显示的内容不同时,才会刷新。;
+#var prompt.current-content {};
+
 #nop 显示字段值;
 #alias {prompt.refresh} {
     #local topMaxLine   {0};
@@ -401,12 +404,18 @@ VAR {命令输入提示符} prompt-prompt {Input};
         #var prompt-top-max-line {$topMaxLine};
         #var prompt-bot-max-line {$botMaxLine};
         #split {$topMaxLine} {$botMaxLine};
+        #var prompt.current-content {};
         #buffer end;
     };
 
     #local idx {};
     #foreach {*content[]} {idx} {
         #local line {$content[$idx]};
+        #if { {$prompt.current-content[=$line[line]]} === {$line[text]} } {
+            #continue;
+        };
+
+        #var prompt.current-content[=$line[line]] {$line[text]};
         #echo {{%s}{$line[line]}} {$line[text]};
     };