Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function initUI(m)
- local mW, mH = m.getSize()
- local tbl = {
- mon = m,
- monW = mW,
- monH = mH
- }
- function tbl.spacer(y, str)
- local l = string.len(str)
- local x = math.floor(tbl.monW / 2 - l / 2)
- tbl.mon.setCursorPos(1, y)
- for i=1,x do tbl.mon.write(" ") end
- tbl.mon.write(str)
- for i=1,tbl.monW-l do tbl.mon.write(" ") end
- return y + 1
- end
- function tbl.drawVbar(sy, ey)
- local cx, cy = tbl.mon.getCursorPos()
- for i=sy,ey do
- tbl.mon.setCursorPos(cx, i)
- tbl.mon.write(' ')
- end
- tbl.mon.setCursorPos(cx + 1, cy)
- end
- function tbl.writeMid(str, nlen)
- local slen = string.len(str)
- local cx, cy = tbl.mon.getCursorPos()
- if slen >= nlen then error("Invalid length!") end
- local hlen = (nlen - slen) / 2
- tbl.mon.setCursorPos(cx + hlen, cy)
- tbl.mon.write(str)
- tbl.mon.setCursorPos(cx + nlen, cy)
- return str
- end
- function tbl.monWriteFGBG(str)
- local fg, bg = tbl.mon.getTextColor(), tbl.mon.getBackgroundColor()
- local lcol, col, slen = bg, bg, string.len(str)
- for i=1,slen do
- if string.sub(str, i, i) == ' ' then col = bg else col = fg end
- if col ~= lcol then tbl.mon.setBackgroundColor(col) end
- tbl.mon.write(' ')
- lcol = col
- end
- tbl.mon.setTextColor(fg)
- tbl.mon.setBackgroundColor(bg)
- end
- function tbl.writeDigit(d)
- if d < 0 or d > 14 then error("Invalid digit!") end
- local cx, cy = tbl.mon.getCursorPos()
- local pos = d * 4 + 1
- local npos = pos + 4
- -- _0_ _1_ _2_ _3_ _4_ _5_ _6_ _7_ _8_ _9_ _,_ _._ _%_ _%_
- tbl.monWriteFGBG(string.sub("### # ### ### # # ### ### ### ### ### ## # ", pos, npos))
- tbl.mon.setCursorPos(cx, cy + 1) tbl.monWriteFGBG(string.sub("# # # # # # # # # # # # # # ## # ", pos, npos))
- tbl.mon.setCursorPos(cx, cy + 2) tbl.monWriteFGBG(string.sub("# # # ### ### ### ### ### # ### ### # ", pos, npos))
- tbl.mon.setCursorPos(cx, cy + 3) tbl.monWriteFGBG(string.sub("# # # # # # # # # # # # # # # ## ", pos, npos))
- tbl.mon.setCursorPos(cx, cy + 4) tbl.monWriteFGBG(string.sub("### # ### ### # ### ### # ### ### # # # ## ", pos, npos))
- tbl.mon.setCursorPos(cx + 4, cy)
- end
- function tbl.writeNumber(n, digits, noZero)
- beginning = true
- for i=1,digits do
- local i10 = 10 ^ (digits - i + 1)
- local digit = math.floor((n % i10) / (i10 / 10))
- if noZero and beginning and digit == 0 then
- local cx, cy = tbl.mon.getCursorPos()
- tbl.mon.setCursorPos(cx + 4, cy)
- else
- tbl.writeDigit(digit, i ~= digits)
- beginning = false
- end
- end
- end
- return tbl
- end
Advertisement
Add Comment
Please, Sign In to add comment