<> <> <> <> DIRECTORY CDMenus, CDSequencer, ColorMap, ColorWorld, Commander USING [CommandProc, Register], IO, Rope, Terminal, TerminalIO, UserProfile, WindowManager; CDColorCommands: CEDAR PROGRAM IMPORTS CDMenus, CDSequencer, ColorMap, ColorWorld, Commander, IO, Rope, Terminal, TerminalIO, UserProfile, WindowManager = BEGIN virtual: Terminal.Virtual = Terminal.Current[]; SetMyColor: PROC [] = BEGIN IF virtual.hasColorDisplay AND WindowManager.colorDisplayOn THEN { m: Terminal.ColorMode = Terminal.GetColorMode[virtual]; IF m.full OR m.bitsPerPixelChannelA<4 THEN RETURN; [] _ Terminal.SetColorCursorPresentation[virtual, onesAreWhite]; ColorMap.SetRGBColor[index: 0, r:0, g:0, b:0]; -- [black] background ColorMap.SetRGBColor[index: 1, r:0, g:1, b:0]; -- [green] diff ColorMap.SetRGBColor[index: 2, r:0, g:0, b:1]; -- [blue] met ColorMap.SetRGBColor[index: 4, r:1, g:0, b:0]; -- [red] poly ColorMap.SetRGBColor[index: 8, r:0.9, g:0.9, b:0]; ColorMap.SetRGBColor[index: 3, r:0, g:0.4, b:0.7]; -- met+diff ColorMap.SetRGBColor[index: 5, r:0.8, g:0.3, b:0]; -- poly+diff ColorMap.SetRGBColor[index: 6, r:0.5, g:0, b:0.5]; -- poly+met ColorMap.SetRGBColor[index: 7, r:0.8, g:0.3, b:0.6]; -- poly+diff+met ColorMap.SetRGBColor[index: 9, r:0.9, g:0.8, b:0.9]; --nearly background ColorMap.SetRGBColor[index: 10, r:0.8, g:0.9, b:0.8]; -- nearly background ColorMap.SetRGBColor[index: 11, r:0.0, g:0.9, b:0.8]; ColorMap.SetRGBColor[index: 12, r:1, g:0.2, b:0.2]; ColorMap.SetRGBColor[index: 13, r:1, g:1, b:0.2]; ColorMap.SetRGBColor[index: 14, r:1, g:1, b:0.0]; -- [yellow] imp ColorMap.SetRGBColor[index: (IF m.bitsPerPixelChannelA=8 THEN 255 ELSE 15), r:1, g:1, b:1]; }; END; SetColorBPP: PROC [bpp: INT, pos: WindowManager.ScreenPos, force: BOOL_FALSE] = <<--force position by putting off and on again>> BEGIN m: Terminal.ColorMode = Terminal.GetColorMode[virtual]; IF bpp=4 OR bpp=8 AND ColorWorld.HasMode[bpp] THEN { IF WindowManager.colorDisplayOn THEN { IF NOT force AND NOT m.full AND m.bitsPerPixelChannelA=bpp THEN { SetMyColor[]; RETURN; }; WindowManager.StopColorViewers[]; }; WindowManager.StartColorViewers[screenPos: pos, bitsPerPixel: bpp]; }; IF bpp>=0 THEN SetMyColor[]; END; ColorMenuComm: PROC[comm: CDSequencer.Command] = BEGIN n: CARDINAL; IF NOT ColorWorld.HasMode[4] THEN { TerminalIO.WriteRope["no color display\n"]; RETURN }; n _ TerminalIO.RequestSelection[ label: "color display", choice: IF ColorWorld.HasMode[8] THEN LIST["cedar", "mycolors", "off", "Cursor white", "Cursor black", "4 bit left", "4 bit right", "8 bit left", "8 bit right"] ELSE LIST["cedar", "mycolors", "off", "Cursor-white", "Cursor black", "4 bit left", "4 bit right"] ]; SELECT n FROM 1 => CedarColorComm[NIL]; 2 => SetMyColor[]; 3 => IF WindowManager.colorDisplayOn THEN WindowManager.StopColorViewers[]; 4 => [] _ Terminal.SetColorCursorPresentation[virtual, onesAreWhite]; 5 => [] _ Terminal.SetColorCursorPresentation[virtual, onesAreBlack]; 6 => SetColorBPP[4, left, TRUE]; 7 => SetColorBPP[4, right, TRUE]; 8 => SetColorBPP[8, left, TRUE]; 9 => SetColorBPP[8, right, TRUE]; ENDCASE => TerminalIO.WriteRope["skipped\n"]; END; CedarColorComm: PROC[comm: CDSequencer.Command] = BEGIN TerminalIO.WriteRope["reset cedar colors\n"]; IF ColorWorld.HasMode[4] THEN { ColorMap.StandardMap[]; WindowManager.RestoreCursor[]; [] _ Terminal.SetColorCursorPresentation[virtual, onesAreBlack]; }; END; ColorCommand: Commander.CommandProc = BEGIN s: IO.STREAM ~ IO.RIS[cmd.commandLine]; bbp: INT _ 0; side: INT _ 0; DO token: Rope.ROPE _ IO.GetTokenRope[s ! IO.EndOfStream => EXIT].token; IF Rope.IsEmpty[token] THEN EXIT; SELECT Rope.Fetch[token, 0] FROM '4 => bbp _ 4; '8 => bbp _ 8; 'r, 'R => side _ 1; 'l, 'L => side _ -1; ENDCASE => EXIT; ENDLOOP; IF bbp>0 AND side#0 THEN SetColorBPP[bbp, IF side=1 THEN right ELSE left, TRUE] ELSE ColorMenuComm[NIL] END; <<-- Module initialization>> [] _ CDMenus.CreateMenu["Display options", $DisplayMenu]; IF ColorWorld.HasMode[4] OR ColorWorld.HasMode[8] THEN { SetColorBPP[ bpp: UserProfile.Number[key: "Chipndale.ColorStartBits", default: -1], <<-- strategy is>> <<-- -1 don't touch>> <<-- 0 take bitmode as is and initialize, if possible>> <<-- >0 do bitmode and initialize, if possible>> pos: (IF UserProfile.Boolean[key: "Chipndale.ColorStartLeft", default: TRUE] THEN left ELSE right) ]; Commander.Register[ key: "CDColor", proc: ColorCommand, doc: "Chipndale color setup" ]; CDSequencer.ImplementCommand[$ColorDisplayMenuC, ColorMenuComm,, doQueue]; CDSequencer.ImplementCommand[$CedarColorDisplay, CedarColorComm,, doQueue]; CDMenus.CreateEntry[$DisplayMenu, "cedar", $CedarColorDisplay]; CDMenus.CreateEntry[$DisplayMenu, "color-menu", $ColorDisplayMenuC]; }; END.