pdeffebach / ClipData.jl

Move data to and from the clipboard in Julia
https://pdeffebach.github.io/ClipData.jl/stable/
MIT License
82 stars 6 forks source link

Don't print output #21

Closed chris-b1 closed 2 years ago

chris-b1 commented 3 years ago

Not sure if this was a leftover from debugging, but I would suggest by default output should not printed, and the returnstring arg should be sufficient to handle cases where the literal clipboard content is needed?

https://github.com/pdeffebach/ClipData.jl/blob/8d6aead1f01fc64accbefe727ddcd2afdcb2c318/src/ClipData.jl#L115

pdeffebach commented 3 years ago

Hey sorry for the delay about this. I will make sure to take a look soon.

pdeffebach commented 2 years ago

Sorry for the delay in looking into this.

To be clear, this is what you are referring to?

julia> x = [1 2; 3 4]
2×2 Matrix{Int64}:
 1  2
 3  4

julia> cliparray(x)
1   2
3   4

julia> cliparray(x; returnstring = true)
1   2
3   4
"1\t2\n3\t4"

I think the default behavior is good, actually. I think the output with whitespace is sufficiently different than the output with \t. Users might want both, but for different reasons.

pdeffebach commented 2 years ago

Ah I could see how this could be a problem if you are calling it inside a function... Let's provide keyword arguments to control this behavior.

chris-b1 commented 2 years ago

Thanks - for larger tables in particular the terminal IO on my setup (Windows, VS Code) is slow, and the pasted table breaks "scroll history" so I like it off by default.

As an example

using CSV, DataFrames, ClipData

function to_clipboard(df::DataFrames.DataFrame)
    buf = IOBuffer()
    CSV.write(buf, df; delim='\t')
    clipboard(String(take!(buf)))
end

N = 1000; df = DataFrame(a=rand(N), b=rand(N), c=rand(N))

julia> @time to_clipboard(df)
  0.001046 seconds (14.47 k allocations: 4.635 MiB)

julia> @time cliptable(df)
 <snip>
  0.207863 seconds (14.48 k allocations: 4.691 MiB)
alecloudenback commented 2 years ago

I'd also prefer it to not print by default.

pdeffebach commented 2 years ago

Okay I'm going to do a PR for this soon.

But first I will make a release with better compat entries, since I think we fixed some compat a few months ago but forgot a release.

pdeffebach commented 2 years ago

Just made a release. So should be fixed now.