DIRECTORY Ascii, Atom, CharDisplays, EditedStream, IO, RefText, Rope, TEditLocks, TextEdit, TextLooks, TextNode, TiogaOps, TypeScript, ViewerClasses, ViewerIO; TypescriptDisplays: CEDAR PROGRAM IMPORTS Atom, EditedStream, IO, RefText, Rope, TEditLocks, TextEdit, TextLooks, TextNode, TiogaOps, TypeScript, ViewerIO = {OPEN CharDisplays; REFTEXT: TYPE = REF TEXT; ROPE: TYPE = Rope.ROPE; Viewer: TYPE = ViewerClasses.Viewer; typescriptDisplay: CharDisplayClass _ NEW [CharDisplayClassRep _ [ Init: InitTSDisplay, TakeChar: TSTakeChar, CursorMove: TSCursorMove, ClearAll: TSClearAll]]; TSDisplay: TYPE = REF TSDisplayRep; TSDisplayRep: PUBLIC TYPE = RECORD [ ts: Viewer, fromDisplay: IO.STREAM, TORoot, TONode: TiogaOps.Ref, TNRoot: TextNode.Ref, TNNode: TextNode.RefTextNode, looks: TextLooks.Looks, spaces: REFTEXT, lineS: SEQUENCE length: NAT OF Line ]; Line: TYPE = RECORD [ tiogaCount: NAT, key: ATOM]; InitTSDisplay: PROC [cd: CharDisplay, initData: REF ANY] = { tsd: TSDisplay _ NEW [TSDisplayRep[cd.class.lines]]; cd.otherInstanceData _ tsd; tsd.ts _ TypeScript.Create[info: [name: cd.name, iconic: FALSE]]; TypeScript.ChangeLooks[tsd.ts, 'f]; [in: cd.fromDisplay] _ ViewerIO.CreateViewerStreams[name: cd.name, viewer: tsd.ts, editedStream: FALSE]; EditedStream.SetEcho[cd.fromDisplay, NIL]; tsd.TORoot _ TiogaOps.ViewerDoc[tsd.ts]; tsd.TNRoot _ TiogaOpsRefToTextNodeRef[tsd.TORoot]; tsd.looks _ TextLooks.RopeToLooks["f"]; tsd.spaces _ RefText.New[cd.class.columns]; FOR l: NAT IN [0 .. cd.class.lines) DO TypeScript.PutChar[tsd.ts, '\n]; tsd.lineS[l] _ [ tiogaCount: 0, key: Atom.MakeAtom[IO.PutFR["Before%g", IO.int[l]]] ]; ENDLOOP; SetLines[cd, tsd]; }; SetLines: PROC [cd: CharDisplay, tsd: TSDisplay] = { IsBegin: PROC [ci: INT] RETURNS [is: BOOL] = INLINE {is _ ci = 0 OR nr.Fetch[ci-1] = '\n}; nr: ROPE; lineNum, prevCI: INT; TypeScript.Flush[tsd.ts]; tsd.TONode _ TiogaOps.LastChild[tsd.TORoot]; tsd.TNNode _ TextNode.NarrowToTextNode[TiogaOpsRefToTextNodeRef[tsd.TONode]]; nr _ TiogaOps.GetRope[tsd.TONode]; lineNum _ cd.class.lines; prevCI _ nr.Length[]; FOR ci: INT _ nr.Length[]-1, ci-1 WHILE lineNum > 0 DO IF ci < 0 THEN ERROR; IF IsBegin[ci] THEN { lineNum _ lineNum - 1; TiogaOps.PutTextKey[node: tsd.TONode, where: ci, key: tsd.lineS[lineNum].key]; tsd.lineS[lineNum].tiogaCount _ prevCI - ci - 1; prevCI _ ci; }; ENDLOOP; }; TiogaOpsRefToTextNodeRef: PROC [tor: TiogaOps.Ref] RETURNS [tnr: TextNode.Ref] = TRUSTED {tnr _ LOOPHOLE[tor] --TiogaOpsImpl says TiogaOpsDefs.NodeBody = TextNode.Body--}; TSTakeChar: PROC [cd: CharDisplay, char: CHAR, insert: BOOL _ FALSE] = { tsd: TSDisplay _ NARROW[cd.otherInstanceData]; lock: TEditLocks.LockRef _ NIL; squash: [0 .. 1] _ IF insert THEN 0 ELSE 1; base: INT _ TiogaOps.GetTextKey[node: tsd.TONode, key: tsd.lineS[cd.line].key].where; wasEmpty: BOOL; wasEmpty _ tsd.lineS[cd.line].tiogaCount = 0; EnsureLineTo[cd, tsd, cd.line, cd.col+squash]; lock _ TEditLocks.Lock[doc: tsd.TNRoot, who: "Char Displays"]; { ENABLE UNWIND => IF lock # NIL THEN TEditLocks.Unlock[tsd.TNRoot]; [] _ TextEdit.ReplaceByChar[root: tsd.TNRoot, dest: tsd.TNNode, char: char, start: base + cd.col, len: squash, looks: tsd.looks]; tsd.lineS[cd.line].tiogaCount _ tsd.lineS[cd.line].tiogaCount + 1 - squash; TEditLocks.Unlock[doc: tsd.TNRoot]; }; IF wasEmpty OR cd.col = 0 THEN SetLines[cd, tsd]; TSCursorMove[cd, 0, 1, TRUE]; }; EnsureLineTo: PROC [cd: CharDisplay, tsd: TSDisplay, line, col: INT] = { diff: INT _ col - tsd.lineS[line].tiogaCount; lock: TEditLocks.LockRef _ NIL; base: INT _ TiogaOps.GetTextKey[node: tsd.TONode, key: tsd.lineS[cd.line].key].where; IF tsd.spaces.maxLength < diff THEN tsd.spaces _ RefText.New[diff]; WHILE tsd.spaces.length < diff DO tsd.spaces _ RefText.InlineAppendChar[tsd.spaces, Ascii.SP]; ENDLOOP; IF diff <= 0 THEN RETURN; lock _ TEditLocks.Lock[doc: tsd.TNRoot, who: "Char Displays"]; { ENABLE UNWIND => IF lock # NIL THEN TEditLocks.Unlock[tsd.TNRoot]; [] _ TextEdit.ReplaceByString[root: tsd.TNRoot, dest: tsd.TNNode, string: tsd.spaces, stringStart: 0, stringNum: diff, start: base + tsd.lineS[line].tiogaCount, len: 0, looks: tsd.looks]; tsd.lineS[line].tiogaCount _ tsd.lineS[line].tiogaCount + diff; TEditLocks.Unlock[doc: tsd.TNRoot]; }; }; TSCursorMove: PROC [cd: CharDisplay, line, col: INT, relative: BOOL _ FALSE] = { tsd: TSDisplay _ NARROW[cd.otherInstanceData]; IF relative THEN {line _ line + cd.line; col _ col + cd.col}; IF cd.class.autoMargins THEN { dl: INT _ col / cd.class.columns; line _ line + dl; col _ col - dl * cd.class.columns; } ELSE col _ MIN[col, cd.class.columns-1]; IF line < 0 THEN ERROR; IF line >= cd.class.lines THEN { delta: INT _ line - (cd.class.lines-1); FOR i: INT IN [0 .. delta) DO TypeScript.PutChar[tsd.ts, '\n] ENDLOOP; line _ line - delta; SetLines[cd, tsd]; }; cd.line _ line; cd.col _ col; }; TSClearAll: PROC [cd: CharDisplay] = { TSCursorMove[cd: cd, col: 0, line: cd.class.lines*2]; TSCursorMove[cd: cd, col: 0, line: 0]; }; }. XTypescriptDisplays.Mesa Last Edited by: Spreitzer, March 11, 1985 1:12:44 pm PST Κ|– "cedar" style˜Icode™K™8K˜KšΟk œ*œj˜ŸK˜šΠbxœœ˜!KšœœZ˜xK˜Kšœœ˜K˜Kšœœœœ˜Kšœœœ˜Kšœœ˜$K˜šœ&œ˜BKšœ˜K˜K˜K˜—K˜Kšœ œœ˜#šœœœœ˜$K˜ Kšœ œœ˜K˜K˜K˜K˜Kšœœ˜Kšœœ œœ˜#Kšœ˜—K˜šœœœ˜Kšœ œ˜Kšœœ˜ —K˜šΟn œœœœ˜˜>Kšœ˜Kš œœœœœ˜BKšœ˜KšœK˜KKšœ#˜#K˜—Kšœ œ œ˜1Kšœœ˜K˜—K˜šŸ œœ.œ˜HKšœœ$˜-Kšœœ˜KšœœL˜UKšœœ ˜Cšœ˜!Kšœ8œ˜˜>Kšœ˜Kš œœœœœ˜BKšœ»˜»Kšœ?˜?Kšœ#˜#K˜—K˜—K˜š Ÿ œœœ œœ˜PKšœœ˜.Kšœ œ-˜=šœœ˜Kšœœ˜!K˜K˜"K˜—Kšœœ˜(Kšœ œœ˜šœœ˜ Kšœœ˜'Kš œœœœ!œ˜FK˜K˜K˜—K˜K˜ K˜—K™šŸ œœ˜&Kšœ5˜5Kšœ&˜&Kšœ˜—K˜K˜——…—vJ