Thread overview
How to put an arbitrary string to clipboard in D?
Jul 30, 2021
tastyminerals
Jul 30, 2021
rikki cattermole
Jul 31, 2021
tastyminerals
Jul 31, 2021
rikki cattermole
Jul 31, 2021
Adam D Ruppe
July 30, 2021

I made a GUI app using tkd library. I am reading the string from one of the app widgets and would like to put it into the clipboard. Does anyone have an idea how to copy a string to the clipboard in D?

July 31, 2021
On 31/07/2021 7:33 AM, tastyminerals wrote:
> I made a GUI app using tkd library. I am reading the string from one of the app widgets and would like to put it into the clipboard. Does anyone have an idea how to copy a string to the clipboard in D?

copyText on a Text widget appears to do what you want.

https://github.com/nomad-software/tkd/blob/9ca40d117649bb9a9db108d8f92e92870b9dc77e/source/tkd/widget/text.d#L477

https://wiki.tcl-lang.org/page/tk_textCopy
July 31, 2021
On Friday, 30 July 2021 at 20:01:09 UTC, rikki cattermole wrote:
>
> On 31/07/2021 7:33 AM, tastyminerals wrote:
>> I made a GUI app using tkd library. I am reading the string from one of the app widgets and would like to put it into the clipboard. Does anyone have an idea how to copy a string to the clipboard in D?
>
> copyText on a Text widget appears to do what you want.
>
> https://github.com/nomad-software/tkd/blob/9ca40d117649bb9a9db108d8f92e92870b9dc77e/source/tkd/widget/text.d#L477
>
> https://wiki.tcl-lang.org/page/tk_textCopy

The problem is that I don't use Text widget but retrieve the string from TreeView widget which only has getSelectedRows method. So I thought there may be a way in D to communicate with the system clipboard...
August 01, 2021
On 01/08/2021 6:30 AM, tastyminerals wrote:
> So I thought there may be a way in D to communicate with the system clipboard...

No, this requires a windowing library and yes a window to do it (depending on the windowing system and even the desktop environment).
July 31, 2021
On Saturday, 31 July 2021 at 18:30:47 UTC, tastyminerals wrote:
> So I thought there may be a way in D to communicate with the system clipboard...

You can always call the same system functions from D that you'd use from C.

This is the source to my simpledisplay.d library on its clipboard function:

https://github.com/adamdruppe/arsd/blob/master/simpledisplay.d#L5279

The Windows side isn't too bad, the linux side a bit more complicated. Generally window libs offer something for this but idk about the one you're using.