Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Present the clipboard as an IO object #53313

Open
oxinabox opened this issue Feb 13, 2024 · 3 comments
Open

Present the clipboard as an IO object #53313

oxinabox opened this issue Feb 13, 2024 · 3 comments
Labels
feature Indicates new feature / enhancement requests stdlib Julia's standard library

Comments

@oxinabox
Copy link
Contributor

Idea as an alternative to #53199

I think InteractiveUtils could define a type Clipboard <: IO which accesses the clipboard.
Then could do things like

redirect_stdout(Clipboard()) do
    @code_llvm foo()
end

behind the scenes it would be using the clipboard functions we already have, and using IOBuffers.
I haven't fully thought it through, but I think it is all possible. We might need the user to provide file open strings like "r", "w", "a".

@vtjnash vtjnash added stdlib Julia's standard library feature Indicates new feature / enhancement requests labels Feb 13, 2024
@vtjnash
Copy link
Member

vtjnash commented Feb 13, 2024

Or something like:

open(InteractiveUtils.clipboard) do io
    code_llvm(io, foo, ())
end

I think we would want to typically encourage doing this with local state, especially since there likely needs to be an explicit close(io) event that actually flushes everything to the clipboard.

@vtjnash
Copy link
Member

vtjnash commented Feb 13, 2024

Where the above code would de-sugar to:

sprint() do io
    code_llvm(io, foo, ())
end |> clipboard

@stevengj
Copy link
Member

stevengj commented Feb 13, 2024

Why not just have a method

clipboard(f::Function) = clipboard(sprint(f))

so that you could do:

clipboard() do io
    # print stuff to io
end

? (Mildly "breaking", because the current form of clipboard(f::Function) will copy string(f) to the clipboard, but since this is nearly useless it's hard to imagine anyone doing it. Also, we are less strict about changing interactive interfaces.)

That seems a lot clearer to me — a Clipboard::IO device seems error-prone to me, since it's not obvious when it is "flushed" to the clipboard. When close is called? When you call flush? It would be tempting to use it without remembering to close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Indicates new feature / enhancement requests stdlib Julia's standard library
Projects
None yet
Development

No branches or pull requests

3 participants