751f39ad06596afbfec3df125271b2c30ca19f8f
7 procedure cbufPut (const s
: AnsiString);
8 procedure cbufPutChars (buf
: PChar; count
: Integer);
10 function cbufLastChange (): LongWord;
12 function cbufWalkStart (): LongWord;
13 function cbufWalkEnd (pos
: LongWord): LongWord;
14 procedure cbufPrev (var pos
: LongWord);
15 procedure cbufNext (var pos
: LongWord);
17 function cbufAt (const pos
: LongWord): Char;
20 procedure cbufLastLine (var sp
: LongWord; var ep
: LongWord);
21 // move one line up; `sp` and `ep` MUST be valid values from previous call to `cbufLastLine()`
22 function cbufLineUp (var sp
: LongWord; var ep
: LongWord): Boolean;
24 procedure cbufClear ();
30 // ////////////////////////////////////////////////////////////////////////// //
31 //const ConBufSize = 64;
32 const ConBufSize
= 256*1024;
34 // each line in buffer ends with '\n'; we don't keep offsets or lengthes, as
35 // it's fairly easy to search in buffer, and drawing console is not a common
36 // thing, so it doesn't have to be superfast.
38 cbuf
: packed array [0..ConBufSize
-1] of Char;
39 cbufhead
: LongWord = 0;
40 cbuftail
: LongWord = 0; // `cbuftail` points *at* last char
41 changeCount
: LongWord = 1;
44 function cbufLastChange (): LongWord; begin result
:= changeCount
; end;
47 // ////////////////////////////////////////////////////////////////////////// //
48 procedure cbufPutChars (buf
: PChar; count
: Integer);
56 if changeCount
= 0 then changeCount
:= 1;
62 np
:= (cbuftail
+1) mod ConBufSize
;
65 // we have to make some room; delete top line for this
68 och
:= cbuf
[cbufhead
];
69 cbufhead
:= (cbufhead
+1) mod ConBufSize
;
70 if (cbufhead
= np
) or (och
= #10) then break
;
80 procedure cbufPut (const s
: AnsiString);
82 if length(s
) > 0 then cbufPutChars(@s
[1], length(s
));
86 // ////////////////////////////////////////////////////////////////////////// //
87 // warning! don't modify conbuf while the range is active!
88 function cbufWalkStart (): LongWord; begin result
:= cbuftail
; end;
89 function cbufWalkEnd (pos
: LongWord): LongWord; begin result
:= cbufhead
; end;
90 procedure cbufPrev (var pos
: LongWord); begin pos
:= (pos
+ConBufSize
-1) mod ConBufSize
; end;
91 procedure cbufNext (var pos
: LongWord); begin pos
:= (pos
+1) mod ConBufSize
; end;
93 function cbufAt (const pos
: LongWord): Char; begin result
:= cbuf
[pos
mod ConBufSize
]; end;
96 // ////////////////////////////////////////////////////////////////////////// //
97 procedure cbufLastLine (var sp
: LongWord; var ep
: LongWord);
101 if cbufhead
= cbuftail
then
109 while pos
<> cbufhead
do
111 pp
:= (pos
+ConBufSize
-1) mod ConBufSize
;
112 if cbuf
[pp
] = #10 then break
;
119 function cbufLineUp (var sp
: LongWord; var ep
: LongWord): Boolean;
123 if sp
= cbufhead
then begin sp
:= cbufhead
; ep
:= cbufhead
+1; result
:= false; exit
; end;
124 pos
:= (sp
+ConBufSize
-1) mod ConBufSize
;
125 if (pos
= cbufhead
) or (cbuf
[pos
] <> #10) then begin sp
:= cbufhead
; ep
:= cbufhead
+1; result
:= false; exit
; end;
127 while pos
<> cbufhead
do
129 pp
:= (pos
+ConBufSize
-1) mod ConBufSize
;
130 if cbuf
[pp
] = #10 then break
;
138 procedure cbufClear ();
144 if changeCount
= 0 then changeCount
:= 1;