40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"regexp"
|
|
|
|
logger "git.site.quack-lab.dev/dave/cylogger"
|
|
"golang.design/x/clipboard"
|
|
)
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
logger.InitFlag()
|
|
|
|
// Initialize the clipboard package
|
|
logger.Info("Initializing clipboard...")
|
|
if err := clipboard.Init(); err != nil {
|
|
logger.Error("Failed to initialize clipboard: %v", err)
|
|
return
|
|
}
|
|
|
|
// Read the current text from the clipboard
|
|
logger.Info("Reading text from clipboard...")
|
|
clipboardContent := clipboard.Read(clipboard.FmtText)
|
|
inputText := string(clipboardContent)
|
|
logger.Info("Read %d characters from clipboard", len(inputText))
|
|
logger.Debug("Original text: %s", inputText)
|
|
|
|
// Escape all regex special characters in the input text
|
|
logger.Info("Escaping regex special characters...")
|
|
escapedText := regexp.QuoteMeta(inputText)
|
|
logger.Info("Escaped %d characters", len(escapedText))
|
|
logger.Debug("Escaped text: %s", escapedText)
|
|
|
|
// Write the escaped text back to the clipboard
|
|
logger.Info("Writing escaped text back to clipboard...")
|
|
clipboard.Write(clipboard.FmtText, []byte(escapedText))
|
|
logger.Info("Successfully wrote escaped text to clipboard")
|
|
}
|