-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathBraille_Reader.xml
172 lines (134 loc) · 4.6 KB
/
Braille_Reader.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
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<muclient>
<plugin
name="Braille_Reader"
author="Nick Gammon"
id="9142cc3c8b300ae5faf113c4"
language="Lua"
purpose="Outputs chunks of text for use with a Braille reader"
date_written="2018-10-03 05:50:10"
requires="5.00"
version="1.0"
>
<description trim="y">
<![CDATA[
Outputs in chunks for Braille-readers. See "CONFIGURATION" in plugin for how to change various parameters.
Each line from the MUD is output in up to (default) 40 characters at a time, up to the end of the last word (the most-recent space). Press the "resume" function key to view the next 40 characters.
To skip the rest of the current line press the "skip" function key.
To discard all output press the "clear" function key.
Default keys:
F6 - resume
F7 - skip rest of line
F8 - clear all output
If the display is blank then there is no pending output. Blank lines from the MUD are automatically ignored.
]]>
</description>
</plugin>
<script>
<![CDATA[
-- CONFIGURATION
chars = 40 -- how many to display at a time
unicode = false
text_colour = ColourNameToRGB("white")
background_colour = ColourNameToRGB("black")
resume_fkey = "F6"
skip_fkey = "F7"
clear_fkey = "F8"
-- INTERNAL STUFF
win = "test_" .. GetPluginID () -- get a unique name, ensure not empty if outside plugin
font = "f"
lines = { } -- table of lines from MUD
last_output = ""
function Resume ()
-- clear previous text initially
WindowRectOp(win, miniwin.rect_fill, 0, 0, 0, 0, background_colour, 0)
last_output = ""
-- if nothing to show, a blank output will indicate that
if #lines == 0 then
Redraw ()
return
end -- if
local text = lines [1] -- what needs to be shown
if #text > chars then
local last_space = 0
-- stop at last word
for i = 1, #text do
if i > chars then
break
end -- if past wanted width
if string.sub (text, i, i) == " " then
last_space = i
end -- if found a space
end -- for
if last_space == 0 then
last_space = chars + 1 -- assume space just afterwards
end -- if
lines [1] = Trim (string.sub (text, last_space)) -- rest of line
text = string.sub (text, 1, last_space - 1) -- take all 'chars' characters
partial_line = true
else
table.remove (lines, 1) -- not too long, just remove it
partial_line = false
end -- if too long
WindowText (win, font, text,
5, 5, 0, 0, -- rectangle
text_colour, -- colour
unicode) -- Unicode?
Redraw ()
last_output = text
end -- Resume
function Skip_Line ()
if partial_line then
table.remove (lines, 1)
partial_line = false
end -- if
Resume () -- now show next line
end -- Skip_Line
function Clear_Output ()
lines = {}
partial_line = false
Resume ()
end -- Clear_Output
function OnPluginInstall ()
-- set up key bindings
AcceleratorTo(resume_fkey, 'Resume()', sendto.script)
AcceleratorTo(skip_fkey, 'Skip_Line()', sendto.script)
AcceleratorTo(clear_fkey, 'Clear_Output()', sendto.script)
-- leave room at the bottom for the miniwindow
TextRectangle(0, -- left
0, -- top
0, -- width
-50, -- 50 pixels from the bottom
10, -- BorderOffset,
ColourNameToRGB ("gray"), -- BorderColour,
2, -- BorderWidth,
ColourNameToRGB ("silver"), -- OutsideFillColour,
miniwin.brush_solid) -- OutsideFillStyle
-- make miniwindow to find text size
WindowCreate (win, 0, 0, 0, 0, miniwin.pos_bottom_left, 0, background_colour) -- create window
-- set up font
WindowFont (win, font, "Courier", 14) -- define font
-- get font information
width = WindowTextWidth (win, font, string.rep ("M", chars))
height = WindowFontInfo (win, font, 1) -- height of the font
-- recreate window to have correct width
WindowCreate (win, 0, 0, width + 10, height + 10, miniwin.pos_bottom_left, 0, background_colour) -- create window
WindowShow (win, true) -- show it
lines [1] = "Braille Reader installed"
Resume ()
end -- OnPluginInstall
-- Type: 0 = output line, 1 = note, 2 = command
function OnPluginScreendraw (type, log, line)
-- if output line, add to buffer of lines to be shown
if type ~= 2 and Trim (line) ~= "" then
table.insert (lines, Trim (line))
-- if nothing currently shown, start showing stuff
if last_output == "" then
Resume ()
end -- if
end -- if
end -- function OnPluginScreendraw
]]>
</script>
</muclient>