Advertisement
TwiXon4ik

Untitled

Oct 9th, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.40 KB | None | 0 0
  1. --|============================|
  2. --| Библа. |
  3. --| Автор: SkyDrive_ |
  4. --| Проект McSkill, cервер HTC |
  5. --| 17.04.2017 |
  6. --| Version: 1.21 |
  7. --|============================|
  8. local Sky = {}
  9. local component = require("component")
  10. local computer=require("computer")
  11. local serial = require("serialization")
  12. local term = require("term")
  13. local event = require("event")
  14. local unicode = require("unicode")
  15. local fs = require("filesystem")
  16. local internet = require("internet")
  17. local g = component.gpu
  18. local back = 0xffffff
  19.  
  20. function Sky.Resolution(w,h) --Резоль
  21. if w < 48 then
  22. w = 48 end
  23. if h < 3 then
  24. h = 3 end
  25. g.setResolution(w,h)
  26. return w,h
  27. end
  28.  
  29. function Sky.Mid(w,y,text) --Центровка по центру (Если рамка одинарная)
  30. local _,n = string.gsub(text, "&","")
  31. local l = unicode.len(text) - n * 2
  32. x = (w / 2) - (l / 2)
  33. Sky.Text(x, y, text)
  34. end
  35.  
  36. function Sky.MidL(w,y,text) --Центровка слева
  37. local _,n = string.gsub(text, "&","")
  38. local l = unicode.len(text) - n * 2
  39. x = 13 - (l / 2)
  40. Sky.Text(x+2, y, text)
  41. end
  42.  
  43. function Sky.MidR(w,y,text) --Центровка справа
  44. local _,n = string.gsub(text, "&","")
  45. local l = unicode.len(text) - n * 2
  46. x = ((w - 34) / 2) - (l / 2)
  47. Sky.Text(x+31, y, text)
  48. end
  49.  
  50. function Sky.DrawImage(x,y,path) --Отрисовка картинок
  51. local back, font = g.getBackground(), g.getForeground()
  52. if (fs.exists(path)) then
  53. local start_x = x
  54. local image
  55. local text = ""
  56. local file = fs.open(path)
  57. while true do
  58. local temp = file:read(9999999)
  59. if (temp) then
  60. text = text .. temp
  61. else
  62. break
  63. end
  64. end
  65. local text2 = "{" .. text .. "}"
  66. image = serial.unserialize(text2)
  67. for i = 1, #image / 2 do
  68. x = start_x
  69. for j = 1, #image[i] do
  70. g.setBackground(image[i * 2 - 1][j])
  71. g.setForeground(image[i * 2][j])
  72. g.set(x,y,"▄")
  73. x = x + 1
  74. end
  75. y = y + 1
  76. end
  77. end
  78. g.setBackground(back)
  79. g.setForeground(font)
  80. end
  81.  
  82. function Sky.Com(command) --Выполнить команду
  83. if (component.isAvailable("opencb")) then
  84. local _,c = component.opencb.execute(command)
  85. return c
  86. end
  87. end
  88.  
  89. function Sky.Money(nick) --Баланс игрока
  90. local c = Sky.Com("money " .. nick)
  91. local _, b = string.find(c, "Баланс: §f")
  92. local balance
  93. if string.find(c, "Emeralds") ~= nil then
  94. balance = unicode.sub(c, b - 16, unicode.len(c) - 10)
  95. else
  96. balance = unicode.sub(c, b - 16, unicode.len(c) - 9)
  97. end
  98. return (balance)
  99. end
  100.  
  101. function Sky.Check_money(nick,price) --Чекнуть, баланс, если хватает, то снять бабки
  102. local balance = Sky.Money(nick)
  103. balance = string.sub(balance, 1, string.len(balance) - 3)
  104. if string.find(balance, "-") ~= nil then
  105. return false
  106. else
  107. balance = string.gsub(balance,",","")
  108. if tonumber(balance) < price then
  109. return false
  110. else
  111. Sky.Com("money take " .. nick .. " " .. price)
  112. return true
  113. end
  114. end
  115. end
  116.  
  117. function Sky.Ram(name,col1,col2,w,h,double) --Рамка P.S. Луфф питух
  118. term.clear()
  119. g.setBackground(0x000000)
  120. g.setForeground(col2)
  121. for i = 1, w do
  122. g.set(i,1,"=")
  123. g.set(i,h,"=")
  124. end
  125. for i = 1, h do
  126. g.set(1, i, "||")
  127. if double == nil then
  128. g.set(29, i, "||")
  129. end
  130. g.set(w-1, i, "||")
  131. end
  132. if double == nil then
  133. Sky.MidR(w,1,"[ " .. name .. " ]")
  134. else
  135. Sky.Text(w/2 - unicode.len("[ " .. name .. " ]")/2,1,"[ " .. name .. " ]")
  136. end
  137. g.set(w-42,h,"[ Автор: SkyDrive_ mod: isl02 ]")
  138. g.setForeground(col1)
  139. if double == nil then
  140. Sky.MidR(w,1,name)
  141. else
  142. Sky.Text(w/2 - unicode.len(name)/2,1,name)
  143. end
  144. g.set(w-40,h,"Автор: SkyDrive_ mod: isl02 ")
  145. end
  146.  
  147. function Sky.SetColor(index) --Список цветов
  148. if (index ~= "r") then back = g.getForeground() end
  149. if (index == "0") then g.setForeground(0x333333) end
  150. if (index == "1") then g.setForeground(0x0000ff) end
  151. if (index == "2") then g.setForeground(0x00ff00) end
  152. if (index == "3") then g.setForeground(0x24b3a7) end
  153. if (index == "4") then g.setForeground(0xff0000) end
  154. if (index == "5") then g.setForeground(0x8b00ff) end
  155. if (index == "6") then g.setForeground(0xffa500) end
  156. if (index == "7") then g.setForeground(0xbbbbbb) end
  157. if (index == "8") then g.setForeground(0x808080) end
  158. if (index == "9") then g.setForeground(0x0000ff) end
  159. if (index == "a") then g.setForeground(0x66ff66) end
  160. if (index == "b") then g.setForeground(0x00ffff) end
  161. if (index == "c") then g.setForeground(0xff6347) end
  162. if (index == "d") then g.setForeground(0xff00ff) end
  163. if (index == "e") then g.setForeground(0xffff00) end
  164. if (index == "f") then g.setForeground(0xffffff) end
  165. if (index == "g") then g.setForeground(0x00ff00) end
  166. if (index == "r") then g.setForeground(back) end
  167. end
  168.  
  169. function Sky.Text(x,y,text) --Цветной текст
  170. local n = 1
  171. for i = 1, unicode.len(text) do
  172. if unicode.sub(text, i,i) == "&" then
  173. Sky.SetColor(unicode.sub(text, i + 1, i + 1))
  174. elseif unicode.sub(text, i - 1, i - 1) ~= "&" then
  175. g.set(x+n,y, unicode.sub(text, i,i))
  176. n = n + 1
  177. end
  178. end
  179. end
  180.  
  181. function Sky.Button(x,y,w,h,col1,col2,text) -- Кнопка
  182. g.setForeground(col1)
  183. g.set(x + w/2 - unicode.len(text)/2, y+h/2, text)
  184. g.setForeground(col2)
  185. for i = 1, w-2 do
  186. g.set(x+i,y,"─")
  187. g.set(x+i,y+h-1,"─")
  188. end
  189. for i = 1, h-2 do
  190. g.set(x,y+i,"│")
  191. g.set(x+w-1,y+i,"│")
  192. end
  193. g.set(x,y,"┌")
  194. g.set(x+w-1,y,"┐")
  195. g.set(x,y+h-1,"└")
  196. g.set(x+w-1,y+h-1,"┘")
  197. end
  198.  
  199. function Sky.TakeItem(nick, item, numb) --Забрать итем
  200. if string.find(Sky.Com("clear " .. nick .. " " .. item .. " " .. numb), "Убрано") ~= nil then
  201. return true
  202. else
  203. return false
  204. end
  205. end
  206.  
  207. function Sky.ClearL(h) --Очистка левой части
  208. g.fill(3,2,26,h-2," ")
  209. end
  210.  
  211. function Sky.ClearR(w,h) --Очистка правой части
  212. g.fill(31,2,w-32,h-2," ")
  213. end
  214.  
  215. function Sky.Math_round(roundIn , roundDig) --Округлить число
  216. local mul = math.pow(10, roundDig)
  217. return ( math.floor(( roundIn * mul) + 0.5)/mul)
  218. end
  219.  
  220. function Sky.Swap(array, index1, index2) --Свап
  221. array[index1], array[index2] = array[index2], array[index1]
  222. end
  223.  
  224. function Sky.Shake(array) --Шафл
  225. local counter = #array
  226. while counter > 1 do
  227. local index = math.random(counter)
  228. Sky.Swap(array, index, counter)
  229. counter = counter - 1
  230. end
  231. end
  232.  
  233. function Sky.Get(url, filename,x,y) --Получить поток
  234. local f, reason = io.open(filename, "w")
  235. if not f then
  236. g.set(x,y," Ошибка чтения файла ")
  237. os.sleep(2)
  238. return
  239. end
  240.  
  241. g.set(x,y," Идёт скачивание... ")
  242. os.sleep(2)
  243. local result, response = pcall(internet.request, url)
  244. if result then
  245. g.set(x,y," Файл успешно загружен ")
  246. os.sleep(2)
  247. for chunk in response do
  248. f:write(chunk)
  249. end
  250. f:close()
  251. else
  252. f:close()
  253. fs.remove(filename)
  254. g.set(x,y," HTTP запрос не дал результатов ")
  255. os.sleep(2)
  256. end
  257. end
  258.  
  259. function Sky.Run(url, ...) --Запуск и удаление файла
  260. local tmpFile = os.tmpname()
  261. Sky.Read(url, tmpFile)
  262. term.clear() -- <=== Очистка экрана перед запуском проги, если чё, она тута
  263. local success, reason = shell.execute(tmpFile, nil, ...)
  264. if not success then
  265. --mid(23," Битый файлик ")
  266. --os.sleep(2)
  267. end
  268. fs.remove(tmpFile)
  269. end
  270.  
  271. function Sky.CheckOP(nick) --Чек на опку
  272. return true
  273. end
  274.  
  275. function Sky.Playtime(nick) --Плейтайм
  276. local c = Sky.Com("playtime " .. nick)
  277. local _, b = string.find(c, "на сервере ")
  278. if string.find(c, "час") then
  279. local text = string.sub(c, b+1, string.find(c, " час"))
  280. return text .. " ч."
  281. else
  282. local text = string.sub(c, b+1, string.find(c, " минут"))
  283. return text .. " мин."
  284. end
  285.  
  286. end
  287.  
  288. function Sky.CheckMute(nick) --Чекнуть висит ли мут
  289. local c = Sky.Com("checkban " .. nick)
  290. if string.find(c, "Muted: §aFalse") ~= nil then
  291. return false
  292. else
  293. return true
  294. end
  295. end
  296.  
  297. function Sky.GetHostTime(timezone) --Получить текущее реальное время компьютера, хостящего сервер майна
  298. timezone = timezone or 2
  299. local file = io.open("/HostTime.tmp", "w")
  300. file:write("123")
  301. file:close()
  302. local timeCorrection = timezone * 3600
  303. local lastModified = tonumber(string.sub(fs.lastModified("/HostTime.tmp"), 1, -4)) + timeCorrection
  304. fs.remove("HostTime.tmp")
  305. local year, month, day, hour, minute, second = os.date("%Y", lastModified), os.date("%m", lastModified), os.date("%d", lastModified), os.date("%H", lastModified), os.date("%M", lastModified), os.date("%S", lastModified)
  306. return tonumber(day), tonumber(month), tonumber(year), tonumber(hour), tonumber(minute), tonumber(second)
  307. end
  308.  
  309. function Sky.Time(timezone) --Получет настоящее время, стоящее на Хост-машине
  310. local time = {Sky.GetHostTime(timezone)}
  311. local text = string.format("%02d:%02d:%02d", time[4], time[5], time[6])
  312. return text
  313. end
  314.  
  315. function Sky.Hex(Hcolor) --Конвертация Dec в Hex
  316. local hex = "000000" .. string.format('%x', Hcolor)
  317. hex = string.sub(hex, unicode.len(hex)-5, unicode.len(hex))
  318. return hex
  319. end
  320.  
  321. function Sky.Dec(Dcolor) --Конвертация Hex в Dec
  322. if Dcolor == "" then
  323. Dcolor = "ffffff"
  324. end
  325. local dec = string.format('%d', '0x'.. Dcolor)
  326. return tonumber(dec)
  327. end
  328.  
  329. function Sky.TF(value) --Если false, то вернёт true и наоборот
  330. if value then
  331. return false
  332. end
  333. return true
  334. end
  335.  
  336. function Sky.Palitra(col) --Палитра
  337. local OldColor = g.getForeground()
  338. if col ~= nil then
  339. OldColor = col
  340. NewColor = col
  341. end
  342. local NewColor = g.getForeground()
  343. local x,y = g.getResolution()
  344. x = x/2-14
  345. y = y/2-5
  346. local palitra = {
  347. {0x9b2d30, 0xff0000, 0xff9900, 0xffff00},
  348. {0x66ff00, 0x008000, 0x00ffff, 0x0000ff},
  349. {0x00cccc, 0x8b00ff, 0xff00ff, 0xf78fa7},
  350. {0x666666, 0x222222, 0xffffff},
  351. }
  352.  
  353. g.setForeground(0x333333)
  354.  
  355. g.set(x,y, "█▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█▀▀▀▀▀▀▀▀█")
  356. g.set(x,y+1,"█ █ ██████ █")
  357. g.set(x,y+2,"█ █ ██████ █")
  358. g.set(x,y+3,"█ █▄▄▄▄▄▄▄▄█")
  359. g.set(x,y+4,"█ █ █")
  360. g.set(x,y+5,"█ █ █")
  361. g.set(x,y+6,"█ █ █")
  362. g.set(x,y+7,"█ █ Ок █")
  363. g.set(x,y+8,"█▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█▄▄▄▄▄▄▄▄█")
  364.  
  365. for i = 1, #palitra do
  366. for j = 1, #palitra[i] do
  367. g.setForeground(palitra[i][j])
  368. g.set(j*4-4+x+2,i*2-2+y+1, "██")
  369. end
  370. end
  371.  
  372. g.setForeground(OldColor)
  373. g.set(x+19,y+1,"██████")
  374. g.set(x+19,y+2,"██████")
  375. g.set(x+19, y+5, Sky.Hex(OldColor))
  376.  
  377. while true do
  378. local e,_,w,h = event.pull("touch")
  379. if e == "touch" then
  380. for i = 1, #palitra do
  381. for j = 1, #palitra[i] do
  382. if w>=j*4-4+x+2 and w<=j*4-4+x+3 and h==i*2-2+y+1 then
  383. NewColor = palitra[i][j]
  384. g.setForeground(NewColor)
  385. g.set(x+19,y+1,"██████")
  386. g.set(x+19,y+2,"██████")
  387. g.set(x+19, y+5, Sky.Hex(NewColor))
  388. end
  389. end
  390. end
  391. if w>=x+19 and w<=x+24 and h==y+5 then
  392. g.set(x+19,y+5," ")
  393. term.setCursor(x+19,y+5)
  394. NewColor = Sky.Read({max = 6, accept = "0-9a-f", blink = true})
  395. NewColor = Sky.Dec(NewColor)
  396. g.setForeground(NewColor)
  397. g.set(x+19,y+1,"██████")
  398. g.set(x+19,y+2,"██████")
  399. g.set(x+19, y+5, Sky.Hex(NewColor))
  400. elseif w>=x+21 and w<=x+22 and h==y+7 then
  401. g.setForeground(OldColor)
  402. g.fill(x,y,x+26,y+8," ")
  403. return NewColor
  404. end
  405. end
  406. end
  407. end
  408.  
  409. function Sky.PressButton(Pw,Ph,mass)
  410. local x,y,w,h = mass[1], mass[2], mass[3], mass[4]
  411. if Pw>=x and Pw<=x+w-1 and Ph>=y and Ph<=y+h-1 then
  412. return true
  413. end
  414. return false
  415. end
  416.  
  417. function Sky.DrawButton(mass)
  418. local x,y,w,h,text,col1,col2 = mass[1], mass[2], mass[3], mass[4], mass[5], mass[6], mass[7]
  419. g.fill(x,y,w,h," ")
  420. g.setForeground(col1)
  421. g.set(x + w/2 - unicode.len(text)/2, y+h/2, text)
  422. g.setForeground(col2)
  423. for i = 1, w-2 do
  424. g.set(x+i,y,"─")
  425. g.set(x+i,y+h-1,"─")
  426. end
  427. for i = 1, h-2 do
  428. g.set(x,y+i,"│")
  429. g.set(x+w-1,y+i,"│")
  430. end
  431. g.set(x,y,"┌")
  432. g.set(x+w-1,y,"┐")
  433. g.set(x,y+h-1,"└")
  434. g.set(x+w-1,y+h-1,"┘")
  435. end
  436.  
  437. function Sky.PressSwitch(Pw,Ph, mass)
  438. local x,y = mass[1], mass[2]
  439. if Pw>=x and Pw<=x+4 and Ph>=y and Ph<=y+2 then
  440. return true
  441. end
  442. return false
  443. end
  444.  
  445. function Sky.DrawSwitch(mass) --Свич
  446. local x,y,col1,col2,value = mass[1], mass[2], mass[3], mass[4], mass[5]
  447. g.setForeground(col2)
  448. g.set(x,y, "┌───┐")
  449. g.set(x,y+1,"│ │")
  450. g.set(x,y+2,"└───┘")
  451. if value == true then
  452. g.setForeground(col1)
  453. g.set(x+2,y+1,"√")
  454. elseif value ~= false then
  455. g.setForeground(value)
  456. g.set(x+1,y+1,"▐█▌")
  457. g.setForeground(col2)
  458. end
  459. end
  460.  
  461. function Sky.Word(x,y,text,ramka) --Шрифт
  462. text = unicode.lower(text)
  463. for i = 1, unicode.len(text) do
  464. Sky.Symbol(i*8-8 + x, y, string.sub(text,i,i), ramka)
  465. end
  466. end
  467.  
  468. function Sky.Symbol(x,y,symbol,ramka) --Символы шрифта
  469. local WBack = g.getBackground()
  470.  
  471. if ramka ~= nil then
  472. local WColor = g.getForeground()
  473. g.setForeground(ramka)
  474. g.set(x,y, "███████")
  475. g.set(x,y+1,"███████")
  476. g.set(x,y+2,"███████")
  477. g.set(x,y+3,"▀▀▀▀▀▀▀")
  478. g.setBackground(ramka)
  479. g.setForeground(WColor)
  480. end
  481.  
  482. if symbol == "a" then
  483. g.set(x+1,y, "▄▄▄▄▄")
  484. g.set(x+1,y+1,"█▄▄▄█")
  485. g.set(x+1,y+2,"█ █")
  486. elseif symbol == "b" then
  487. g.set(x+1,y, "▄▄▄▄")
  488. g.set(x+1,y+1,"█▄▄█▄")
  489. g.set(x+1,y+2,"█▄▄▄█")
  490. elseif symbol == "c" then
  491. g.set(x+1,y, "▄▄▄▄▄")
  492. g.set(x+1,y+1,"█")
  493. g.set(x+1,y+2,"█▄▄▄▄")
  494. elseif symbol == "d" then
  495. g.set(x+1,y, "▄▄▄▄")
  496. g.set(x+1,y+1,"█ █")
  497. g.set(x+1,y+2,"█▄▄▄▀")
  498. elseif symbol == "e" then
  499. g.set(x+1,y, "▄▄▄▄▄")
  500. g.set(x+1,y+1,"█▄▄▄")
  501. g.set(x+1,y+2,"█▄▄▄▄")
  502. elseif symbol == "f" then
  503. g.set(x+1,y, "▄▄▄▄▄")
  504. g.set(x+1,y+1,"█▄▄")
  505. g.set(x+1,y+2,"█")
  506. elseif symbol == "g" then
  507. g.set(x+1,y, "▄▄▄▄▄")
  508. g.set(x+1,y+1,"█ ▄▄")
  509. g.set(x+1,y+2,"█▄▄▄█")
  510. elseif symbol == "h" then
  511. g.set(x+1,y, "▄ ▄")
  512. g.set(x+1,y+1,"█▄▄▄█")
  513. g.set(x+1,y+2,"█ █")
  514. elseif symbol == "i" then
  515. g.set(x+2,y, "▄▄▄")
  516. g.set(x+2,y+1," █")
  517. g.set(x+2,y+2,"▄█▄")
  518. elseif symbol == "j" then
  519. g.set(x+1,y, "▄▄▄▄▄")
  520. g.set(x+1,y+1," █")
  521. g.set(x+1,y+2,"█▄▄▄█")
  522. elseif symbol == "k" then
  523. g.set(x+1,y, "▄ ▄")
  524. g.set(x+1,y+1,"█▄▀")
  525. g.set(x+1,y+2,"█ ▀▄")
  526. elseif symbol == "l" then
  527. g.set(x+1,y, "▄")
  528. g.set(x+1,y+1,"█")
  529. g.set(x+1,y+2,"█▄▄▄")
  530. elseif symbol == "m" then
  531. g.set(x+1,y, "▄ ▄")
  532. g.set(x+1,y+1,"█▀▄▀█")
  533. g.set(x+1,y+2,"█ █")
  534. elseif symbol == "n" then
  535. g.set(x+1,y, "▄▄ ▄")
  536. g.set(x+1,y+1,"█ █ █")
  537. g.set(x+1,y+2,"█ ▀█")
  538. elseif symbol == "o" then
  539. g.set(x+1,y, "▄▄▄▄▄")
  540. g.set(x+1,y+1,"█ █")
  541. g.set(x+1,y+2,"█▄▄▄█")
  542. elseif symbol == "p" then
  543. g.set(x+1,y, "▄▄▄▄▄")
  544. g.set(x+1,y+1,"█▄▄▄█")
  545. g.set(x+1,y+2,"█")
  546. elseif symbol == "q" then
  547. g.set(x+1,y, "▄▄▄▄▄")
  548. g.set(x+1,y+1,"█ █")
  549. g.set(x+1,y+2,"█▄▄██")
  550. elseif symbol == "r" then
  551. g.set(x+1,y, "▄▄▄▄▄")
  552. g.set(x+1,y+1,"█▄▄▄█")
  553. g.set(x+1,y+2,"█ ▀▄")
  554. elseif symbol == "s" then
  555. g.set(x+1,y, "▄▄▄▄▄")
  556. g.set(x+1,y+1,"█▄▄▄▄")
  557. g.set(x+1,y+2,"▄▄▄▄█")
  558. elseif symbol == "t" then
  559. g.set(x+1,y, "▄▄▄▄▄")
  560. g.set(x+1,y+1," █")
  561. g.set(x+1,y+2," █")
  562. elseif symbol == "u" then
  563. g.set(x+1,y, "▄ ▄")
  564. g.set(x+1,y+1,"█ █")
  565. g.set(x+1,y+2,"▀▄▄▄▀")
  566. elseif symbol == "v" then
  567. g.set(x+1,y, "▄ ▄")
  568. g.set(x+1,y+1,"█ █")
  569. g.set(x+1,y+2," ▀▄▀")
  570. elseif symbol == "w" then
  571. g.set(x+1,y, "▄ ▄")
  572. g.set(x+1,y+1,"█ █ █")
  573. g.set(x+1,y+2,"▀▄█▄▀")
  574. elseif symbol == "x" then
  575. g.set(x+1,y, "▄ ▄")
  576. g.set(x+1,y+1," ▀▄▀")
  577. g.set(x+1,y+2,"▄▀ ▀▄")
  578. elseif symbol == "y" then
  579. g.set(x+1,y, "▄ ▄")
  580. g.set(x+1,y+1," ▀▄▀ ")
  581. g.set(x+1,y+2," █")
  582. elseif symbol == "z" then
  583. g.set(x+1,y, "▄▄▄▄▄")
  584. g.set(x+1,y+1," ▄▄▄▀")
  585. g.set(x+1,y+2,"█▄▄▄▄")
  586. end
  587. g.setBackground(WBack)
  588. end
  589.  
  590. function Sky.Read(settings)
  591. --mask, max, rim - returnIfMax, accept, blink, center, nick, clip
  592. if not settings then
  593. settings = {}
  594. end
  595. local nextBlink = 0
  596. if not settings.text then
  597. settings.text = ""
  598. end
  599. if settings.blink ~= false then
  600. settings.blink = true
  601. end
  602. if settings.max then
  603. settings.max = settings.max - 1
  604. end
  605. local sx, sy = term.getCursor()
  606. local oldFg = g.getForeground()
  607. local oldBg = g.getBackground()
  608. local SX = sx
  609. while true do
  610. if settings.center then
  611. SX = sx - unicode.len(settings.text) / 2
  612. end
  613. local event, address, char, code, nick = event.pull(settings.blink and math.min(0, nextBlink - computer.uptime())) --, "key_down"
  614. if char == 13 and event == "key_down" then
  615. local char, fg, bg = g.get(SX + unicode.len(settings.text), sy)
  616. if settings.center then
  617. SX = sx - unicode.len(settings.text) / 2
  618. end
  619. g.set(SX + unicode.len(settings.text), sy, char or " ")
  620. if settings.nick then
  621. return settings.text, nick
  622. end
  623. return settings.text
  624. elseif char == 8 and event == "key_down" then
  625. settings.text = unicode.sub(settings.text, 1, -2)
  626. if settings.center then
  627. SX = sx - unicode.len(settings.text) / 2
  628. end
  629. g.set(SX, sy, (not settings.mask and settings.text or settings.mask:rep(unicode.len(settings.text))) .. " ")
  630. if settings.center then
  631. g.set(SX-1, sy, " ")
  632. end
  633. elseif char and char ~= 0 and event == "key_down" then
  634. local acceptRegx = settings.accept and ("[" .. settings.accept .. "]") or "."
  635. if unicode.char(char):find(acceptRegx) then
  636. if settings.max and settings.max >= unicode.len(settings.text) then
  637. settings.text = settings.text .. unicode.char(char)
  638. if settings.center then
  639. SX = sx - unicode.len(settings.text) / 2
  640. end
  641. g.set(SX, sy, not settings.mask and settings.text or settings.mask:rep(unicode.len(settings.text)))
  642. if settings.max and settings.rim and settings.max == unicode.len(settings.text) then
  643. local char, fg, bg = g.get(SX + unicode.len(settings.text), sy)
  644. g.set(SX + unicode.len(settings.text), sy, char or " ")
  645. return settings.text
  646. end
  647. end
  648. end
  649. elseif event == "clipboard" and settings.clip then
  650. settings.text = settings.text .. char
  651. if settings.max and settings.max < unicode.len(settings.text) then
  652. settings.text = string.sub(settings.text, 1, settings.max - 3) .. "..."
  653. end
  654. if settings.center then
  655. SX = sx - unicode.len(settings.text) / 2
  656. end
  657. g.set(SX, sy, not settings.mask and settings.text or settings.mask:rep(unicode.len(settings.text)))
  658. end
  659.  
  660. if settings.blink and nextBlink <= computer.uptime() then
  661. oldFg = g.getForeground()
  662. oldBg = g.getBackground()
  663. local char, fg, bg = g.get(SX + unicode.len(settings.text), sy)
  664. g.setForeground(bg)
  665. g.setBackground(fg)
  666. g.set(SX + unicode.len(settings.text), sy, char or " ")
  667. g.setForeground(oldFg)
  668. g.setBackground(oldBg)
  669. nextBlink = computer.uptime() + 0.5
  670. end
  671. end
  672. end
  673.  
  674. return Sky
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement