This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
CrazedProgrammer's profile picture

Better Copy + Paste Support

Started by CrazedProgrammer, 16 April 2015 - 05:49 PM
CrazedProgrammer #1
Posted 16 April 2015 - 07:49 PM
It would be nice to have a proper "paste" event which doesn't restrict itself to 256 characters and a single line.
I would also like two new functions:
os.copy(str) – Copies string str to clipboard.
os.clipboard() – Returns a string of what's in the clipboard. If there's nothing in the clipboard, it returns nil.
The clipboard should be the clipboard of the last player to access the computer.
I hope it can be implemented, and there may be a slight problem with system-specific newline characters like "\n" or "\r\n".
Either way, please implement it so that newline characters are just "\n" from lua.
Edited on 17 April 2015 - 07:12 PM
flaghacker #2
Posted 16 April 2015 - 07:54 PM
I think the max copy-paste size is there to keep people from copying their code to a server, breaking the "forth wall" and stuff.

I like the functions you suggested.
Edited on 16 April 2015 - 05:55 PM
Creator #3
Posted 16 April 2015 - 07:56 PM
Totally support the idea. For example in OmniOS I would like to copy the content of the clipboard into OmniOS's clipboard. However I see no way to do this.
Lyqyd #4
Posted 16 April 2015 - 10:29 PM
Paste size limitations may be due in part to the necessity of transporting the contents of the clipboard from the client to the server.
Creator #5
Posted 16 April 2015 - 10:32 PM
A limit of 10 kB would be fine, but not 256Bytes. what we are also asking for is a way to get the system clipboard w/o pressing ctrl+v
SeaLife #6
Posted 16 April 2015 - 11:15 PM
I wouldnt prefer to use "kb" as size-limit for clipboard…

use string length? Like 1024 or something like that :D/>
Bomb Bloke #7
Posted 16 April 2015 - 11:47 PM
os.copy(str) – Copies string str to clipboard.
os.clipboard() – Returns a string of what's in the clipboard. If there's nothing in the clipboard, it returns nil.

Which "clipboard" are we talking about here?

If you mean that of the CC computer itself, as "os.whatever" would imply, then why not just do?:

local myClipBoard = str

If you mean that of "the real OS of the player", then that raises the questions as to which player you're going to try and pull data from, and once your script's managed to work that out, whether or not they want to have their clipboard contents read by you…
flaghacker #8
Posted 16 April 2015 - 11:54 PM
that raises the questions as to which player you're going to try and pull data from

Ah I always seem to forget this argument… Nice catch.
theoriginalbit #9
Posted 17 April 2015 - 04:21 AM
Just incase no one picked up on the subtlety that Bomb Bloke was trying to point out… all computers run on a server, even in Single-player there is a server and client, therefore if you were to have os.copy and os.clipboard they'd be based on the server's clipboard and not the client.

So as Bomb Bloke said, lets assume that it is implemented in a way where the client's clipboard is synchronised through the network, then the question becomes, if 4 people are looking at the computer which client's clipboard do you interact with…
Creator #10
Posted 17 April 2015 - 10:08 AM
So when you press ctrl + v you mean the=at the severs clipboard is invoked. What I meant was that instaed of pressing ctrl + v there is a function to get the clipboard. Like crtl + v, but without pressing them.
flaghacker #11
Posted 17 April 2015 - 10:47 AM
So when you press ctrl + v you mean the=at the severs clipboard is invoked. What I meant was that instaed of pressing ctrl + v there is a function to get the clipboard. Like crtl + v, but without pressing them.

