瀏覽代碼

+ added 256 color support to the Unix console video unit

Nikolay Nikolov 3 年之前
父節點
當前提交
3564d5e34a
共有 2 個文件被更改,包括 82 次插入32 次删除
  1. 52 32
      packages/rtl-console/src/unix/video.pp
  2. 30 0
      packages/rtl-console/tests/video3.pp

+ 52 - 32
packages/rtl-console/src/unix/video.pp

@@ -366,45 +366,65 @@ end;
 const  ansitbl:array[0..7] of char='04261537';
 
 function attr2ansi(Fg,Bg,OFg,OBg:byte):string;
+var
+  tmpS: string;
 begin
   attr2ansi:=#27'[';
-  if TerminalSupportsBold then
-    if fg and 8<>0 then
-      begin
-        {Enable bold if not yet on.}
-        if ofg and 8=0 then
-          attr2ansi:=attr2ansi+'1;';
-      end
-    else
-      {Disable bold if on.}
-      if ofg and 8<>0 then
-        attr2ansi:=attr2ansi+'22;';
-  if bg and 8<>0 then
+  if (Fg > 15) or (Bg > 15) then
     begin
-      {Enable bold if not yet on.}
-      if obg and 8=0 then
-        attr2ansi:=attr2ansi+'5;';
+      if Fg<>OFg then
+        begin
+          if TerminalSupportsBold and (ofg and 8<>0) then
+            attr2ansi:=attr2ansi+'22;';
+          Str(Fg,tmpS);
+          attr2ansi:=attr2ansi+'38:5:'+tmpS+';';
+        end;
+      if Bg<>OBg then
+        begin
+          Str(Bg,tmpS);
+          attr2ansi:=attr2ansi+'48:5:'+tmpS+';';
+        end;
     end
   else
-    {Disable bold if on.}
-    if obg and 8<>0 then
-      attr2ansi:=attr2ansi+'25;';
+    begin
+      if TerminalSupportsBold then
+        if fg and 8<>0 then
+          begin
+            {Enable bold if not yet on.}
+            if ofg and 8=0 then
+              attr2ansi:=attr2ansi+'1;';
+          end
+        else
+          {Disable bold if on.}
+          if ofg and 8<>0 then
+            attr2ansi:=attr2ansi+'22;';
+      if bg and 8<>0 then
+        begin
+          {Enable bold if not yet on.}
+          if obg and 8=0 then
+            attr2ansi:=attr2ansi+'5;';
+        end
+      else
+        {Disable bold if on.}
+        if obg and 8<>0 then
+          attr2ansi:=attr2ansi+'25;';
 
-  if TerminalSupportsHighIntensityColors then
-  begin
-    if fg and 15<>ofg and 15 then
-      if fg and 8<>0 then
-        attr2ansi:=attr2ansi+'9'+ansitbl[fg and 7]+';'
+      if TerminalSupportsHighIntensityColors then
+      begin
+        if fg and 15<>ofg and 15 then
+          if fg and 8<>0 then
+            attr2ansi:=attr2ansi+'9'+ansitbl[fg and 7]+';'
+          else
+            attr2ansi:=attr2ansi+'3'+ansitbl[fg and 7]+';';
+      end
       else
-        attr2ansi:=attr2ansi+'3'+ansitbl[fg and 7]+';';
-  end
-  else
-  begin
-    if fg and 7<>ofg and 7 then
-      attr2ansi:=attr2ansi+'3'+ansitbl[fg and 7]+';';
-  end;
-  if bg and 7<>obg and 7 then
-     attr2ansi:=attr2ansi+'4'+ansitbl[bg and 7]+';';
+      begin
+        if fg and 7<>ofg and 7 then
+          attr2ansi:=attr2ansi+'3'+ansitbl[fg and 7]+';';
+      end;
+      if bg and 7<>obg and 7 then
+         attr2ansi:=attr2ansi+'4'+ansitbl[bg and 7]+';';
+    end;
 
   if attr2ansi[length(attr2ansi)]=';' then
     attr2ansi[length(attr2ansi)]:='m'

+ 30 - 0
packages/rtl-console/tests/video3.pp

@@ -0,0 +1,30 @@
+{ test for the 256-color support }
+program video3;
+
+uses
+  video, keyboard;
+
+var
+  k: TKeyEvent;
+  X, Y: Integer;
+begin
+  InitKeyboard;
+  InitEnhancedVideo;
+  repeat
+    for X := 0 to ScreenWidth - 1 do
+      for Y := 0 to ScreenHeight - 1 do
+        with EnhancedVideoBuf[Y * ScreenWidth + X] do
+        begin
+          ForegroundColor := Byte(X + Y);
+          BackgroundColor := ForegroundColor xor 255;
+          ExtendedGraphemeCluster := 'A';
+        end;
+    UpdateScreen(False);
+
+    k := GetKeyEvent;
+    k := TranslateKeyEvent(k);
+  until GetKeyEventChar(k) = 'q';
+  DoneEnhancedVideo;
+  DoneKeyboard;
+end.
+