dswfyq6201 2014-01-24 19:30
浏览 247
已采纳

如何在Go中将文本复制到剪贴板或从剪贴板复制文本? [关闭]

In my Go language command line application, I need the ability to copy certain snippets of text to the system clipboard using Go. Basically something like PyperClip, but for Go.

I'm looking for a platform agnostic solution! Any help would be great :)

  • 写回答

1条回答 默认 最新

  • doupuchen6378 2014-01-24 21:03
    关注

    One project (just for Windows and Mac) seems approaching what you want: atotto/clipboard.

    Provide copying and pasting to the Clipboard for Go.

    func ReadAll() (string, error)
    func WriteAll(text string) error
    

    Linux support is in this clipboard_linux.go class: a simple wrapper to xsel --output/input --clipboard system command.


    Another approach: try and take advantage of third-party libraries, like GLFW:

    a free, Open Source, multi-platform library for opening a window, creating an OpenGL context and managing input

    Its Go wrapper glfw3 does provide a clipboard.go file, with supposedly multi-platform methods.

    func (w *Window) SetClipboardString(str string)
    func (w *Window) GetClipboardString() (string, error)
    

    But that would be in the context of GLFW windows, not any shell window of course.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私