From da0807d3693c490992b80a9ab965cbc56b4c7d5c Mon Sep 17 00:00:00 2001 From: norayr Date: Sun, 13 Apr 2014 21:04:37 +0400 Subject: [PATCH] module crt almost completed, crttest for reference Former-commit-id: 4943886b6436a439a0250f4591114cd908262069 --- src/test/vt100/Makefile | 2 +- src/test/vt100/crt.Mod | 151 ++++++++++++++++++++++++++++++++++--- src/test/vt100/crttest.Mod | 57 ++++++++++++++ src/test/vt100/vt100.Mod | 77 ++++++++++++++----- 4 files changed, 257 insertions(+), 30 deletions(-) create mode 100644 src/test/vt100/crttest.Mod diff --git a/src/test/vt100/Makefile b/src/test/vt100/Makefile index 4b99a8c4..37546ecb 100644 --- a/src/test/vt100/Makefile +++ b/src/test/vt100/Makefile @@ -2,7 +2,7 @@ VOC = /opt/voc/bin/voc all: - $(VOC) -s vt100.Mod crt.Mod -M + $(VOC) -s vt100.Mod crt.Mod crttest.Mod -M clean: rm *.h diff --git a/src/test/vt100/crt.Mod b/src/test/vt100/crt.Mod index d2b298f2..80b01883 100644 --- a/src/test/vt100/crt.Mod +++ b/src/test/vt100/crt.Mod @@ -3,6 +3,31 @@ MODULE crt; IMPORT vt100, Unix, Console, Strings; (* strings to remove later ? *) +CONST + +(* Foreground and background color constants *) + Black* = 0; + Blue* = 1; + Green* = 2; + Cyan* = 3; + Red* = 4; + Magenta* = 5; + Brown* = 6; + LightGray* = 7; + +(* Foreground color constants *) + DarkGray* = 8; + LightBlue* = 9; + LightGreen* = 10; + LightCyan* = 11; + LightRed* = 12; + LightMagenta* = 13; + Yellow* = 14; + White* = 15; + +(* Add-in for blinking *) + Blink* = 128; + TYPE PFdSet = POINTER TO Unix.FdSet; @@ -44,21 +69,127 @@ VAR tmpstr : ARRAY 23 OF CHAR; i := Unix.Select(0, pfd^, pfd^, pfd^, tv); END Delay; - PROCEDURE GotoXY* (x, y: INTEGER); BEGIN vt100.CUP (y, x); END GotoXY; -BEGIN -(* test *) - EraseDisplay; - GotoXY (0, 0); - COPY(vt100.CSI, tmpstr); - Strings.Append(vt100.Green, tmpstr); - Strings.Append("hello", tmpstr); - Console.String(tmpstr); Console.Ln; - Delay (2000); + PROCEDURE HighVideo*; + VAR tmpstr: ARRAY 5 OF CHAR; + BEGIN + COPY (vt100.CSI, tmpstr); + Strings.Append(vt100.Bold, tmpstr); + Console.String(tmpstr); + END HighVideo; + + PROCEDURE DelLine*; + BEGIN + vt100.EL(2); + END DelLine; + PROCEDURE InsLine*; + BEGIN + vt100.SCP; + Console.Ln; + vt100.RCP; + END InsLine; + + PROCEDURE LowVideo*; + VAR tmpstr : ARRAY 7 OF CHAR; + BEGIN + COPY (vt100.CSI, tmpstr); + Strings.Append(vt100.ResetBold, tmpstr); + Console.String(tmpstr); + END LowVideo; + + PROCEDURE NormVideo*; + VAR tmpstr : ARRAY 7 OF CHAR; + BEGIN + COPY(vt100.CSI, tmpstr); + Strings.Append(vt100.ResetAll, tmpstr); + Console.String(tmpstr); + END NormVideo; + + PROCEDURE SetAttr(attr : ARRAY OF CHAR); + VAR tmpstr : ARRAY 16 OF CHAR; + BEGIN + COPY(vt100.CSI, tmpstr); + Strings.Append(attr, tmpstr); + Console.String(tmpstr); + END SetAttr; + + PROCEDURE TextBackground*(color : SHORTINT); + BEGIN + IF color = Black THEN + SetAttr(vt100.BBlack) + ELSIF color = Blue THEN + SetAttr(vt100.BBlue) + ELSIF color = Green THEN + SetAttr(vt100.BGreen) + ELSIF color = Cyan THEN + SetAttr(vt100.BCyan) + ELSIF color = Red THEN + SetAttr(vt100.BRed) + ELSIF color = Magenta THEN + SetAttr(vt100.BMagenta) + ELSIF color = Brown THEN + SetAttr(vt100.BYellow) + ELSIF color = LightGray THEN + SetAttr(vt100.BLightGray) + ELSIF color = DarkGray THEN + SetAttr(vt100.BDarkGray) + ELSIF color = LightBlue THEN + SetAttr(vt100.BLightBlue) + ELSIF color = LightGreen THEN + SetAttr(vt100.BLightBlue) + ELSIF color = LightCyan THEN + SetAttr(vt100.BLightCyan) + ELSIF color = LightRed THEN + SetAttr(vt100.BLightRed) + ELSIF color = LightMagenta THEN + SetAttr(vt100.BLightMagenta) + ELSIF color = Yellow THEN + SetAttr(vt100.BLightYellow) + ELSIF color = White THEN + SetAttr(vt100.BWhite) + END; + END TextBackground; + + PROCEDURE TextColor*(color : SHORTINT); + BEGIN + IF color = Black THEN + SetAttr(vt100.Black) + ELSIF color = Blue THEN + SetAttr(vt100.Blue) + ELSIF color = Green THEN + SetAttr(vt100.Green) + ELSIF color = Cyan THEN + SetAttr(vt100.Cyan) + ELSIF color = Red THEN + SetAttr(vt100.Red) + ELSIF color = Magenta THEN + SetAttr(vt100.Magenta) + ELSIF color = Brown THEN + SetAttr(vt100.Yellow) + ELSIF color = LightGray THEN + SetAttr(vt100.LightGray) + ELSIF color = DarkGray THEN + SetAttr(vt100.DarkGray) + ELSIF color = LightBlue THEN + SetAttr(vt100.LightBlue) + ELSIF color = LightGreen THEN + SetAttr(vt100.LightBlue) + ELSIF color = LightCyan THEN + SetAttr(vt100.LightCyan) + ELSIF color = LightRed THEN + SetAttr(vt100.LightRed) + ELSIF color = LightMagenta THEN + SetAttr(vt100.LightMagenta) + ELSIF color = Yellow THEN + SetAttr(vt100.LightYellow) + ELSIF color = White THEN + SetAttr(vt100.White) + END; + END TextColor; END crt. diff --git a/src/test/vt100/crttest.Mod b/src/test/vt100/crttest.Mod new file mode 100644 index 00000000..39a10f98 --- /dev/null +++ b/src/test/vt100/crttest.Mod @@ -0,0 +1,57 @@ +MODULE crttest; + +IMPORT crt, vt100, Console, Strings; + + +VAR tmpstr : ARRAY 32 OF CHAR; +BEGIN +(* test *) + crt.EraseDisplay; + crt.GotoXY (0, 0); + + COPY(vt100.CSI, tmpstr); + Strings.Append(vt100.Yellow, tmpstr); + (*Strings.Append(vt100.CSI, tmpstr); + Strings.Append(vt100.BBlue, tmpstr);*) + Strings.Append(vt100.CSI, tmpstr); + Strings.Append(vt100.Blink, tmpstr); + Strings.Append("hello", tmpstr); + Strings.Append(vt100.CSI, tmpstr); + Strings.Append(vt100.ResetAll, tmpstr); + Console.String(tmpstr); Console.Ln; + Console.Ln; + + COPY(vt100.CSI, tmpstr); + Strings.Append (vt100.BRed, tmpstr); + Strings.Append (" ", tmpstr); + Console.String (tmpstr); Console.Ln; + + COPY(vt100.CSI, tmpstr); + Strings.Append (vt100.BBlue, tmpstr); + Strings.Append (" ", tmpstr); + Console.String (tmpstr); Console.Ln; + + COPY(vt100.CSI, tmpstr); + Strings.Append (vt100.BYellow, tmpstr); + Strings.Append (" ", tmpstr); + Console.String (tmpstr); Console.Ln; + + COPY(vt100.CSI, tmpstr); + Strings.Append(vt100.ResetAll, tmpstr); + Console.String(tmpstr); Console.Ln; + + crt.HighVideo; + Console.String("high video"); Console.Ln; + Console.Ln; + crt.LowVideo; + Console.String("low video"); Console.Ln; + + crt.TextColor(crt.Red); Console.String("red"); Console.Ln; + crt.TextColor(crt.Green); Console.String("green"); Console.Ln; + crt.TextBackground(crt.Yellow); crt.TextColor(crt.Blue); Console.String("blue on yellow"); Console.Ln; + + Console.Ln; Console.Ln; + crt.Delay (2000); + + +END crttest. diff --git a/src/test/vt100/vt100.Mod b/src/test/vt100/vt100.Mod index 8224579e..846349f5 100644 --- a/src/test/vt100/vt100.Mod +++ b/src/test/vt100/vt100.Mod @@ -1,30 +1,69 @@ MODULE vt100; IMPORT Console, Strings, IntStr := oocIntStr; - (* reference http://en.wikipedia.org/wiki/ANSI_escape_code *) + (* reference http://en.wikipedia.org/wiki/ANSI_escape_code + & http://misc.flogisoft.com/bash/tip_colors_and_formatting + *) CONST Escape* = 1BX; - SynchronousIdle = 16X; + SynchronousIdle* = 16X; LeftCrotchet* = '['; - (* colors *) - Black* = "22;30m"; - Red* = "22;31m"; - Green* = "22;32m"; - Brown* = "22;33m"; - Blue* = "22;34m"; - Magenta* = "22;35m"; - Cyan* = "22;36m"; - Gray* = "22;37m"; - DarkGray* = "01;30m"; - LightRed* = "01;31m"; - LightGreen* = "01;32m"; - Yellow* = "01;33m"; - LightBlue* = "01;34m"; - LightMagenta* = "01;35m"; - LightCyan* = "01;36m"; - White* = "01;37m"; + (* formatting *) + Bold* = "1m"; + Dim* = "2m"; + Underlined* = "4m"; + Blink* = "5m"; (* does not work with most emulators, works in tty and xterm *) + Reverse* = "7m"; (* invert the foreground and background colors *) + Hidden* = "8m"; (* useful for passwords *) + + (* reset *) + ResetAll* = "0m"; + ResetBold* = "21m"; + ResetDim* = "22m"; + ResetUnderlined* = "24m"; + ResetBlink* = "25m"; + ResetReverse* = "27m"; + ResetHidden* = "28m"; + + (* foreground colors *) + Black* = "30m"; + Red* = "31m"; + Green* = "32m"; + Yellow* = "33m"; + Blue* = "34m"; + Magenta* = "35m"; + Cyan* = "36m"; + LightGray* = "37m"; + Default* = "39m"; + DarkGray* = "90m"; + LightRed* = "91m"; + LightGreen* = "92m"; + LightYellow* = "93m"; + LightBlue* = "94m"; + LightMagenta* = "95m"; + LightCyan* = "96m"; + White* = "97m"; + + (* background colors *) + BBlack* = "40m"; + BRed* = "41m"; + BGreen* = "42m"; + BYellow* = "43m"; + BBlue* = "44m"; + BMagenta* = "45m"; + BCyan* = "46m"; + BLightGray* = "47m"; + BDefault* = "49m"; + BDarkGray* = "100m"; + BLightRed* = "101m"; + BLightGreen* = "102m"; + BLightYellow* = "103m"; + BLightBlue* = "104m"; + BLightMagenta*= "105m"; + BLightCyan* = "106m"; + BWhite* = "107m"; VAR CSI* : ARRAY 5 OF CHAR;