mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-15 02:12:42 -04:00
re-added clipboard pasting (now for term.read()) and fixed clipboard being sent twice (only on key down again now)
This commit is contained in:
parent
bc7437769f
commit
acd5603844
@ -612,7 +612,7 @@ end
|
||||
|
||||
function stdinStream:read(n)
|
||||
local result = term.read(stdinHistory)
|
||||
if #stdinHistory > 10 then
|
||||
while #stdinHistory > 10 do
|
||||
table.remove(stdinHistory, 1)
|
||||
end
|
||||
return result
|
||||
|
@ -136,5 +136,5 @@ for k, v in pairs(driver.keyboard.keys) do
|
||||
end
|
||||
|
||||
function driver.keyboard.keys.isControl(char)
|
||||
return char < 0x20 or (char >= 0x7F and char <= 0x9F)
|
||||
return type(char) == "number" and (char < 0x20 or (char >= 0x7F and char <= 0x9F))
|
||||
end
|
@ -171,12 +171,23 @@ function term.read(history)
|
||||
driver.gpu.set(term.gpu(), w, y, char)
|
||||
end
|
||||
end
|
||||
local function scrollEnd()
|
||||
local w = term.size()
|
||||
cursor = history[current]:len() + 1
|
||||
scroll = math.max(0, cursor - (w - (start - 1)))
|
||||
render()
|
||||
end
|
||||
local function copyIfNecessary()
|
||||
if current ~= #history then
|
||||
history[#history] = history[current]
|
||||
current = #history
|
||||
end
|
||||
end
|
||||
local function updateCursor()
|
||||
term.cursor(start - 1 + cursor - scroll, y)
|
||||
term.cursorBlink(cursor <= history[current]:len() and
|
||||
history[current]:sub(cursor, cursor) or " ")
|
||||
end
|
||||
local function handleKeyPress(char, code)
|
||||
local w, h = term.size()
|
||||
local cancel = false
|
||||
@ -224,24 +235,18 @@ function term.read(history)
|
||||
end
|
||||
elseif code == keys["end"] then
|
||||
if cursor < history[current]:len() + 1 then
|
||||
cursor = history[current]:len() + 1
|
||||
scroll = math.max(0, cursor - (w - (start - 1)))
|
||||
render()
|
||||
scrollEnd()
|
||||
end
|
||||
elseif code == keys.up then
|
||||
if current > 1 then
|
||||
current = current - 1
|
||||
cursor = history[current]:len() + 1
|
||||
scroll = math.max(0, cursor - (w - (start - 1)))
|
||||
render()
|
||||
scrollEnd()
|
||||
end
|
||||
cancel = current == 1
|
||||
elseif code == keys.down then
|
||||
if current < #history then
|
||||
current = current + 1
|
||||
cursor = history[current]:len() + 1
|
||||
scroll = math.max(0, cursor - (w - (start - 1)))
|
||||
render()
|
||||
scrollEnd()
|
||||
end
|
||||
cancel = current == #history
|
||||
elseif code == keys.enter then
|
||||
@ -266,9 +271,7 @@ function term.read(history)
|
||||
scrollRight()
|
||||
end
|
||||
end
|
||||
term.cursor(start - 1 + cursor - scroll, y)
|
||||
term.cursorBlink(cursor <= history[current]:len() and
|
||||
history[current]:sub(cursor, cursor) or " ")
|
||||
updateCursor()
|
||||
return cancel
|
||||
end
|
||||
local function onKeyDown(_, address, char, code)
|
||||
@ -295,19 +298,25 @@ function term.read(history)
|
||||
keyRepeat = event.cancel(keyRepeat)
|
||||
end
|
||||
end
|
||||
--[[local function onClipboard(_, address, value)
|
||||
if address ~= term.keyboard then
|
||||
local function onClipboard(_, address, value)
|
||||
if address ~= term.keyboard() then
|
||||
return
|
||||
end
|
||||
if current ~= #history then
|
||||
history[#history] = history[current]
|
||||
current = #history
|
||||
end
|
||||
copyIfNecessary()
|
||||
term.cursorBlink(false)
|
||||
local l = value:find("\n", 1, true)
|
||||
if l then
|
||||
history[current] = history[current] .. value:sub(1, l - 1)
|
||||
result = history[current] .. "\n"
|
||||
else
|
||||
history[current] = history[current] .. value
|
||||
done = done or value:find("\n", 1, true) >= 0
|
||||
end]]
|
||||
scrollEnd()
|
||||
updateCursor()
|
||||
end
|
||||
end
|
||||
event.listen("key_down", onKeyDown)
|
||||
event.listen("key_up", onKeyUp)
|
||||
event.listen("clipboard", onClipboard)
|
||||
term.cursorBlink(true)
|
||||
while not result do
|
||||
coroutine.sleep()
|
||||
@ -317,6 +326,7 @@ function term.read(history)
|
||||
end
|
||||
event.ignore("key_down", onKeyDown)
|
||||
event.ignore("key_up", onKeyUp)
|
||||
event.ignore("clipboard", onClipboard)
|
||||
term.cursorBlink(false)
|
||||
print()
|
||||
return result
|
||||
|
@ -56,8 +56,10 @@ class Screen(val tileEntity: tileentity.Screen) extends MCGuiScreen {
|
||||
val char = Keyboard.getEventCharacter
|
||||
|
||||
if (code != Keyboard.KEY_ESCAPE && code != Keyboard.KEY_F11)
|
||||
if (code == Keyboard.KEY_INSERT && MCGuiScreen.isShiftKeyDown)
|
||||
if (code == Keyboard.KEY_INSERT && MCGuiScreen.isShiftKeyDown) {
|
||||
if (Keyboard.getEventKeyState)
|
||||
PacketSender.sendClipboard(tileEntity, MCGuiScreen.getClipboardString)
|
||||
}
|
||||
else if (Keyboard.getEventKeyState) {
|
||||
PacketSender.sendKeyDown(tileEntity, char, code)
|
||||
}
|
||||
|
@ -783,7 +783,11 @@ class Computer(val owner: Computer.Environment) extends Persistable with Runnabl
|
||||
}
|
||||
else {
|
||||
lua.setTotalMemory(Int.MaxValue)
|
||||
message = Some(lua.toString(3))
|
||||
val error = lua.toString(3)
|
||||
if (error != null)
|
||||
message = Some(error)
|
||||
else
|
||||
message = Some("unknown error")
|
||||
}
|
||||
close()
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user