From 56072b2c5161eb91dda4a03438fb0952f22d5442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 20 Jan 2016 23:18:02 +0100 Subject: [PATCH] Textgpu fixes --- src/lua/core/internet.lua | 11 ++++++++++- src/lua/core/textgpu.lua | 38 +++++++++++++++++++++++++------------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/lua/core/internet.lua b/src/lua/core/internet.lua index 8e2c6ac..31f8317 100644 --- a/src/lua/core/internet.lua +++ b/src/lua/core/internet.lua @@ -21,7 +21,7 @@ function internet.start() return { finishConnect = function() if not sfd then - return false, reason + error(reason) end return true end, @@ -40,6 +40,15 @@ function internet.start() } end + function component.request(url, post) + local host = url:match("http://([^/]+)") + local con = component.connect(host, 80) + if con:finishConnect() then + con:write("GET " .. url .. " HTTP/1.1\r\nHost: " .. host .. "\r\n\r\n") + end + + end + modules.component.api.register(nil, "internet", component) end diff --git a/src/lua/core/textgpu.lua b/src/lua/core/textgpu.lua index dc7d439..52cf9c5 100644 --- a/src/lua/core/textgpu.lua +++ b/src/lua/core/textgpu.lua @@ -39,12 +39,16 @@ local function prepareBuffers(w, h) end end -local usub = modules.sandbox.utf8.sub +local usub local function insertString(main, sub, at) + checkArg(1, main, "string") + checkArg(2, sub, "string") + checkArg(3, at, "number") return usub(main, 1, at - 1) .. sub .. usub(main, at + utf8.len(sub)) end function textgpu.start() + usub = modules.sandbox.unicode.sub local gpu = {} function gpu.bind() return false, "This is static bound gpu" end function gpu.setBackground(color, isPaletteIndex) @@ -125,11 +129,15 @@ function textgpu.start() x = math.floor(x) y = math.floor(y) if not vertical then + if not tbuffer[y] then + return false + end tbuffer[y] = insertString(tbuffer[y], value, x) bbuffer[y] = insertString(bbuffer[y], background:rep(utf8.len(value)), x) fbuffer[y] = insertString(fbuffer[y], foreground:rep(utf8.len(value)), x) write("\x1b[" .. y .. ";" .. x .. "H" .. value) else + --TODO: Buffers! write("\x1b[" .. y .. ";" .. x .. "H") value:gsub(".", function(c) write(c .. "\x1b[D\x1b[B") @@ -171,12 +179,14 @@ function textgpu.start() if lwrite then local wx = (tx + linex)|0 local wy = (ty + y + i - 1)|0 - write("\x1b[4" .. bg .. "m") - write("\x1b[3" .. fg .. "m") - write("\x1b[" .. wy .. ";" .. wx .. "H" .. line) - tbuffer[wy] = insertString(tbuffer[wy], line, wx) - bbuffer[wy] = insertString(bbuffer[wy], bg:rep(utf8.len(line)), wx) - fbuffer[wy] = insertString(fbuffer[wy], fg:rep(utf8.len(line)), wx) + if tbuffer[wy] then + write("\x1b[4" .. bg .. "m") + write("\x1b[3" .. fg .. "m") + write("\x1b[" .. wy .. ";" .. wx .. "H" .. line) + tbuffer[wy] = insertString(tbuffer[wy], line, wx) + bbuffer[wy] = insertString(bbuffer[wy], bg:rep(utf8.len(line)), wx) + fbuffer[wy] = insertString(fbuffer[wy], fg:rep(utf8.len(line)), wx) + end bg = btbuf[i]:sub(j,j) fg = ftbuf[i]:sub(j,j) line = nil @@ -189,12 +199,14 @@ function textgpu.start() if line then local wx = (tx + linex)|0 local wy = (ty + y + i - 1)|0 - write("\x1b[4" .. bg .. "m") - write("\x1b[3" .. fg .. "m") - write("\x1b[" .. wy .. ";" .. wx .. "H" .. line) - tbuffer[wy] = insertString(tbuffer[wy], line, wx) - bbuffer[wy] = insertString(bbuffer[wy], bg:rep(utf8.len(line)), wx) - fbuffer[wy] = insertString(fbuffer[wy], fg:rep(utf8.len(line)), wx) + if tbuffer[wy] then + write("\x1b[4" .. bg .. "m") + write("\x1b[3" .. fg .. "m") + write("\x1b[" .. wy .. ";" .. wx .. "H" .. line) + tbuffer[wy] = insertString(tbuffer[wy], line, wx) + bbuffer[wy] = insertString(bbuffer[wy], bg:rep(utf8.len(line)), wx) + fbuffer[wy] = insertString(fbuffer[wy], fg:rep(utf8.len(line)), wx) + end line = nil linex = nil lwrite = false