<> <> <> <> DIRECTORY CDSequencer, Commander USING [CommandProc, Register], ImagerTerminal, IO, PopUpSelection, Rope, Terminal, TerminalIO, UserProfile, ViewerPrivate, WindowManager; CDColorCommands: CEDAR PROGRAM IMPORTS CDSequencer, Commander, IO, ImagerTerminal, PopUpSelection, Rope, Terminal, TerminalIO, UserProfile, ViewerPrivate, WindowManager = BEGIN SetColorBPP: PROC [bpp: INT, pos: WindowManager.ScreenPos, force: BOOL_FALSE] = <<--force position by putting off and on again>> BEGIN virtual: Terminal.Virtual = Terminal.Current[]; m: Terminal.ColorMode = Terminal.GetColorMode[virtual]; IF bpp=4 OR bpp=8 AND Terminal.LegalColorMode[virtual, [full: FALSE, bitsPerPixelChannelA: bpp, bitsPerPixelChannelB: 0]] THEN { IF WindowManager.colorDisplayOn THEN { IF NOT force AND NOT m.full AND m.bitsPerPixelChannelA=bpp THEN { [] _ Terminal.SetColorCursorPresentation[virtual, onesAreWhite]; RETURN; }; WindowManager.StopColorViewers[]; }; WindowManager.StartColorViewers[screenPos: pos, bitsPerPixel: bpp]; [] _ Terminal.SetColorCursorPresentation[virtual, onesAreWhite]; }; END; ColorMenuComm: PROC[comm: CDSequencer.Command] = BEGIN n: CARDINAL; virtual: Terminal.Virtual = Terminal.Current[]; IF ~ (Terminal.LegalColorMode[virtual, [FALSE, 8, 0]] OR Terminal.LegalColorMode[virtual, [FALSE, 4, 0]]) THEN { TerminalIO.PutRope["no color display\n"]; RETURN }; n _ PopUpSelection.Request[ header: "color display", choice: IF Terminal.LegalColorMode[virtual, [FALSE, 8, 0]] THEN LIST["reset cedar", "off", "cursor white", "cursor black", "4 bit left", "4 bit right", "8 bit left", "8 bit right"] ELSE LIST["reset cedar", "off", "cursor white", "cursor black", "4 bit left", "4 bit right"] ]; SELECT n FROM 1 => ResetCedarColorsComm[NIL]; 2 => IF WindowManager.colorDisplayOn THEN WindowManager.StopColorViewers[]; 3 => [] _ Terminal.SetColorCursorPresentation[Terminal.Current[], onesAreWhite]; 4 => [] _ Terminal.SetColorCursorPresentation[Terminal.Current[], onesAreBlack]; 5 => SetColorBPP[4, left, TRUE]; 6 => SetColorBPP[4, right, TRUE]; 7 => SetColorBPP[8, left, TRUE]; 8 => SetColorBPP[8, right, TRUE]; ENDCASE => TerminalIO.PutRope["skipped\n"]; IF comm#NIL THEN TerminalIO.PutRope[" this command forced the display hardware; now set color map and pattern\n"]; END; ResetCedarColorsComm: PROC[comm: CDSequencer.Command] = BEGIN virtual: Terminal.Virtual = Terminal.Current[]; TerminalIO.PutRope["reset cedar colors\n"]; IF virtual.hasColorDisplay THEN { ImagerTerminal.SetStandardColorMap[virtual]; WindowManager.RestoreCursor[]; [] _ Terminal.SetColorCursorPresentation[virtual, onesAreBlack]; [] _ ViewerPrivate.SetCreator[NIL]; }; 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>> Init: PROC [] = BEGIN virtual: Terminal.Virtual = Terminal.Current[]; IF virtual.hasColorDisplay THEN { bpp: INT _ 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: WindowManager.ScreenPos _ left; IF Rope.Equal["right", UserProfile.Token[key: "ColorDisplay.Side"], FALSE] THEN pos _ right; SetColorBPP[bpp: bpp, pos: pos]; CDSequencer.ImplementCommand[$DisplaySetColors, ColorMenuComm,, doQueue]; CDSequencer.ImplementCommand[$DisplayResetCedar, ResetCedarColorsComm,, doQueue]; Commander.Register[ key: "///Commands/CDColor", proc: ColorCommand, doc: "ChipNDale color setup" ]; }; END; Init[]; END.