Просмотр исходного кода

feat(event): 削减对 #event 的调用,全面切换至 ttevent

dzp 1 год назад
Родитель
Сommit
c85a487c52

+ 15 - 14
framework/log.tin

@@ -95,7 +95,18 @@ PaoTin++ © 2020~2023 的所有版权均由担子炮(dzp <danzipao@gmail.com>) 
     };
 };
 
-#event {RECEIVED INPUT} {
+#alias {log.Open} {
+    #if { "$gLog[initialled]" != "true" } {#return};
+    #config {LOG} {RAW};
+    #config {LOG LEVEL} {HIGH};
+    #log timestamp {%Y-%m-%d %H:%M:%S };
+    #log append {$gLog[PATH]/$gLog[buffer]};
+    ttevent.Handle {RECEIVED INPUT} {log} {framework/log} {log.input};
+    ttevent.Handle {RECEIVED LINE}  {log} {framework/log} {mudLog $gTTEventArgZero};
+    ttevent.Handle {SEND OUTPUT}    {log} {framework/log} {log.sendLog};
+};
+
+#alias {log.input} {
     #if { "$gLog[initialled]" != "true" } {#return};
 
     #local needEcho {false};
@@ -104,7 +115,7 @@ PaoTin++ © 2020~2023 的所有版权均由担子炮(dzp <danzipao@gmail.com>) 
         #local needEcho {true};
     };
     #else {
-        #line sub escape #var tmp {%0};
+        #line sub escape #var tmp {$gTTEventArgZero};
         #local cmds {};
         #list cmds create {$tmp};
         #if { &cmds[] > 1 } {
@@ -113,24 +124,14 @@ PaoTin++ © 2020~2023 的所有版权均由担子炮(dzp <danzipao@gmail.com>) 
     };
 
     #if { "$needEcho" == "true" } {
-        #local input {%0};
+        #local input {$gTTEventArgZero};
         #replace input {<} {\<};
         #echo {<029>%t INPUT: <429>%s<099>} {%Y-%m-%d %H:%M:%S} {$input};
     };
 };
 
-#alias {log.Open} {
-    #if { "$gLog[initialled]" != "true" } {#return};
-    #config {LOG} {RAW};
-    #config {LOG LEVEL} {HIGH};
-    #log timestamp {%Y-%m-%d %H:%M:%S };
-    #log append {$gLog[PATH]/$gLog[buffer]};
-    #event {RECEIVED LINE}  {mudLog %%0};
-    #event {SEND OUTPUT}    {log.sendLog %%0};
-};
-
 #alias {log.sendLog} {
-    #local text {%0};
+    #local text {$gTTEventArgZero};
     #replace text {<} {\<};
     #format text {<029>SEND: <429>%p<099>} {$text};
     mudLog $text;

+ 5 - 3
framework/main.tin

@@ -14,7 +14,7 @@ PaoTin++ © 2020~2023 的所有版权均由担子炮(dzp <danzipao@gmail.com>) 
 
 #kill all;
 
-#event {PROGRAM START} {
+#line oneshot #event {PROGRAM START} {
     #if { "$user[manual]" == "true" } {
         #var user[id]       {};
         #var user[name]     {};
@@ -43,7 +43,7 @@ PaoTin++ © 2020~2023 的所有版权均由担子炮(dzp <danzipao@gmail.com>) 
     auto-login;
 };
 
-#event {PROGRAM TERMINATION} {
+#line oneshot #event {PROGRAM TERMINATION} {
     #screen set title {NONE};
 };
 
@@ -62,7 +62,6 @@ PaoTin++ © 2020~2023 的所有版权均由担子炮(dzp <danzipao@gmail.com>) 
 
     #%0 {
         log.Open;
-        load-module lib/event;
         event.Define {user-online} {无参} {framework} {已经登录到服务器,所有命令都可以正常使用了。};
         load-module lib/ui;
         #if { "$user[manual]" != "true" } {
@@ -187,6 +186,9 @@ PaoTin++ © 2020~2023 的所有版权均由担子炮(dzp <danzipao@gmail.com>) 
     #nop 一些预置的常量;
     load-lib constant;
 
+    #nop 事件驱动编程框架;
+    load-module lib/event;
+
     #nop 提供 TinTin++ 命令行自动补全功能。;
     load-lib tab-completion;
 

