Feat: 支持剪切板调用
This commit is contained in:
@@ -21,14 +21,6 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取API密钥
|
|
||||||
// apiKey := getAPIKey()
|
|
||||||
// if apiKey == "" {
|
|
||||||
// fmt.Println("错误: 未设置API密钥")
|
|
||||||
// fmt.Println("请设置环境变量 SILICON_API_KEY 或在配置文件中指定")
|
|
||||||
// os.Exit(1)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 创建AI客户端
|
// 创建AI客户端
|
||||||
client := ai.NewClient(config.API)
|
client := ai.NewClient(config.API)
|
||||||
|
|
||||||
|
|||||||
@@ -1,39 +1,10 @@
|
|||||||
package clipboard
|
package clipboard
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"runtime"
|
|
||||||
|
|
||||||
"github.com/atotto/clipboard"
|
"github.com/atotto/clipboard"
|
||||||
)
|
)
|
||||||
|
|
||||||
var isClipboardAvailable bool
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
// 检测剪切板是否可用
|
|
||||||
// Linux需要xclip或xsel
|
|
||||||
if runtime.GOOS == "linux" {
|
|
||||||
isClipboardAvailable = isXClipAvailable()
|
|
||||||
} else {
|
|
||||||
isClipboardAvailable = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func isXClipAvailable() bool {
|
|
||||||
// 简单检查,实际使用时会在调用时检测
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write 将文本复制到剪切板
|
// Write 将文本复制到剪切板
|
||||||
func Write(text string) error {
|
func Write(text string) error {
|
||||||
if !isClipboardAvailable {
|
|
||||||
return fmt.Errorf("clipboard not available on this system")
|
|
||||||
}
|
|
||||||
return clipboard.WriteAll(text)
|
return clipboard.WriteAll(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteSilent 静默复制到剪切板,不返回错误
|
|
||||||
func WriteSilent(text string) bool {
|
|
||||||
err := Write(text)
|
|
||||||
return err == nil
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package clipboard
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestWrite(t *testing.T) {
|
||||||
|
Write("你好鸭")
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user