-
Notifications
You must be signed in to change notification settings - Fork 15
/
ANSI_Log.xml
350 lines (264 loc) · 7.23 KB
/
ANSI_Log.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE muclient
[
<!ENTITY PreserveLineBreaksWanted "vbTrue" >
<!ENTITY LogOutputWanted "vbTrue" >
<!ENTITY LogCommandsWanted "vbTrue" >
]>
<!-- Saved on Friday, July 25, 2003, 10:50 AM -->
<!-- MuClient version 3.42 -->
<!-- Plugin "ANSI_Log" generated by Plugin Wizard -->
<!--
You can change the entities at the top to control the way it works.
PreserveLineBreaksWanted = Whether or not each line ends with a hard carriage return
LogOutputWanted = Whether output from the MUD is to be logged
LogCommandsWanted = Whether commands you type are to be logged
vbTrue = yes
vbFalse = no
-->
<muclient>
<plugin
name="ANSI_Log"
author="Nick Gammon"
id="08025212f70f54d3bb25dd02"
language="VBscript"
purpose="Logs commands and MUD output using ANSI colours"
date_written="2003-07-25 10:45:39"
requires="3.35"
version="1.0"
>
<description trim="y">
<![CDATA[
Once installed, this plugin will log player commands, and output from the MUD, to the current log file using ANSI colour sequences.
As far as possible, the plugin will try to match the colours on the output lines to existing ANSI codes (this may fail if you are using MXP and the MUD sends non-ANSI colours).
It then generates the appropriate ANSI code and writes it to the log file.
The trigger and alias in the plugin set the "omit from log" flags so the lines are not logged twice.
They are set to "keep evaluating" so that other triggers and aliases are still processed.
]]>
</description>
</plugin>
<!-- Triggers -->
<triggers>
<trigger
enabled="y"
keep_evaluating="y"
match="^.*$"
name="ansi_log"
omit_from_log="y"
regexp="y"
script="LogOutput"
sequence="5"
>
</trigger>
</triggers>
<!-- Aliases -->
<aliases>
<alias
name="ansi_log"
script="LogCommand"
match="^.*$"
enabled="y"
omit_from_log="y"
omit_from_output="y"
regexp="y"
keep_evaluating="y"
sequence="5"
>
<send>%0</send>
</alias>
</aliases>
<!-- Script -->
<script>
dim PreserveLineBreaksWanted
PreserveLineBreaksWanted = &PreserveLineBreaksWanted;
dim LogOutputWanted
LogOutputWanted = &LogOutputWanted;
dim LogCommandsWanted
LogCommandsWanted = &LogCommandsWanted;
<![CDATA[
'
' Helper function to output code for bold, underline etc.
'
Function DoExtra (is_set, was_set, on_code, off_code)
DoExtra = ""
If is_set And (not was_set) Then
DoExtra = ANSI (on_code) ' send setting code
ElseIf (Not is_set) And (was_set) Then
DoExtra = ANSI (off_code) ' send resetting code
End If ' need to un-set it
End Function
'
' log in ANSI colours (call from trigger/alias that matches everything)
'
sub LogOutput (name, matchingline, wildcards)
dim firstline, lastline, line, style, styles
dim logline, colour, target, bold, column
dim normal (8)
dim hilite (8)
dim lastfore, lastback, lastbold
dim lastul, lastblink, lastinverse
dim ul, blink, inverse
dim i
'
' Not necessary if logging not active or not wanted
'
If (Not IsLogOpen) Or (not LogOutputWanted) Then
Exit Sub
End If
' find which line this is
lastline = GetLinesInBufferCount
' now find the first line in this paragraph
firstline = lastline - 1
do while firstline > 0
if GetLineInfo (firstline, 3) then
exit do
end if
firstline = firstline - 1
loop ' end while loop - finding start of paragraph
'
' paragraph starts with first line *past* the previous newline
'
firstline = firstline + 1
'
' paragraph can't end past where it started
'
if firstline > lastline then firstline = lastline
'
' discard world.notes and user input
'
if GetLineInfo (firstline, 4) then exit sub ' note line
if GetLineInfo (firstline, 5) then exit sub ' input line
'
' Empty lines are a special and simple case
'
if firstline = lastline and GetLineInfo (firstline, 2) = 0 then
WriteLog "" ' just write the blank line
Exit Sub
end if
'
' find what the ANSI colours are for this world
'
for i = 1 to 8
normal (i) = NormalColour (i) ' normal
hilite (i) = BoldColour (i) ' highlight
next
'
' process entire paragraph
'
logline = logline & ANSI (0) ' reset all styles
lastfore = 37 ' reset is white
lastback = 40 ' on black
lastbold = vbFalse
lastul = vbFalse
lastblink = vbFalse
lastinverse = vbFalse
for line = firstline to lastline
styles = GetLineInfo (line, 11) ' how many styles
'
' process all styles runs in this line
'
for style = 1 to styles
'
' find text style (ANSI code)
'
target = GetStyleInfo (line, style, 14) ' RGB colour of style text
colour = -1
bold = vbFalse
'
' work out which ANSI colour it must have been by a scan
'
for i = 1 to 8
' normal colour
if target = normal (i) then
colour = 29 + i
exit for
end if
' bold colour
if target = hilite (i) then
colour = 29 + i
bold = vbTrue
exit for
end if
next ' colour
'
' if found, output that colour
'
if colour <> -1 then
'
' only output if colour change
'
if colour <> lastfore then
logline = logline & ANSI (colour)
lastfore = colour
end if
end if ' colour found
logline = logline & DoExtra (bold, lastbold, 1, 22)
lastbold = bold
target = GetStyleInfo (line, style, 15) ' RGB colour of style background
colour = -1
'
' work out which ANSI colour it must have been by a scan
'
for i = 1 to 8
' normal colour
if target = normal (i) then
colour = 39 + i
exit for
end if
next ' colour
'
' if found, output that colour
'
if colour <> -1 then
'
' only output if colour change
'
if colour <> lastback then
logline = logline & ANSI (colour)
lastback = colour
end if
end if ' colour found
'
' do other styles (underline, blink, inverse)
'
bold = GetStyleInfo (line, style, 8) ' bold flag
logline = logline & DoExtra (bold, lastbold, 1, 22)
lastbold = bold
ul = GetStyleInfo (line, style, 9) ' underline flag
logline = logline & DoExtra (ul, lastul, 4, 24)
lastul = ul
blink = GetStyleInfo (line, style, 10) ' blink flag
logline = logline & DoExtra (blink, lastblink, 3, 23)
lastblink = blink
inverse = GetStyleInfo (line, style, 11) ' inverse flag
logline = logline & DoExtra (inverse, lastinverse, 7, 27)
lastinverse = inverse
'
' now output the text
'
logline = logline & GetStyleInfo (line, style, 1)
next ' process the next style
'
' If wanted, keep the original (soft) line breaks
'
If PreserveLineBreaksWanted And line <> lastline Then
logline = logline & vbCrLf
End If
next ' end for loop - processing each line in the paragraph
WriteLog logline
end sub ' end of LogOutput
sub LogCommand (name, matchingline, wildcards)
'
' Not necessary if logging not active or not wanted
'
If (Not IsLogOpen) Or (not LogCommandsWanted) Then
Exit Sub
End If
'
' simply log in default ANSI colours
'
WriteLog ANSI (0) & matchingline
end sub
]]>
</script>
</muclient>