+ 1 - 1
framework/online.tin

@@ -29,7 +29,7 @@ event.Emit user-online;
 #nop 提供给用户的自动执行函数;
 user-online;
 
-#event {RECEIVED OUTPUT} {
+ttevent.Handle {RECEIVED OUTPUT} {online.KeepAlive} {framework/online} {
     #undelay online.WatchDog;
     #delay online.WatchDog {#zap} 180;
 };

+ 2 - 2
plugins/lib/alert.tin

@@ -128,7 +128,7 @@ load-lib storage;
     #if { &alert-items[] == 0 } {
         #var alert-focus {0};
         #undelay alert.check;
-        #unevent {RECEIVED KEYPRESS};
+        ttevent.UnHandle {RECEIVED KEYPRESS} {alert.perform};
         prompt.Set {{alert}{}};
         #return;
     };
@@ -139,7 +139,7 @@ load-lib storage;
     #local interval {$alert-items[1][interval]};
     xtt.Tick alert.beep {alert.beep} $interval;
 
-    #event {RECEIVED KEYPRESS} {#var alert-focus {@time.Now{}}};
+    ttevent.Handle {RECEIVED KEYPRESS} {alert.perform} {lib/alert} {#var alert-focus {@time.Now{}}};
 
     #list alert-items indexate {begin};
     #list alert-items order;

+ 7 - 5
plugins/lib/ga.tin

@@ -22,6 +22,9 @@ PaoTin++ © 2020~2023 的所有版权均由担子炮(dzp <danzipao@gmail.com>) 
     #list gXttPipeLine create {};
     #class data/lib/ga close;
 
+    ttevent.Handle {SENT OUTPUT}        {lib/ga} {lib/ga} {ga.send-output};
+    ttevent.Handle {RECEIVED PROMPT}    {lib/ga} {lib/ga} {ga.received-prompt};
+
     #return true;
 };
 
@@ -30,17 +33,16 @@ load-lib event;
 
 event.Define {GA} {有参} {$MODULE} {接收到 IAC GA 时发射本事件,参数为造成本次输出的命令};
 
-#event {SENT OUTPUT} {
-    #local cmd {%0};
+#alias {ga.send-output} {
+    #local cmd {$gTTEventArgZero};
     #replace cmd {{$TELNET[CR]?}$TELNET[LF]} {};
     #if { "$cmd" != "" } {
         #list gXttPipeLine add {$cmd};
     };
 };
 
-#event {RECEIVED PROMPT} {
-    #local rawLine  {%0};
-    #local line     {%1};
+#alias {ga.received-prompt} {
+    #local line     {$gTTEventArgv[1]};
     #if { "$line" == "== 未完继续 %*== (%*继续下一页%*)%*" } {
         #line gag;
         #cr;

+ 2 - 3
plugins/lib/tab-completion.tin

@@ -6,9 +6,7 @@ PaoTin++ © 2020~2023 的所有版权均由担子炮(dzp <danzipao@gmail.com>) 
 你可以在遵照 GPLv3 协议的基础之上使用、修改及重新分发本程序。
 */
 
-#event {READ FILE} {
-    refresh-tab-completion;
-};
+ttevent.Handle {READ FILE} {refresh-tab-completion} {lib/tab-completion} {refresh-tab-completion};
 
 #alias {refresh-tab-completion} {
     #info {ALIASES} save;
@@ -32,6 +30,7 @@ PaoTin++ © 2020~2023 的所有版权均由担子炮(dzp <danzipao@gmail.com>) 
             #continue;
         };
     };
+    #unvar info[ALIASES];
 };
 
 #tab #action;

+ 2 - 1
plugins/lib/ui/prompt.tin

@@ -153,6 +153,7 @@ VAR {命令输入提示符} prompt-prompt {Input};
     prompt.Set {};
     prompt.bindKey;
     prompt.Enable;
+    ttevent.Handle {SCREEN RESIZE} {prompt} {lib/ui} {prompt.resize};
 
     #return true;
 };
@@ -592,7 +593,7 @@ VAR {命令输入提示符} prompt-prompt {Input};
     };
 };
 
-#event {SCREEN RESIZE} {
+#alias {prompt.resize} {
     #var prompt-top-max-line {0};
     #var prompt-bot-max-line {0};
     #var prompt-screen-width {0};