Guest User

KristScape by cossacksson

a guest
Jul 25th, 2015
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.93 KB | None | 0 0
  1. --KristScape by cossacksson
  2. local release = 0
  3. local version = "Dev Build 2"
  4. local latest = 0
  5. local gui = 0
  6. local tabs = 1
  7. local activetab = 1
  8. local selected = false
  9. local editing = false
  10. local title = {}
  11. local address = {}
  12. local content = {}
  13. local literal = {}
  14. local history = {}
  15. local links = {}
  16. local themefore = 32
  17. local themeback = 8192
  18. local themehead = 256
  19. local themetext = 32768
  20. local themetool = -1
  21. local themedang = 16384
  22. local issue = 0
  23. local drawn = ""
  24. local headers = {["User-Agent"] = "KristScape "..version}
  25. links[1] = {}
  26. links[2] = {}
  27. links[3] = {}
  28. links[1][0] = 0
  29. history[1] = {}
  30. history[2] = {}
  31. history[3] = {}
  32. history[1][0] = 0
  33. local function boot()
  34. term.setBackgroundColor(1)
  35. term.clear()
  36. checkdir()
  37. checkdir()
  38. if http then update() end
  39. settle()
  40. title[1] = "New Tab"
  41. address[1] = ""
  42. content[1] = "[BG:WHITE]"
  43. while tabs > 0 do
  44. go()
  45. end
  46. term.setBackgroundColor(32768)
  47. term.setTextColor(16)
  48. term.clear()
  49. term.setCursorPos(1,1)
  50. end
  51. function update()
  52. --latest = tonumber(http.get(readconfig("versionserver")).readAll())
  53. --if latest > version then
  54. print("This is a pre-release. Checking up...")
  55. --log("Discovered update")
  56. if readconfig("autoupdate") then
  57. local me = fs.open(fs.getName(shell.getRunningProgram()),"w")
  58. local nextversion = http.get("https://raw.githubusercontent.com/BTCTaras/kristwallet/scape/kristscape").readAll()
  59. --print("Installed update. Run this program again to start v"..latest..".")
  60. me.write(nextversion)
  61. me.close()
  62. --("Installed update")
  63. -- else
  64. --log("Ignored update")
  65. -- latest = -2
  66. -- end
  67. else
  68. --log("No updates found")
  69. end
  70. end
  71. function log(text)
  72. logfile = fs.open("kst/log_scape","a")
  73. logfile.writeLine(tostring(os.day()).."-"..tostring(os.time())..": "..text)
  74. logfile.close()
  75. end
  76. function checkfile(path,default)
  77. if not fs.exists("kst/"..path) then
  78. file = fs.open("kst/"..path,"w")
  79. file.writeLine(default)
  80. file.close()
  81. --log("Created file "..path)
  82. return false
  83. else
  84. return true
  85. end
  86. end
  87. function resetfile(path,default)
  88. file = fs.open("kst/"..path,"w")
  89. file.writeLine(default)
  90. file.close()
  91. --log("Wrote file "..path)
  92. end
  93. function readconfig(path)
  94. if fs.exists("kst/"..path) then
  95. file = fs.open("kst/"..path,"r")
  96. local context = file.readAll()
  97. file.close()
  98. if context == "true" then return true end
  99. if context == "false" then return false end
  100. return context
  101. else
  102. return false
  103. end
  104. end
  105. function settle()
  106. gui = 2
  107. if pocket then gui = 4 end
  108. if term.isColor() then gui = 1 end
  109. if term.isColor() and pocket then gui = 2 end
  110. local theme = readconfig("theme")
  111. themefore = 2^tonumber(theme:sub(1,1),16)
  112. themeback = 2^tonumber(theme:sub(2,2),16)
  113. themehead = 2^tonumber(theme:sub(3,3),16)
  114. themetext = 2^tonumber(theme:sub(4,4),16)
  115. themedang = 2^tonumber(theme:sub(5,5),16)
  116. end
  117. local function panic()
  118. tabs = 0
  119. end
  120. local function getError(code)
  121. if code == 000 then return "UNSPECIFIED_EXCEPTION" end
  122. if code == 001 then return "ILLEGALLY_NESTED_TAGS" end
  123. if code == 002 then return "UNEXPECTED_CLOSING_TAG" end
  124. if code == 003 then return "HTTP_NOT_ENABLED" end
  125. if code == 004 then return "NO_DATA_RECEIVED" end
  126. if code == 005 then return "NO_DNS_RECORD_FOUND" end
  127. if code == 006 then return "GENERIC_EXCEPTION" end
  128. if code == 007 then return "UNSUPPORTED_IMAGE_FORMAT" end
  129. if code == 008 then return "NFP_IMAGE_NOT_STORED_LOCALLY" end
  130. if code == 009 then return "HOSTNAME_NOT_RESOLVED" end
  131. if code == 010 then return "NO_WEBPAGE_RECEIVED" end
  132. if code == 042 then return "BLOCKED_BY_CHUCK_NORRIS" end
  133. if code == 069 then return "ADULT_CONTENT_BLOCKED" end
  134. return "INVALID_ERROR_CODE"
  135. end
  136. function checkdir()
  137. if fs.isDir("kst") then
  138. checkfile("log_scape","KristScape browsing history")
  139. checkfile("versionserver","https://raw.githubusercontent.com/BTCTaras/kristwallet/master/staticapi/browserversion")
  140. checkfile("updateserver","https://raw.githubusercontent.com/BTCTaras/kristwallet/master/kristscape")
  141. checkfile("theme","5d8fe")
  142. checkfile("theme","1ecff")
  143. checkfile("theme","87ffe")
  144. checkfile("theme","39bfe")
  145. checkfile("theme","4c8fe")
  146. checkfile("theme","6e8ff")
  147. checkfile("theme","f788e")
  148. checkfile("adult","false")
  149. resetfile("syncnode","http://ceriat.net/krist/index.php")
  150. resetfile("pages/test",[[Images test
  151. .nfp format:
  152. [BR][IMAGE]images/dang.nfp[/IMAGE][END]
  153. ]])
  154. resetfile("pages/error",[[Oh dear!!!!![ERROR]
  155. [BG:THEMEDISABLED][C:THEMETEXT][HL:THEMEFG][BR][CENTER]KristScape has encountered an error![/CENTER][HL:THEMEDISABLED]
  156. [BR]The page could not be displayed because of an
  157. [BR]error. Sorry about that :(
  158. [BR]
  159. [BR]Code: [C:YELLOW][HL:RED][PROBLEM][C:THEMETEXT][HL:THEMEDISABLED]
  160. [BR]
  161. [BR]If you need help or don't know what this
  162. [BR]means, you can ask on the Krist thread.
  163. [BR] [IMAGE]images/dang.nfp[/IMAGE]
  164. [END]
  165. ]])
  166. resetfile("pages/images/dang.nfp",[[4444 44 4 4 44444
  167. 4 44 44 44 444 4 4 4
  168. 4 4 44 44 4 44 4 4
  169. 4 4 444444444 4 444 4 444
  170. 4 4 4 44 4 44 44 4
  171. 444 44 4 4 4 4444]])
  172. resetfile("pages/images/krist.nft",[[?0?5/?5?d\
  173. ?5?d\?d?5/]])
  174. else
  175. fs.makeDir("kst/scape")
  176. end
  177. end
  178. local function centerText(text)
  179. local x,y = term.getSize()
  180. local x2,y2 = term.getCursorPos()
  181. term.setCursorPos(math.ceil((x/2)-(text:len()/2)),y2)
  182. term.write(text)
  183. end
  184. local function centerTextAt(text,width,at)
  185. local x,y = term.getSize()
  186. local x2,y2 = term.getCursorPos()
  187. term.setCursorPos(math.ceil((x/2)-((width)/2))+at,y2)
  188. term.write(text)
  189. end
  190. local function stripTags(text)
  191. local digest = ""
  192. local nexttag = 0
  193. while true do
  194. nexttag = text:find("%[")
  195. if tostring(nexttag) == "nil" then
  196. digest = text
  197. break
  198. else
  199. if nexttag ~= 1 then
  200. digest = digest .. text:sub(1,nexttag-1):gsub("%]","")
  201. text = text:sub(nexttag)
  202. else
  203. if tostring(text:find("%]")) == "nil" then break else
  204. text = text:sub(nexttag+text:find("%]"))
  205. end
  206. end
  207. end
  208. end
  209. return digest
  210. end
  211. local function newtab()
  212. activetab = tabs + 1
  213. tabs = tabs + 1
  214. title[activetab] = "New Tab"
  215. address[activetab] = ""
  216. literal[activetab] = ""
  217. content[activetab] = "[BG:WHITE]"
  218. history[activetab][0] = 0
  219. links[activetab][0] = 0
  220. end
  221. local function movetab(from,to)
  222. title[to] = title[from]
  223. address[to] = address[from]
  224. literal[to] = literal[from]
  225. content[to] = content[from]
  226. history[to] = history[from]
  227. links[to] = links[from]
  228. end
  229. local function fixaddress(a)
  230. a = a:gsub(".com",".kst"):gsub(".org",".kst"):gsub(".net",".kst"):gsub(".gov",".kst")
  231. if string.sub(a,1,7) ~= "http://" and string.sub(a,1,8) ~= "scape://" then
  232. a = "http://"..a
  233. end
  234. return a
  235. end
  236. local function refresh(addr)
  237. links[activetab][0] = 0
  238. local domain = ""
  239. if addr == "" then
  240. content[activetab] = " "
  241. title[activetab] = ""
  242. else
  243. if string.sub(addr,1,7) == "http://" then
  244. if http then
  245. addr = string.sub(addr,8)
  246. if addr:find(".kst") == nil then crash(9) return false end
  247. domain = string.sub(addr,1,addr:find(".kst")-1)
  248. addr = string.sub(addr,5+string.len(domain))
  249. local zone = http.get(readconfig("syncnode").."?a="..domain).readAll()
  250. --if zone == nil then crash(5) return false end
  251. if zone == "" then crash(5) return false end
  252. if string.sub(zone,1,1) == "$" then
  253. zone = string.sub(zone,2)
  254. address[activetab] = fixaddress(zone)
  255. --content[activetab] = "aaaa[SLB]aaaa"
  256. refresh(address[activetab])
  257. else
  258. literal[activetab] = "http://"..zone..addr
  259. if history[activetab][history[activetab][0]] ~= address[activetab] then
  260. history[activetab][0] = history[activetab][0] + 1
  261. history[activetab][history[activetab][0]] = address[activetab]
  262. end
  263. log(address[activetab])
  264. --print(literal[activetab])
  265. content[activetab] = http.get(literal[activetab],nil,headers).readAll()
  266. content[activetab] = string.gsub(content[activetab],"\n","[SLB]")
  267. if tostring(content[activetab]:find("%[SLB%]")) == "nil" then
  268. title[activetab] = content[activetab]
  269. else
  270. title[activetab] = string.sub(content[activetab],1,string.find(content[activetab],"%[SLB%]")-1)
  271. end
  272. if string.find(content[activetab],"%[SLB%]") ~= nil then
  273. content[activetab] = string.sub(content[activetab],string.find(content[activetab],"%[SLB%]")+4)
  274. else crash(10) return false end
  275. end
  276. else crash(3) return false end
  277. elseif string.sub(addr,1,8) == "scape://" then
  278. addr = string.sub(addr,9)
  279. literal[activetab] = "scape://"..addr
  280. history[activetab][0] = history[activetab][0] + 1
  281. history[activetab][history[activetab][0]] = literal[activetab]
  282. log(literal[activetab])
  283. content[activetab] = readconfig("pages/"..addr)
  284. content[activetab] = string.gsub(content[activetab],"\n","[SLB]")
  285. if tostring(content[activetab]:find("%[SLB%]")) == "nil" then
  286. title[activetab] = content[activetab]
  287. else
  288. title[activetab] = string.sub(content[activetab],1,string.find(content[activetab],"%[SLB%]")-1)
  289. end
  290. content[activetab] = string.sub(content[activetab],string.find(content[activetab],"%[SLB%]")+4)
  291. end
  292. end
  293. end
  294. function crash(code)
  295. issue = code
  296. log("ERROR/"..tostring(code))
  297. refresh("scape://error/")
  298. literal[activetab] = "scape://error"
  299. os.setAlarm(os.time()+.01)
  300. end
  301. function showsite()
  302. if content[activetab]:find("%[NSFW%]") ~= nil then
  303. if readconfig("adult") then
  304.  
  305. else
  306. crash(69)
  307. return false
  308. end
  309. end
  310. drawn = content[activetab]
  311. local page = content[activetab]:gsub("%[PROBLEM%]",string.format("%03d",tostring(issue)).." "..getError(issue)):gsub("%[ID%]",os.getComputerID())
  312. if string.len(page) == 0 then crash(4) return false end
  313. local tag = 0
  314. local el = ""
  315. local align = 1
  316. local cellstart = 1
  317. local paragraph = 0
  318. local offset = 0
  319. local wid = 0
  320. local dontcolorlinks = false
  321. term.setBackgroundColor(1)
  322. el = page:sub(2,page:sub(2):find("%]")).."]"
  323. if el == "[BG:BLACK]" then
  324. term.setBackgroundColor(32768)
  325. elseif el == "[BG:RED]" then
  326. term.setBackgroundColor(16384)
  327. elseif el == "[BG:GREEN]" then
  328. term.setBackgroundColor(8192)
  329. elseif el == "[BG:BROWN]" then
  330. term.setBackgroundColor(4096)
  331. elseif el == "[BG:BLUE]" then
  332. term.setBackgroundColor(2048)
  333. elseif el == "[BG:PURPLE]" then
  334. term.setBackgroundColor(1024)
  335. elseif el == "[BG:CYAN]" then
  336. term.setBackgroundColor(512)
  337. elseif el == "[BG:LIGHTGRAY]" or el == "[BG:LIGHTGREY]" then
  338. term.setBackgroundColor(256)
  339. elseif el == "[BG:DARKGRAY]" or el == "[BG:DARKGREY]" or el == "[BG:GRAY]" or el == "[BG:GREY]" then
  340. term.setBackgroundColor(128)
  341. elseif el == "[BG:PINK]" then
  342. term.setBackgroundColor(64)
  343. elseif el == "[BG:LIME]" then
  344. term.setBackgroundColor(32)
  345. elseif el == "[BG:YELLOW]" then
  346. term.setBackgroundColor(16)
  347. elseif el == "[BG:LIGHTBLUE]" then
  348. term.setBackgroundColor(8)
  349. elseif el == "[BG:MAGENTA]" then
  350. term.setBackgroundColor(4)
  351. elseif el == "[BG:ORANGE]" then
  352. term.setBackgroundColor(2)
  353. elseif el == "[BG:WHITE]" then
  354. term.setBackgroundColor(1)
  355. elseif el == "[BG:THEMEFG]" then
  356. term.setBackgroundColor(themefore)
  357. elseif el == "[BG:THEMEDISABLED]" then
  358. term.setBackgroundColor(themeback)
  359. elseif el == "[BG:THEMEBG]" then
  360. term.setBackgroundColor(themehead)
  361. elseif el == "[BG:THEMETEXT]" then
  362. term.setBackgroundColor(themetext)
  363. elseif el == "[BG:THEMEDANGER]" then
  364. term.setBackgroundColor(themedang)
  365. end
  366. while true do
  367. tag = tag + 1
  368. term.setCursorPos(1,3+tag)
  369. term.write(" ")
  370. if tag == 16 then break end
  371. end
  372. tag = 0
  373. term.setTextColor(32768)
  374. term.setCursorPos(1,4)
  375. while true do
  376. --print(page)
  377. tag = page:find("%[")
  378. if tostring(tag) == "nil" then
  379. if align == 1 then term.write(page:gsub("%]",""))
  380. elseif align == 2 then centerText(page)
  381. end
  382. break
  383. else
  384. if tag ~= 1 then
  385. if align == 1 then
  386. if paragraph == 0 then
  387. term.write(page:sub(1,tag-1):gsub("%]",""))
  388. else
  389. if page:find("%s") ~= nil then
  390. local ox, oy = term.getCursorPos()
  391. if (ox-cellstart) + page:find("%s") < paragraph then
  392. --print(page)
  393. --term.write(tostring(page:find("%s")))
  394. term.write(page:sub(1,page:find("%s")))
  395. page = page:sub(page:find("%s")+1)
  396. else
  397. term.setCursorPos(cellstart,oy+1)
  398. end
  399. else
  400. --paragraph = 0
  401. --print("error-ish")
  402. --something odd happened.
  403. end
  404. end
  405. elseif align == 2 then
  406. local line = page:sub(1,tag-1)
  407. --string.len(page:sub(1,-8+tag+page:find("%[/CENTER%]")))
  408. --string.find(stripTags(page:gsub("%[/CENTER%]","$$ENDCENT")),"$$ENDCENT")-string.len(stripTags(line))-- - string.len(line))
  409. --print()
  410. --while string.len(stripTags(line)) < string.len(stripTags(line)) + offset do line = " " .. line end
  411. --while string.len(stripTags(line)) < string.find(stripTags(page:gsub("%[/CENTER%]","$$ENDCENT")),"$$ENDCENT") + offset do line = line .. " " end
  412. centerTextAt(line,wid,offset)--,-(string.len(page:sub(1,-9+tag+string.find(stripTags(page:gsub("%[/CENTER%]","$$ENDCENT")),"$$ENDCENT")))/2)+offset-5)
  413. offset = offset + string.len(stripTags(line))
  414. end
  415. if paragraph == 0 then page = page:sub(tag) end
  416. else
  417. el = page:sub(tag,-1+tag+page:find("%]"))
  418. if el == "[C:BLACK]" then
  419. term.setTextColor(32768)
  420. elseif el == "[C:RED]" then
  421. term.setTextColor(16384)
  422. elseif el == "[C:GREEN]" then
  423. term.setTextColor(8192)
  424. elseif el == "[C:BROWN]" then
  425. term.setTextColor(4096)
  426. elseif el == "[C:BLUE]" then
  427. term.setTextColor(2048)
  428. elseif el == "[C:PURPLE]" then
  429. term.setTextColor(1024)
  430. elseif el == "[C:CYAN]" then
  431. term.setTextColor(512)
  432. elseif el == "[C:LIGHTGRAY]" or el == "[C:LIGHTGREY]" then
  433. term.setTextColor(256)
  434. elseif el == "[C:DARKGRAY]" or el == "[C:DARKGREY]" or el == "[C:GRAY]" or el == "[C:GREY]" then
  435. term.setTextColor(128)
  436. elseif el == "[C:PINK]" then
  437. term.setTextColor(64)
  438. elseif el == "[C:LIME]" then
  439. term.setTextColor(32)
  440. elseif el == "[C:YELLOW]" then
  441. term.setTextColor(16)
  442. elseif el == "[C:LIGHTBLUE]" then
  443. term.setTextColor(8)
  444. elseif el == "[C:MAGENTA]" then
  445. term.setTextColor(4)
  446. elseif el == "[C:ORANGE]" then
  447. term.setTextColor(2)
  448. elseif el == "[C:WHITE]" then
  449. term.setTextColor(1)
  450. elseif el == "[C:THEMEFG]" then
  451. term.setTextColor(themefore)
  452. elseif el == "[C:THEMEDISABLED]" then
  453. term.setTextColor(themeback)
  454. elseif el == "[C:THEMEBG]" then
  455. term.setTextColor(themehead)
  456. elseif el == "[C:THEMETEXT]" then
  457. term.setTextColor(themetext)
  458. elseif el == "[C:THEMEDANGER]" then
  459. term.setTextColor(themedang)
  460. elseif el == "[HL:BLACK]" then
  461. term.setBackgroundColor(32768)
  462. elseif el == "[HL:RED]" then
  463. term.setBackgroundColor(16384)
  464. elseif el == "[HL:GREEN]" then
  465. term.setBackgroundColor(8192)
  466. elseif el == "[HL:BROWN]" then
  467. term.setBackgroundColor(4096)
  468. elseif el == "[HL:BLUE]" then
  469. term.setBackgroundColor(2048)
  470. elseif el == "[HL:PURPLE]" then
  471. term.setBackgroundColor(1024)
  472. elseif el == "[HL:CYAN]" then
  473. term.setBackgroundColor(512)
  474. elseif el == "[HL:LIGHTGRAY]" or el == "[HL:LIGHTGREY]" then
  475. term.setBackgroundColor(256)
  476. elseif el == "[HL:DARKGRAY]" or el == "[HL:DARKGREY]" or el == "[HL:GRAY]" or el == "[HL:GREY]" then
  477. term.setBackgroundColor(128)
  478. elseif el == "[HL:PINK]" then
  479. term.setBackgroundColor(64)
  480. elseif el == "[HL:LIME]" then
  481. term.setBackgroundColor(32)
  482. elseif el == "[HL:YELLOW]" then
  483. term.setBackgroundColor(16)
  484. elseif el == "[HL:LIGHTBLUE]" then
  485. term.setBackgroundColor(8)
  486. elseif el == "[HL:MAGENTA]" then
  487. term.setBackgroundColor(4)
  488. elseif el == "[HL:ORANGE]" then
  489. term.setBackgroundColor(2)
  490. elseif el == "[HL:WHITE]" then
  491. term.setBackgroundColor(1)
  492. elseif el == "[HL:THEMEFG]" then
  493. term.setBackgroundColor(themefore)
  494. elseif el == "[HL:THEMEDISABLED]" then
  495. term.setBackgroundColor(themeback)
  496. elseif el == "[HL:THEMEBG]" then
  497. term.setBackgroundColor(themehead)
  498. elseif el == "[HL:THEMETEXT]" then
  499. term.setBackgroundColor(themetext)
  500. elseif el == "[HL:THEMEDANGER]" then
  501. term.setBackgroundColor(themedang)--[[ old method
  502. elseif el == "[CENTER]" then
  503. local ox, oy = term.getCursorPos()
  504. if ox ~= 1 then term.setCursorPos(1,1+oy) end
  505. centerText(page:sub(9,-2+tag+page:find("%[/CENTER%]")))
  506. page = page:sub(tag+page:find("%[/CENTER"))
  507. term.setCursorPos(1,1+oy)
  508. if ox ~= 1 then term.setCursorPos(1,2+oy) end]]--
  509. elseif el == "[P]" or el == "[CELL:51]" then
  510. if paragraph == 0 then
  511. local ox, oy = term.getCursorPos()
  512. cellstart = ox
  513. paragraph = 51
  514. else
  515. crash(1)
  516. break
  517. end
  518. elseif el == "[/P]" or el == "[/CELL]" then
  519. if paragraph == 0 then
  520. paragraph = 0
  521. else crash(2) return false end
  522. elseif el == "[CENTER]" then
  523. if align == 1 then
  524. local ox, oy = term.getCursorPos()
  525. if ox ~= 1 then term.setCursorPos(1,1+oy) end
  526. align = 2
  527. wid = string.len(stripTags(page:sub(1,page:find("%[/CENTER%]"))))
  528. elseif align == 2 then
  529. crash(1)
  530. break
  531. end
  532. elseif el == "[/CENTER]" then
  533. if align == 2 then
  534. local ox, oy = term.getCursorPos()
  535. align = 1
  536. term.setCursorPos(1,1+oy)
  537. offset = 0
  538. else crash(2) return false end
  539. elseif el == "[UP]" then
  540. local ox, oy = term.getCursorPos()
  541. term.setCursorPos(ox,oy-1)
  542. elseif el == "[CR]" then
  543. local ox, oy = term.getCursorPos()
  544. term.setCursorPos(1,oy)
  545. elseif el == "[BR]" then
  546. local ox, oy = term.getCursorPos()
  547. term.setCursorPos(1,oy+1)
  548. elseif el == "[LF]" then
  549. local ox, oy = term.getCursorPos()
  550. term.setCursorPos(ox,oy+1)
  551. elseif el == "[TOP]" then
  552. local ox, oy = term.getCursorPos()
  553. term.setCursorPos(1,4)
  554. elseif el == "[END]" then
  555. break--[[
  556. elseif el == "[PROBLEM]" then
  557. if align ~= 1 then crash(1) return false end
  558. --if issue == 0 then crash(6) return false end
  559. term.write(string.format("%03d",tostring(issue)))
  560. term.write(" "..getError(issue))--]]
  561. elseif el == "[IMAGE]" then
  562. local ox, oy = term.getCursorPos()
  563. local src = ""
  564. local url = page:sub(8,-1+page:find("%[/IMAGE%]"))
  565. local islocal = false
  566. local img = ""
  567. if url:sub(1,7) == "http://" then
  568. src = url
  569. elseif url:sub(1,8) == "scape://" then
  570. src = url
  571. islocal = true
  572. else
  573. src = string.sub(literal[activetab],1,-string.find(literal[activetab]:reverse(),"/"))..page:sub(8,-1+page:find("%[/IMAGE%]"))
  574. if src:sub(1,8) == "scape://" then islocal = true end
  575. end
  576. log(src)
  577. if islocal then
  578. src = src:sub(8)
  579. img = readconfig("pages/"..src)
  580. else
  581. print(src)
  582. img = http.get(src).readAll()
  583. end
  584. local filetype = string.sub(src,1-string.find(src:reverse(),"%."))
  585. if filetype == "nfp" then
  586. if islocal then
  587. --img = paintutils.loadImage(src)
  588. paintutils.drawImage(paintutils.loadImage("kst/pages/"..src),ox,oy)
  589. else crash(8) return false end
  590. else
  591. crash(7)
  592. end
  593. page = page:sub(1+page:find("%[/IMAGE"))
  594. elseif el == "[DONTCOLORLINKS]" then
  595. dontcolorlinks = true
  596. elseif el == "[COLORLINKS]" then
  597. dontcolorlinks = false
  598. elseif el == "[A]" then
  599. links[activetab][0] = links[activetab][0] + 1
  600. links[activetab][links[activetab][0]] = {}
  601. links[activetab][links[activetab][0]][0], links[activetab][links[activetab][0]][1] = term.getCursorPos()
  602. links[activetab][links[activetab][0]][2] = page:sub(4,-1+page:find(" "))
  603. page = page:sub(1+page:find(" "))
  604. if not dontcolorlinks then term.setTextColor(512) end
  605. elseif el == "[/A]" then
  606. local linklen = term.getCursorPos()
  607. links[activetab][links[activetab][0]][3] = linklen + links[activetab][links[activetab][0]][1] - 1
  608. end
  609. if el ~= "[A]" then page = page:sub(tag+page:find("%]")) end
  610. end
  611. end
  612. end
  613. end
  614. function go()
  615. --issue = 0
  616. ui()
  617. local event, param1, param2, param3 = os.pullEvent()
  618. if event == "mouse_click" and param1 == 1 then
  619. if param2 > 2 and param2 < 38 and param3 == 2 then
  620. if not editing then
  621. editing = true
  622. address[0] = address[activetab]
  623. else
  624. if selected then selected = false else selected = true end
  625. end
  626. elseif address[activetab] ~= "" and param2 > 44 and param2 < 47 and param3 == 2 then
  627. selected = false
  628. editing = false
  629. address[activetab] = fixaddress(address[0])
  630. refresh(address[activetab])
  631. else
  632. editing = false
  633. selected = false
  634. if param2 < 51 and (param2 - 2) % 17 < 15 and param3 == 1 then
  635. local tabclicked = 1 + math.floor((param2 - 2) / 17)
  636. if (param2 - 2) % 17 == 14 and tabclicked <= tabs then
  637. if tabs * 2 == tabclicked + activetab then
  638. activetab = activetab - 1
  639. elseif tabclicked == activetab - 1 then
  640. movetab(activetab,tabclicked)
  641. if activetab < 3 and tabs == 3 then movetab(activetab + 1,activetab) end
  642. activetab = activetab - 1
  643. elseif tabclicked == 1 and activetab == 3 then
  644. movetab(2,1)
  645. movetab(3,2)
  646. activetab = 2
  647. elseif 2 == tabclicked + activetab then
  648. movetab(2,1)
  649. movetab(3,2)
  650. else
  651. movetab(3,2)
  652. end
  653. tabs = tabs - 1
  654. else
  655. if tabclicked > tabs then
  656. if (param2 - 2) % 17 < 3 then newtab() end
  657. else
  658. activetab = tabclicked
  659. end
  660. end
  661. end
  662. end
  663. elseif editing and event == "char" then
  664. if selected then
  665. address[0] = param1
  666. selected = false
  667. else
  668. address[0] = address[0]..param1
  669. end
  670. elseif editing and event == "key" then
  671. if param1 == 14 then
  672. if selected then
  673. address[0] = ""
  674. selected = false
  675. else
  676. if string.len(address[0]) > 0 then address[0] = address[0]:sub(1,-2) end
  677. end
  678. elseif param1 == 28 then
  679. selected = false
  680. editing = false
  681. if address[0] ~= "" then
  682. address[activetab] = fixaddress(address[0])
  683. refresh(address[activetab])
  684. end
  685. end
  686. end
  687. end
  688. function ui()
  689. term.setTextColor(themefore)
  690. term.setCursorPos(1,1)
  691. term.setBackgroundColor(themehead)
  692. term.write(" ")
  693. term.setTextColor(themetext)
  694. term.setBackgroundColor(themefore)
  695. term.setCursorPos(1,2)
  696. term.write(" ")
  697. term.setCursorPos(1,3)
  698. term.write(" ")
  699. --address bar and buttons
  700. term.setBackgroundColor(1)
  701. term.setCursorPos(3,2)
  702. term.write(" ")
  703. term.setBackgroundColor(themefore)
  704. term.setCursorPos(39,2)
  705. term.setTextColor(themeback)
  706. if history[activetab][0] > 1 then term.setTextColor(themedang) end
  707. term.write("<-")
  708. term.setCursorPos(42,2)
  709. term.setTextColor(themeback)
  710. term.write("->")
  711. term.setCursorPos(45,2)
  712. term.setTextColor(themeback)
  713. if address[activetab] ~= "" then term.setTextColor(themedang) end
  714. term.write("rf")
  715. term.setCursorPos(48,2)
  716. term.setTextColor(themeback)
  717. term.write("-(")
  718. --tabs
  719. local n = 0
  720. while n < tabs do
  721. term.setTextColor(themetext)
  722. term.setCursorPos((17*n)+2,1)
  723. if activetab == n + 1 then term.setBackgroundColor(themefore) else term.setBackgroundColor(themeback) end
  724. term.write(" ")
  725. term.setCursorPos((17*n)+3,1)
  726. if tostring(string.find(title[1+n],"%[ERROR%]")) ~= "nil" then term.setTextColor(themedang) end
  727. term.write(string.gsub(string.sub(title[1+n],1,12),"%[ERROR%]",""))
  728. term.setCursorPos((17*n)+16,1)
  729. term.setTextColor(themedang)
  730. term.write("x")
  731. if n == tabs - 1 then
  732. term.setCursorPos((17*n)+19,1)
  733. term.setBackgroundColor(themeback)
  734. term.setTextColor(themetext)
  735. term.write(" + ")
  736. end
  737. n = n + 1
  738. end
  739. term.setBackgroundColor(1)
  740. term.setCursorPos(3,2)
  741. if editing then
  742. term.setTextColor(themedang)
  743. term.write(address[0]:sub(-33))
  744. if not selected then term.write("_") end
  745. else
  746. term.setTextColor(themetext)
  747. term.write(address[activetab]:sub(1,35))
  748. end
  749. if selected then
  750. term.setBackgroundColor(512)
  751. term.setTextColor(1)
  752. term.setCursorPos(3,2)
  753. term.write(address[0]:sub(1,35))
  754. end
  755. term.setBackgroundColor(themefore)
  756. term.setTextColor(themetext)
  757. term.setCursorPos(string.len(title[activetab]),3)
  758. centerText(string.gsub(title[activetab],"%[ERROR%]",""))
  759. if drawn ~= content[activetab] then showsite() end
  760. term.setBackgroundColor(themeback)
  761. term.setTextColor(themefore)
  762. local bar = 0
  763. while bar < 16 do
  764. bar = bar + 1
  765. term.setCursorPos(51,3+bar)
  766. if bar == 1 or bar == 15 then term.write("#") end
  767. if bar == 16 then term.write("_") end
  768. term.write(" ")
  769. end
  770. end
  771. boot()
Advertisement
Add Comment
Please, Sign In to add comment