View difference between Paste ID: TYCAYy3k and SmfWmQH4
SHOW: | | - or go back to the newest paste.
1
if OneOS then
2
  OneOS.ToolBarColour = colours.lightGrey 
3
end
4
--Credits: 
5
6
--Developers:
7
8
--Hithere
9
10
11
--APIs
12
13
14
--Special thanks to:
15
16
--oeed, for OneOS, the OS Sapphari was
17
--designed for
18
19
20
21
--DEVELOPER CONFIG
22
local waitForMessage =  false
23
24
25
--------------------------------------------------
26-
  sapphariVersionString = "0.0"
26+
  sapphariVersionString = "0.1"
27
  sapphariVersionNumber = 0
28
  sapphariSites = {}
29
  sapphariBlacklist = {}
30
    --The script sets the news, then sets the url vars
31
shell.run("pastebin run Jg8D7mLi")
32
--print("--------------------------------------------------") 
33
--It would seem I don't need to kill any functions as OneOS handles that for me :D
34
--Internal functions
35
local sapphInt = {}
36
function sapphInt.redrawUI()
37
  local termX, termY = term.getSize() 
38
  for i=1,2 do
39
    paintutils.drawLine(1,i,termX,i,colors.lightGray)
40
  end
41
  paintutils.drawLine(2,1,termX/3,1,colors.white)
42
  paintutils.drawLine(termX/3+2,1,termX/3+4,1,colors.green)
43
  term.setCursorPos(termX/3+2,1)
44
  term.write("GO!")
45
end
46
--this function will get the data for a site,
47
--however, will not run it.
48
function sapphInt.getSite(pasteID)
49
  local responce = http.get("http://pastebin.com/raw.php?i="..pasteID)
50
  if responce then
51
    return loadstring(responce.readAll())
52
  else
53
    return false
54
  end
55
end
56
function sapphInt.handleMenu(typeClick, clickX, clickY)
57
  --handle the user   clicking the menu
58
  local termX,termY=term.getSize()
59
  if typeClick == 1 then
60
    --okay, it's a left click, passes first one'
61
    if clickX>1 then --okay, in somewhere special
62
      if clickX<termX/3+1 then
63
        --okay, the user wants to change the url.
64
        term.setCursorPos(2,1)
65
        print("calling")
66
        input = read()
67
        print"dun"
68
        --we will return the input which will
69
        --be returned until the program must
70
        --end, then it will be a temporary
71
        --global variable and read by safari
72
        --again. Complicated? True.
73
        return input 
74
      end
75
    end
76
  end
77
end
78
function sapphInt.decodeHumanReadableURL(HRURL)
79
  --this is where we attempt to decode a
80
  --human readable url. If fails, will tell
81
  --calling function to attempt to use the
82
  --plain url instead.
83
  if sapphariSites[HRURL] then
84
    --this must be an HRURL, so we'll give them'
85
     --the pasteID
86
    return sapphariSites[HRURL]
87
  else
88
    return HRURL
89
    --this must be a PasteID then
90
  end
91
end
92
93
--WEBSITE FUNCTON
94
--sapphutils, MUST be global!!!
95
sapphUtils = {}
96
function sapphUtils.pullEvent(filter)
97
  sapphInt.redrawUI()
98
  while true do do
99
    event, p1, p2, p3,  p4, p5, p6, p7 = oldPullEvent()
100
    if event == "mouse_click" and p3==1 then
101
      print"handling"
102
      local newSiteq = sapphInt.handleMenu(p1, p2, p3)
103
      if newSiteq then
104
        newSite = newSiteq
105
        sapphInt.handleSapphari()
106
        error("Returned to bad pullEvent")
107
      end
108
    end
109
    if filter then
110
      if event == filter then
111
        return event, p1, p2, p3, p4, p5, p6, p7
112
      end
113
    else
114
      return event, p1, p2, p3, p4, p5, p6, p7
115
    end
116
    --if they changed sites, we'll never get here.
117
  end 
