Advertisement
Guest User

Untitled

a guest
May 28th, 2015
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.26 KB | None | 0 0
  1. local w,C,fa,ka,oa,ra,ua,va,xa,ya,za,Aa,Ca,Da,Ea,Fa,Ja,Ka,Na,Oa,Pa,Qa,Ra,Sa=gpu,lines,term,tags,require,string,0xFFFFFF,winshift,math,winwrite,winhead,0x000000,tonumber,wintext,false,load,tostring,winclear,computer,htmltext,"key_down","component","download","Midday Navigator 1.0"w=oa(Qa).gpu
  2. kbd=oa(Qa).keyboard
  3. Na=oa("computer")fs=oa("filesystem")text=oa("text")fa=oa("term")wlen=oa("unicode").wlen
  4. event=oa("event")on=oa("opennet")local
  5. W,M=1,1
  6. local
  7. ma=0
  8. local
  9. la=0
  10. local
  11. Ia,sa=1,3
  12. local
  13. U,wa=w.getResolution()wa=wa-sa+1
  14. local
  15. Ma=Sa
  16. local
  17. ea=""local
  18. Ba=ua
  19. local
  20. Ha=Aa
  21. local
  22. Ta=0x0080FF
  23. local
  24. na={}local
  25. ta={}function
  26. za()w.setForeground(ua)w.setBackground(0x0000FF)w.fill(1,1,U,1," ")w.set(2,1,Ma)w.setBackground(0x00FF00)w.set(U-8,1," S ")w.setBackground(0x0080FF)w.set(U-5,1," < ")w.setBackground(0xFF0000)w.set(U-2,1," X ")w.setForeground(Aa)w.setBackground(ua)w.fill(1,2,U,1," ")w.set(2,2,ea)w.setForeground(Ba)w.setBackground(Ha)end
  27. function
  28. ya(X)X=text.detab(Ja(X))if
  29. wlen(X)==0
  30. then
  31. return
  32. end
  33. local
  34. B,ja
  35. repeat
  36. if
  37. M>wa
  38. then
  39. return
  40. end
  41. B,X,ja=text.wrap(X,U-(W-2),U)if
  42. M>=1
  43. then
  44. w.set(W+Ia-1-ma,M+sa-1,B)end
  45. W=W+wlen(B)if
  46. ja
  47. or(W>U)then
  48. W=1
  49. M=M+1
  50. end
  51. until
  52. not
  53. X
  54. end
  55. function
  56. Ka()ta={}w.fill(Ia,sa,U,wa," ")W,M=1,1
  57. end
  58. ka={}ka['html']=function(X)if
  59. X.caption
  60. then
  61. Ma=X.caption
  62. za()end
  63. local
  64. B=Ca(X.color)if
  65. B
  66. then
  67. Ba=B
  68. w.setForeground(B)end
  69. B=Ca(X.bgcolor)if
  70. B
  71. then
  72. Ha=B
  73. w.setBackground(B)Ka()end
  74. end
  75. ka['font']=function(X)local
  76. B=Ca(X.color)if
  77. B
  78. then
  79. w.setForeground(B)end
  80. B=Ca(X.bgcolor)if
  81. B
  82. then
  83. w.setBackground(B)end
  84. end
  85. ka['/font']=function()w.setForeground(Ba)w.setBackground(Ha)end
  86. ka['cr']=function()M=M+1
  87. W=1
  88. end
  89. ka['---']=function()if
  90. W>1
  91. then
  92. M=M+1
  93. W=1
  94. end
  95. ya(ra.rep('─',U))end
  96. ka['===']=function()if
  97. W>1
  98. then
  99. M=M+1
  100. W=1
  101. end
  102. ya(ra.rep('═',U))end
  103. local
  104. function
  105. X(B,ja,l)if
  106. l>=B.y1
  107. and
  108. l<=B.y2
  109. then
  110. if(ja>=B.x1
  111. or
  112. l>B.y1)and(ja<=B.x2
  113. or
  114. l<B.y2)then
  115. return
  116. true
  117. end
  118. end
  119. end
  120. local
  121. function
  122. B(ja,l,v)return
  123. v>=ja.y1
  124. and
  125. v<=ja.y2
  126. and
  127. l>=ja.x1
  128. and
  129. l<=ja.x2
  130. end
  131. local
  132. function
  133. ja(l)Fa(l.ref)end
  134. ka['a']=function(l)if
  135. l.ref
  136. then
  137. table.insert(ta,{check=X,x1=W+Ia-1-ma,y1=M+sa-1,work=ja,ref=l.ref,col=w.getForeground()})end
  138. local
  139. v=Ca(l.color)or
  140. Ta
  141. w.setForeground(v)end
  142. ka['/a']=function()local
  143. l=ta[#ta]if
  144. l
  145. and
  146. not
  147. l.x2
  148. then
  149. w.setForeground(l.col
  150. or
  151. Ba)l.x2,l.y2=W+Ia-2-ma,M+sa-1
  152. end
  153. end
  154. function
  155. tagWork(l)local
  156. v=l:match('%S+')if
  157. ka[v]then
  158. local
  159. H={}for
  160. R,ba
  161. in
  162. l:gmatch('(%w+)=([^%s"]+)')do
  163. H[R]=ba
  164. end
  165. for
  166. R,ba
  167. in
  168. l:gmatch('(%w+)="([^"]+)"')do
  169. H[R]=ba
  170. end
  171. ka[v](H)else
  172. ya('<'..l..'>')end
  173. end
  174. function
  175. winline(l)if
  176. l
  177. then
  178. M=l.Y-la
  179. W=l.X
  180. local
  181. v=l.text
  182. while
  183. ra.len(v)>0
  184. do
  185. local
  186. H,R
  187. H=v:find("<")if
  188. H
  189. then
  190. R=v:find(">",H)end
  191. if
  192. R
  193. then
  194. ya(v:sub(1,H-1))tagWork(v:sub(H+1,R-1))v=v:sub(R+1)else
  195. ya(v)v=""end
  196. end
  197. if
  198. M<=wa
  199. then
  200. return
  201. true
  202. end
  203. end
  204. end
  205. function
  206. Oa()Ka()local
  207. l=1
  208. for
  209. v=#C,1,-1
  210. do
  211. if
  212. C[v].Y<=la
  213. then
  214. l=v
  215. break
  216. end
  217. end
  218. while
  219. winline(C[l])do
  220. l=l+1
  221. if
  222. C[l]then
  223. C[l].Y=la+M
  224. C[l].X=W
  225. end
  226. end
  227. end
  228. function
  229. codetext()Ka()for
  230. l=1,wa
  231. do
  232. if
  233. C[l+la]then
  234. w.set(1-ma,l+sa-1,C[l+la].text)else
  235. break
  236. end
  237. end
  238. end
  239. Da=Oa
  240. function
  241. va(l,v)ma=ma+l
  242. la=la+v
  243. if
  244. ma<0
  245. then
  246. ma=0
  247. end
  248. if
  249. la<0
  250. then
  251. la=0
  252. end
  253. Da()end
  254. function
  255. Fa(l)if
  256. l==''or
  257. l==nil
  258. or
  259. l=="\n"then
  260. za()return
  261. end
  262. if
  263. l:sub(-1)=="\n"then
  264. l=l:sub(1,-2)end
  265. C={}ma=0
  266. la=0
  267. Ma=Sa
  268. Ba=ua
  269. Ha=Aa
  270. if
  271. l:sub(1,1)=="."then
  272. while
  273. l:sub(1,1)=="."do
  274. ea=ea:match("(.+)/.*")or
  275. ea
  276. l=l:sub(2)end
  277. ea=ea..l
  278. else
  279. ea=l
  280. end
  281. local
  282. v,H=ea:match('(.-)/(.*)')if
  283. not
  284. v
  285. then
  286. v=ea
  287. H=nil
  288. end
  289. if
  290. v==""then
  291. local
  292. R=io.open(ea,"r")if
  293. R
  294. then
  295. for
  296. ba
  297. in
  298. R:lines()do
  299. C[#C+1]={X=1,Y=xa.huge,text=ba}end
  300. R:close()else
  301. C[1]={X=5,Y=1,text="<html>Файл <font color=0xFF0000>"..ea.."</font> не найден"}end
  302. else
  303. local
  304. R,ba=on.getIP()if
  305. R
  306. then
  307. on.send(v,"get",H)local
  308. J,qa,da
  309. repeat
  310. J,qa,da=on.receive(3)until
  311. qa=="get"or
  312. not
  313. qa
  314. if
  315. qa=="get"then
  316. da=Ja(da)local
  317. Ga=1
  318. while#da>0
  319. do
  320. local
  321. La=da:find("\n")if
  322. La
  323. then
  324. C[Ga],da={X=1,Y=xa.huge,text=da:sub(1,La-1)},da:sub(La+1)else
  325. C[Ga],da={X=1,Y=xa.huge,text=da},""end
  326. Ga=Ga+1
  327. end
  328. else
  329. if
  330. J
  331. then
  332. C[1]={X=1,Y=xa.huge,text="Ответ от узла "..Ja(J)}C[2]={X=1,Y=xa.huge,text=Ja(da)}else
  333. C[1]={X=1,Y=xa.huge,text="Таймаут ожидания"}end
  334. end
  335. else
  336. C[1]={X=5,Y=1,text="<html>Ошибка подключения к сети OpenNet: <font color=0xFF0000>"..ba.."</font>"}end
  337. end
  338. Da=codetext
  339. if
  340. C[1]then
  341. C[1].Y=1
  342. if
  343. ra.find(C[1].text,"<%s*html.*>")then
  344. Da=Oa
  345. end
  346. end
  347. if
  348. na[#na]~=ea
  349. then
  350. table.insert(na,ea)end
  351. za()Da()end
  352. local
  353. l=true
  354. function
  355. read()w.setForeground(Aa)w.setBackground(ua)fa.setCursor(1,2)fa.clearLine()fa.setCursor(2,2)Fa(fa.read(na,Ea))end
  356. function
  357. save()if
  358. kbd
  359. then
  360. w.setForeground(Aa)w.setBackground(ua)fa.setCursor(1,2)fa.clearLine()fa.setCursor(2,2)fa.write("Safe as: ")Na.pushSignal(Pa,kbd.address,0,200)local
  361. v=fa.read({"/download/"..ea:match("[^/]*$")},Ea):sub(1,-2)if
  362. v~=""then
  363. if
  364. not
  365. fs.exists(Ra)then
  366. fs.makeDirectory(Ra)end
  367. local
  368. H=io.open(v,"w")if
  369. H
  370. then
  371. for
  372. R=1,#C-1
  373. do
  374. H:write(C[R].text.."\n")end
  375. H:write(C[#C].text)H:close()else
  376. fa.clearLine()fa.setCursor(2,2)fa.write("File "..v.." can't be saved")Na.beep()os.sleep(2)end
  377. end
  378. za()end
  379. end
  380. function
  381. back()if#na>1
  382. then
  383. na[#na]=nil
  384. Fa(na[#na])end
  385. end
  386. function
  387. quit()w.setForeground(ua)w.setBackground(Aa)fa.clear()l=Ea
  388. end
  389. do
  390. local
  391. v=...if
  392. v
  393. then
  394. Fa(v)else
  395. za()read()end
  396. end
  397. local
  398. v=Ea
  399. while
  400. l
  401. do
  402. local
  403. H,R,ba,J,qa=event.pull()if
  404. H=="scroll"and
  405. J>=sa
  406. then
  407. if
  408. v
  409. then
  410. va(-5*qa,0)else
  411. va(0,-3*qa)end
  412. end
  413. if
  414. H==Pa
  415. then
  416. if
  417. J==208
  418. then
  419. va(0,3)end
  420. if
  421. J==200
  422. then
  423. va(0,-3)end
  424. if
  425. J==203
  426. then
  427. va(-5,0)end
  428. if
  429. J==205
  430. then
  431. va(5,0)end
  432. if
  433. J==29
  434. then
  435. v=true
  436. end
  437. if
  438. J==15
  439. then
  440. read()end
  441. if
  442. v
  443. and
  444. J==31
  445. then
  446. save()end
  447. if
  448. J==14
  449. then
  450. back()end
  451. if
  452. v
  453. and
  454. J==17
  455. then
  456. quit()end
  457. end
  458. if
  459. H=="key_up"and
  460. J==29
  461. then
  462. v=Ea
  463. end
  464. if
  465. H=="touch"and
  466. qa==0
  467. then
  468. if
  469. J==1
  470. then
  471. if
  472. ba>=U-8
  473. and
  474. ba<=U-6
  475. then
  476. save()end
  477. if
  478. ba>=U-5
  479. and
  480. ba<=U-3
  481. then
  482. back()end
  483. if
  484. ba>=U-2
  485. then
  486. quit()end
  487. elseif
  488. J==2
  489. then
  490. read()else
  491. for
  492. da=1,#ta
  493. do
  494. if
  495. ta[da]:check(ba,J)then
  496. ta[da]:work()break
  497. end
  498. end
  499. end
  500. end
  501. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement