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