118
end  end      
119
--fix os.pullEvent
120
oldPullEvent = os.pullEvent
121
os.pullEvent = sapphInt.pullEvent
122
function sapphUtils.read(startx, starty, endx, endy)
123
  print("started")
124
  local endy = starty
125
  --a function for text boxes, that, in short,
126
  --has a text wrapping feature
127
  --~ to quit
128
  local writenString = ""
129
  local cursorPos = 0
130
  while true do
131
    local evt, charcode = oldPullEvent("key")
132
    term.setCursorPos(5,5) 
133
    if evt == "key" then
134
      print"okay"
135
    else
136
      print"FUUUUUUUUUUUUUUU"
137
    end
138
    charcode = tonumber(charcode)
139
    print(charcode)
140
      if charcode == 41 then
141
        return false
142
      elseif charcode == 203 then
143
        --move left
144
      elseif charcode == 205 then
145
        --move right
146
      elseif charcode == 14 then
147
        --delete a cha+r with string.sub
148
      elseif charcode == 28 then
149
        term.setCursorPos(5,5)
150
        print("returning")
151
        return writenString
152
      elseif charcode>58 and charcode<80 then
153
        --Now, now, no need to do anything here!
154
        --This just prevents these from trying 
155
        --to be added to the string :)
156
        --REJECTED keys:
157
      elseif charcode == 88 then
158
      elseif charcode == 183 then
159
      elseif charcode == 70 then
160
      elseif charcode == 197 then
161
      elseif charcode == 210 then
162
      elseif charcode == 199 then
163
      elseif charcode == 201 then
164
      elseif charcode == 211 then
165
      elseif charcode == 207 then
166
      elseif charcode == 209 then
167
      elseif charcode == 29 then
168
      elseif charcode == 219 then
169
      elseif charcode == 56 then
170
      elseif charcode == 184 then
171
      elseif charcode == 220 then
172
      elseif charcode == 221 then
173
      elseif charcode == 157 then
174
      elseif charcode == 42 then
175
      elseif charcode == 54 then
176
      elseif charcode == 58 then
177
      else
178
        local keyString = keys.getName(charcode)
179
        if keyString == nil then
180
          keyString = "There was an error. Tell Hithere it was this sapphInt.read() and that it failed hard"
181
        end
182
        writenString = writenString..keyString
183
        term.setCursorPos(8,6)
184
        print("test")
185
        print(writenString)
186
        --do the key thing here
187
    end
188
  end
189
end
190
--this must get  the pasteid, not the human
191
--redable url
192
t = 0
193
function sapphInt.handleWebsite(url)
194
  term.setCursorPos(7,4)
195
  t=t+1
196
  print("got to handle"..t)
197
  --need help on how to run a string as a function
198
  --this will work for now
199
  local rurl = sapphInt.decodeHumanReadableURL(url)
200
  local site = sapphInt.getSite(rurl)
201
  if site then
202
    --local ok, error = pcall(site())
203
    setfenv(site, getfenv())
204
    local ok, error = pcall(site())
205
  end
206
  --term.setCursorPos(1,1)
207
  --term.clear()
208
  --cool people do it backwards
209
  
210
end 
211
function sapphInt.handleSapphari()
212
  --the mother function
213
  --the main mother loop. If the site crashes
214
  --it will go to homepage, will go to homepa
215
  --ge if first run too.
216
  --we'll need a loop
217
  while true do
218
    if newSite then
219
      gotoNewSite = newSite
220
      newSite = nil
221
      
222
      term.setCursorPos(1,3)
223
      term.setBackgroundColor(colors.black)
224
      term.clear()
225
      --cool people do it backwards
226
      sapphInt.handleWebsite(gotoNewSite)
227
    else
228
      sapphInt.handleWebsite("F99c7Fmi")
229
    end
230
  end
231
end
232
---------------------------------------------------
233
234
235
236
237
238
239
240
--yes = true
241
--sapphInt.handleNews()
242
sapphInt.handleSapphari()