diff options
| author | Andrew Lee <alee14498@protonmail.com> | 2020-11-15 13:15:34 -0500 |
|---|---|---|
| committer | Andrew Lee <alee14498@protonmail.com> | 2020-11-15 13:15:34 -0500 |
| commit | e379656333caefe28914c6bc0cdfe9a80b1ecd0e (patch) | |
| tree | dbc8ebef215d90b4d6285530a31dc1bd4ae0f15f /.mbs/lib | |
| parent | a405ec93546b95c2369ec9069b3616944d785198 (diff) | |
| download | bits-UI-e379656333caefe28914c6bc0cdfe9a80b1ecd0e.tar.gz bits-UI-e379656333caefe28914c6bc0cdfe9a80b1ecd0e.tar.bz2 bits-UI-e379656333caefe28914c6bc0cdfe9a80b1ecd0e.zip | |
Updated MBS
Diffstat (limited to '.mbs/lib')
| -rw-r--r-- | .mbs/lib/blit_window.lua | 32 | ||||
| -rw-r--r-- | .mbs/lib/readline.lua | 38 | ||||
| -rw-r--r-- | .mbs/lib/scroll_window.lua | 32 | ||||
| -rw-r--r-- | .mbs/lib/stack_trace.lua | 4 |
4 files changed, 53 insertions, 53 deletions
diff --git a/.mbs/lib/blit_window.lua b/.mbs/lib/blit_window.lua index 39cd843..9cd4979 100644 --- a/.mbs/lib/blit_window.lua +++ b/.mbs/lib/blit_window.lua @@ -58,14 +58,14 @@ function create(original) local lineBack = back_colour[cursor_y] local preStop = pos - 1 local preStart = math.min(1, preStop) - local postStart = pos + string.len(writeText) + local postStart = pos + #writeText local postStop = sizeX local sub, rep = string.sub, string.rep - text[cursor_y] = sub(lineText, preStart, preStop)..writeText..sub(lineText, postStart, postStop) - text_colour[cursor_y] = sub(lineColor, preStart, preStop)..rep(cur_text_colour, #writeText)..sub(lineColor, postStart, postStop) - back_colour[cursor_y] = sub(lineBack, preStart, preStop)..rep(cur_back_colour, #writeText)..sub(lineBack, postStart, postStop) - cursor_x = pos + string.len(writeText) + text[cursor_y] = sub(lineText, preStart, preStop) .. writeText .. sub(lineText, postStart, postStop) + text_colour[cursor_y] = sub(lineColor, preStart, preStop) .. rep(cur_text_colour, #writeText) .. sub(lineColor, postStart, postStop) + back_colour[cursor_y] = sub(lineBack, preStart, preStop) .. rep(cur_back_colour, #writeText) .. sub(lineBack, postStart, postStop) + cursor_x = pos + #writeText end function redirect.blit(writeText, writeFore, writeBack) @@ -104,14 +104,14 @@ function create(original) local lineBack = back_colour[cursor_y] local preStop = cursor_x - 1 local preStart = math.min(1, preStop) - local postStart = cursor_x + string.len(writeText) + local postStart = cursor_x + #writeText local postStop = sizeX local sub = string.sub - text[cursor_y] = sub(lineText, preStart, preStop)..writeText..sub(lineText, postStart, postStop) - text_colour[cursor_y] = sub(lineColor, preStart, preStop)..writeFore..sub(lineColor, postStart, postStop) - back_colour[cursor_y] = sub(lineBack, preStart, preStop)..writeBack..sub(lineBack, postStart, postStop) - cursor_x = pos + string.len(writeText) + text[cursor_y] = sub(lineText, preStart, preStop) .. writeText .. sub(lineText, postStart, postStop) + text_colour[cursor_y] = sub(lineColor, preStart, preStop) .. writeFore .. sub(lineColor, postStart, postStop) + back_colour[cursor_y] = sub(lineBack, preStart, preStop) .. writeBack .. sub(lineBack, postStart, postStop) + cursor_x = pos + #writeText end function redirect.clear() @@ -246,8 +246,8 @@ function create(original) end end - for i=1, sizeY do - target.setCursorPos(1,i) + for i = 1, sizeY do + target.setCursorPos(1, i) target.blit(text[i], text_colour[i], back_colour[i]) end @@ -273,15 +273,15 @@ function create(original) back_colour[y] = back_colour[y]:sub(1, new_x) elseif new_x > sizeX then text[y] = text[y] .. (" "):rep(new_x - sizeX) - text_colour[y] = text_colour[y] .. (cur_text_colour):rep(new_x - sizeX) - back_colour[y] = back_colour[y] .. (cur_back_colour):rep(new_x - sizeX) + text_colour[y] = text_colour[y] .. cur_text_colour:rep(new_x - sizeX) + back_colour[y] = back_colour[y] .. cur_back_colour:rep(new_x - sizeX) end end -- Add any new lines we might need. local text_line = (" "):rep(new_x) - local fore_line = (cur_text_colour):rep(new_x) - local back_line = (cur_back_colour):rep(new_x) + local fore_line = cur_text_colour:rep(new_x) + local back_line = cur_back_colour:rep(new_x) for y = sizeY + 1, new_y do text[y] = text_line text_colour[y] = fore_line diff --git a/.mbs/lib/readline.lua b/.mbs/lib/readline.lua index ba322a6..6a78321 100644 --- a/.mbs/lib/readline.lua +++ b/.mbs/lib/readline.lua @@ -119,7 +119,7 @@ function read(opts) local _, cy = term.getCursorPos() term.setCursorPos(sx, cy) - local sReplace = (_bClear and " ") or replace_char + local sReplace = _bClear and " " or replace_char if opts.highlight and not _bClear then -- We've a highlighting function: step through each line of input @@ -209,7 +209,7 @@ function read(opts) redraw() while true do local sEvent, param, param1, param2 = os.pullEvent() - if sEvent == "char" and (nMod == 0 or nMod == 3 or (nMod == 2 and not meta_keys:find(param, 1, true))) then + if sEvent == "char" and (nMod == 0 or nMod == 3 or nMod == 2 and not meta_keys:find(param, 1, true)) then -- Typed key -- Alt+X will queue a char event, so we limit ourselves to cases where -- no modifier is used, or Ctrl+Alt are (equivalent to AltGr), or the Alt @@ -254,7 +254,7 @@ function read(opts) sLine = nil nPos = 0 break - elseif (nMod == 0 and param == keys.left) or (nMod == 1 and param == keys.b) then + elseif nMod == 0 and param == keys.left or nMod == 1 and param == keys.b then -- Left if nPos > 0 then clear() @@ -262,7 +262,7 @@ function read(opts) recomplete() redraw() end - elseif (nMod == 0 and param == keys.right) or (nMod == 1 and param == keys.f) then + elseif nMod == 0 and param == keys.right or nMod == 1 and param == keys.f then -- Right if nPos < #sLine then -- Move right @@ -292,8 +292,8 @@ function read(opts) recomplete() redraw() end - elseif (nMod == 0 and (param == keys.up or param == keys.down)) - or (nMod == 1 and (param == keys.p or param == keys.n)) then + elseif nMod == 0 and (param == keys.up or param == keys.down) + or nMod == 1 and (param == keys.p or param == keys.n) then -- Up or down if nCompletion then -- Cycle completions @@ -340,8 +340,8 @@ function read(opts) uncomplete() redraw() end - elseif (nMod == 0 and param == keys.home) - or (nMod == 1 and param == keys.a) then + elseif nMod == 0 and param == keys.home + or nMod == 1 and param == keys.a then -- Home if nPos > 0 then clear() @@ -349,8 +349,8 @@ function read(opts) recomplete() redraw() end - elseif (nMod == 0 and param == keys["end"]) - or (nMod == 1 and param == keys.e) then + elseif nMod == 0 and param == keys["end"] + or nMod == 1 and param == keys.e then -- End if nPos < #sLine then clear() @@ -371,14 +371,14 @@ function read(opts) nPos = math.min(#sLine, cur) -- We need the clear to remove the completion - clear(); recomplete(); redraw() + clear() recomplete() redraw() elseif nMod == 2 and param == keys.u then -- Upcase word if nPos < #sLine then local nNext = nextWord() sLine = nsub(1, nPos) .. nsub(nPos + 1, nNext):upper() .. nsub(nNext + 1, #sLine) nPos = nNext - clear(); recomplete(); redraw() + clear() recomplete() redraw() end elseif nMod == 2 and param == keys.l then -- Lowercase word @@ -386,7 +386,7 @@ function read(opts) local nNext = nextWord() sLine = nsub(1, nPos) .. nsub(nPos + 1, nNext):lower() .. nsub(nNext + 1, #sLine) nPos = nNext - clear(); recomplete(); redraw() + clear() recomplete() redraw() end elseif nMod == 2 and param == keys.c then -- Capitalize word @@ -395,7 +395,7 @@ function read(opts) sLine = nsub(1, nPos) .. nsub(nPos + 1, nPos + 1):upper() .. nsub(nPos + 2, nNext):lower() .. nsub(nNext + 1, #sLine) nPos = nNext - clear(); recomplete(); redraw() + clear() recomplete() redraw() end -- Killing text @@ -424,7 +424,7 @@ function read(opts) kill(sLine:sub(1, nPos)) sLine = sLine:sub(nPos + 1) nPos = 0 - recomplete(); redraw() + recomplete() redraw() end elseif nMod == 1 and param == keys.k then -- Delete from cursor to end of line @@ -433,7 +433,7 @@ function read(opts) kill(sLine:sub(nPos + 1)) sLine = sLine:sub(1, nPos) nPos = #sLine - recomplete(); redraw() + recomplete() redraw() end elseif nMod == 2 and param == keys.d then -- Delete from cursor to end of next word @@ -443,7 +443,7 @@ function read(opts) clear() kill(sLine:sub(nPos + 1, nNext)) sLine = sLine:sub(1, nPos) .. sLine:sub(nNext + 1) - recomplete(); redraw() + recomplete() redraw() end end elseif nMod == 1 and param == keys.w then @@ -455,7 +455,7 @@ function read(opts) kill(sLine:sub(nPrev + 1, nPos)) sLine = sLine:sub(1, nPrev) .. sLine:sub(nPos + 1) nPos = nPrev - recomplete(); redraw() + recomplete()redraw() end end elseif nMod == 1 and param == keys.y then @@ -464,7 +464,7 @@ function read(opts) clear() sLine = sLine:sub(1, nPos) .. insert .. sLine:sub(nPos + 1) nPos = nPos + #insert - recomplete(); redraw() + recomplete() redraw() end -- Misc elseif nMod == 0 and param == keys.tab then diff --git a/.mbs/lib/scroll_window.lua b/.mbs/lib/scroll_window.lua index 75a6fb1..b2c1044 100644 --- a/.mbs/lib/scroll_window.lua +++ b/.mbs/lib/scroll_window.lua @@ -80,14 +80,14 @@ function create(original) local lineBack = back_colour[scroll_cursor_y] local preStop = pos - 1 local preStart = math.min(1, preStop) - local postStart = pos + string.len(writeText) + local postStart = pos + #writeText local postStop = sizeX local sub, rep = string.sub, string.rep - text[scroll_cursor_y] = sub(lineText, preStart, preStop)..writeText..sub(lineText, postStart, postStop) - text_colour[scroll_cursor_y] = sub(lineColor, preStart, preStop)..rep(cur_text_colour, #writeText)..sub(lineColor, postStart, postStop) - back_colour[scroll_cursor_y] = sub(lineBack, preStart, preStop)..rep(cur_back_colour, #writeText)..sub(lineBack, postStart, postStop) - cursor_x = pos + string.len(writeText) + text[scroll_cursor_y] = sub(lineText, preStart, preStop) .. writeText .. sub(lineText, postStart, postStop) + text_colour[scroll_cursor_y] = sub(lineColor, preStart, preStop) .. rep(cur_text_colour, #writeText) .. sub(lineColor, postStart, postStop) + back_colour[scroll_cursor_y] = sub(lineBack, preStart, preStop) .. rep(cur_back_colour, #writeText) .. sub(lineBack, postStart, postStop) + cursor_x = pos + #writeText end function redirect.blit(writeText, writeFore, writeBack) @@ -131,13 +131,13 @@ function create(original) local lineBack = back_colour[scroll_cursor_y] local preStop = cursor_x - 1 local preStart = math.min(1, preStop) - local postStart = cursor_x + string.len(writeText) + local postStart = cursor_x + #writeText local postStop = sizeX local sub = string.sub - text[scroll_cursor_y] = sub(lineText, preStart, preStop)..writeText..sub(lineText, postStart, postStop) - text_colour[scroll_cursor_y] = sub(lineColor, preStart, preStop)..writeFore..sub(lineColor, postStart, postStop) - back_colour[scroll_cursor_y] = sub(lineBack, preStart, preStop)..writeBack..sub(lineBack, postStart, postStop) + text[scroll_cursor_y] = sub(lineText, preStart, preStop) .. writeText .. sub(lineText, postStart, postStop) + text_colour[scroll_cursor_y] = sub(lineColor, preStart, preStop) .. writeFore .. sub(lineColor, postStart, postStop) + back_colour[scroll_cursor_y] = sub(lineBack, preStart, preStop) .. writeBack .. sub(lineBack, postStart, postStop) cursor_x = pos + #writeText end @@ -149,8 +149,8 @@ function create(original) end local text_line = (" "):rep(sizeX) - local fore_line = (cur_text_colour):rep(sizeX) - local back_line = (cur_back_colour):rep(sizeX) + local fore_line = cur_text_colour:rep(sizeX) + local back_line = cur_back_colour:rep(sizeX) for i = scroll_offset + 1, sizeY + scroll_offset do text[i] = text_line @@ -331,7 +331,7 @@ function create(original) local original = original local scroll_offset = scroll_offset + (offset or 0) for i = 1, sizeY do - original.setCursorPos(1,i) + original.setCursorPos(1, i) local yOffset = scroll_offset + i original.blit(text[yOffset], text_colour[yOffset], back_colour[yOffset]) end @@ -422,16 +422,16 @@ function create(original) back_colour[y] = back_colour[y]:sub(1, new_x) elseif new_x > sizeX then text[y] = text[y] .. (" "):rep(new_x - sizeX) - text_colour[y] = text_colour[y] .. (cur_text_colour):rep(new_x - sizeX) - back_colour[y] = back_colour[y] .. (cur_back_colour):rep(new_x - sizeX) + text_colour[y] = text_colour[y] .. cur_text_colour:rep(new_x - sizeX) + back_colour[y] = back_colour[y] .. cur_back_colour:rep(new_x - sizeX) end end if new_y > sizeY then -- Append any new lines we might need. local text_line = (" "):rep(new_x) - local fore_line = (cur_text_colour):rep(new_x) - local back_line = (cur_back_colour):rep(new_x) + local fore_line = cur_text_colour:rep(new_x) + local back_line = cur_back_colour:rep(new_x) for y = total_height + 1, new_y do text[y] = text_line text_colour[y] = fore_line diff --git a/.mbs/lib/stack_trace.lua b/.mbs/lib/stack_trace.lua index 7674813..2c94dcd 100644 --- a/.mbs/lib/stack_trace.lua +++ b/.mbs/lib/stack_trace.lua @@ -5,7 +5,7 @@ local function traceback(x) -- Attempt to detect error() and error("xyz", 0). -- This probably means they're erroring the program intentionally and so we -- shouldn't display anything. - if x == nil or (type(x) == "string" and not x:find(":%d+:")) then + if x == nil or type(x) == "string" and not x:find(":%d+:") then return x end @@ -65,7 +65,7 @@ local function xpcall_with(fn) -- Find the position where the stack traceback actually starts local trace_starts for i = #trace, 1, -1 do - if trace[i] == "stack traceback:" then trace_starts = i; break end + if trace[i] == "stack traceback:" then trace_starts = i break end end -- If this traceback is more than 15 elements long, keep the first 9, last 5 |