No, he means that when you invoke the methods, there's no way to decide who's clipboard should be used, as multiple players could be using a computer at once.
Edited on 17 April 2015 - 08:49 AM
Creator #12
Posted 17 April 2015 - 07:52 PM
When you press ctrl + v in cc, your clipboard is pulled. What I am saying is that there could be a function like os.getClipboard() that will act as if you pressed ctrl + v.
Lyqyd #13
Posted 17 April 2015 - 08:02 PM
You who, though? You seem to be ignoring the fact that multiple players can use a computer at once. Whose clipboard should be used when that function is called?
Creator #14
Posted 17 April 2015 - 08:17 PM
I have not thought about that. Maybe make it take the clipboard of the person that booted the PC. This destroy all my dreams.
Lupus590 #15
Posted 17 April 2015 - 08:19 PM
what if they go offline on the server? (while the computer is still running)
Edited on 17 April 2015 - 06:19 PM
Creator #16
Posted 17 April 2015 - 08:41 PM
How does the current ctrl + v work. Maybe it should be the person who clicked on the pc while no one else was using it. This way if another person comes, it will still be the first person. If they disconnect, it returns ""
CrazedProgrammer #17
Posted 17 April 2015 - 09:10 PM
You who, though? You seem to be ignoring the fact that multiple players can use a computer at once. Whose clipboard should be used when that function is called?
Sorry Lyqyd, I didn't think of that.
I think the last player to access the computer should be the one with the clipboard.
flaghacker #18
Posted 17 April 2015 - 10:54 PM
You who, though? You seem to be ignoring the fact that multiple players can use a computer at once. Whose clipboard should be used when that function is called?
Sorry Lyqyd, I didn't think of that.
I think the last player to access the computer should be the one with the clipboard.

That's not really intuitive thought. Let's say you're using a computer and someone else opens it, then your clipboard suddently stops working.

And what if the new person leaves? Revert back to your keyboard? And what if no one is using the computer? Return an empty clipboard?

I think it's too complicated to add.
Creator #19
Posted 17 April 2015 - 11:12 PM
It is kind of complicated. And I see no evident solution
theoriginalbit #20
Posted 18 April 2015 - 03:02 AM
How does the current ctrl + v work.
The ctrl + v works currently by when you press ctrl + v your client will send the contents of your clipboard to the server so the paste event can be queued to the computer. This same approach cannot be applied to a function to get the clipboard because that function would run on the server, not your client.
Exerro #21
Posted 18 April 2015 - 11:56 AM
The only way I could see this working is using the event system, something like this:
-> Client presses ctrl-c
-> "copy" event passed to computer
-> computer yields with clipboard data, i.e. coroutine.yield( "ThisIsStuffToGoInClientClipboard" )

This would almost definitely mess things up if the client didn't yield with the clipboard data after getting the "copy" event, so I doubt it's a feasible solution, although maybe a config option would be good.
flaghacker #22
Posted 18 April 2015 - 03:42 PM
That won't work at all, the string you pass to yield is the event filter, you can't use it for other stuff.

Maybe the event could gcontain the playername, and maybe the clipboard functions could have the player name as a parameter, but tthat's all a bit complicated and it would break the 4th wall.

Edit: typo
Edited on 18 April 2015 - 01:42 PM
Creator #23
Posted 18 April 2015 - 06:28 PM
About the playername, I can actually change my name and if I biuld a program, I would like it to work on everybody.
flaghacker #24
Posted 18 April 2015 - 07:14 PM
About the playername, I can actually change my name and if I biuld a program, I would like it to work on everybody.

Euh, yea? That would work…

event, player = os.pullEvent ("paste")
print (os.getClipboard (player)
Creator #25
Posted 18 April 2015 - 07:35 PM
It would require someone to fire a paste event, but the idea is that it becomes automatical.
flaghacker #26
Posted 18 April 2015 - 09:36 PM
It would require someone to fire a paste event, but the idea is that it becomes automatical.

Of course, I was showing an example of how the problem you mentioned in your previous post could be solved.
Creator #27
Posted 18 April 2015 - 10:04 PM
How is your paste event fired?
KingofGamesYami #28
Posted 18 April 2015 - 10:17 PM
The paste event is handled Java side.