本文整理汇总了Golang中github.com/atotto/clipboard.ReadAll函数的典型用法代码示例。如果您正苦于以下问题:Golang ReadAll函数的具体用法?Golang ReadAll怎么用?Golang ReadAll使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ReadAll函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: processClipboard
func processClipboard() {
val, _ := clipboard.ReadAll()
if lastClipboardValue != val {
lastClipboardValue = val
found := false
for _, urlPattern := range urls {
m, _ := regexp.MatchString(
"\\A"+strings.Replace(urlPattern, "*", "(.*)", -1)+"\\z",
val)
if m {
found = true
break
}
}
if found {
go func() {
min := minify(val)
if len(min) > 0 {
clipboard.WriteAll(min)
lastClipboardValue = min
}
}()
}
}
}
示例2: returnPw
func returnPw(pwch chan string) {
var pwd string
select {
case pw := <-pwch:
pwd = pw
case <-time.After(750 * time.Millisecond):
say("Generating...")
pwd = <-pwch
}
if *noTerminal {
fmt.Print(pwd)
return
}
before, err := clipboard.ReadAll()
clipboard.WriteAll(pwd)
say("\nPassword copied to clipboard! ")
time.Sleep(5 * time.Second)
say("Cleaning clipboard in 5 seconds...")
time.Sleep(5 * time.Second)
if err != nil {
clipboard.WriteAll("")
} else {
clipboard.WriteAll(before)
}
say("\n...again? or CTRL+C\n")
}
示例3: clipboardInputNumber
func clipboardInputNumber(dev *at.Device, message string) {
ticker := time.NewTicker(time.Millisecond * 100)
go func() {
previousPhoneNumber := ""
for range ticker.C {
if phoneNumber, err := clipboard.ReadAll(); err == nil {
if phoneNumber, err = normalizePhoneNumber(phoneNumber); err == nil {
if phoneNumber != previousPhoneNumber {
sendSMS(dev, message, phoneNumber)
previousPhoneNumber = phoneNumber
}
}
}
}
}()
scanner := bufio.NewScanner(os.Stdin)
fmt.Print("Наберите \"выход\": ")
for scanner.Scan() {
text := scanner.Text()
if isExitCommand(text) {
break
}
fmt.Print("Наберите \"выход\" для прекращения работы.")
}
ticker.Stop()
}
示例4: AddCommand
// AddCommand adds a Note
func AddCommand(c *cli.Context, i storage.Impl) (n storage.Note, err error) {
nName, err := NoteName(c)
if err != nil {
return n, err
}
if exists := i.NoteExists(nName); exists == true {
return n, fmt.Errorf("Note already exists")
}
n.Name = nName
n.Temporary = c.Bool("t")
// Only open editor if -p (read from clipboard) isnt set
if c.IsSet("p") {
nText, err := clipboard.ReadAll()
if err != nil {
return n, err
}
n.Text = nText
} else {
if err := writer.WriteNote(&n); err != nil {
return n, err
}
}
if err := i.SaveNote(&n); err != nil {
return n, err
}
return n, nil
}
示例5: main
func main() {
usr, _ := user.Current()
baseDir = fmt.Sprintf("%v/Pictures/webpic", usr.HomeDir)
os.MkdirAll(baseDir, 0755)
jsonFileAddr := fmt.Sprintf("%s/parser.json", baseDir)
reloadParser(jsonFileAddr)
var postUrl string
var workerNum int
var useDaemon bool
rootCmd := &cobra.Command{
Use: "webpic",
Short: "Download all the images in given post url",
Run: func(cmd *cobra.Command, args []string) {
if useDaemon {
//Check clipboard
var previousString string
fmt.Println("Start watching clipboard.... (press ctrl+c to exit)")
for {
text, err := clipboard.ReadAll()
if previousString != text {
//Found something new in clipboard, check if it is URL.
if err == nil && len(text) > 0 {
urlInfo := urlRegex.FindStringSubmatch(text)
if len(urlInfo) > 0 {
go crawler(text, workerNum)
}
}
previousString = text
}
time.Sleep(time.Second)
}
} else {
if postUrl == "" {
fmt.Println("Please use 'webpic -u URL'.")
return
}
crawler(postUrl, workerNum)
}
},
}
rootCmd.Flags().StringVarP(&postUrl, "url", "u", "", "Url of post")
rootCmd.Flags().IntVarP(&workerNum, "worker", "w", 25, "Number of workers")
rootCmd.Flags().BoolVarP(&useDaemon, "daemon", "d", false, "Enable daemon mode to watch the clipboard.")
updateCmd := &cobra.Command{
Use: "update",
Short: "Download new parser from github and update local.",
Run: func(cmd *cobra.Command, args []string) {
updateParser(jsonFileAddr)
},
}
rootCmd.AddCommand(updateCmd)
rootCmd.Execute()
}
示例6: readClipboard
func readClipboard() string {
text, err := clipboard.ReadAll()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
return text
}
示例7: main
func main() {
text, err := clipboard.ReadAll()
if err != nil {
panic(err)
}
fmt.Print(text)
}
示例8: Example
func Example() {
clipboard.WriteAll("日本語")
text, _ := clipboard.ReadAll()
fmt.Println(text)
// Output:
// 日本語
}
示例9: KeyFuncPaste
func KeyFuncPaste(this *Buffer) Result {
text, err := clipboard.ReadAll()
if err == nil {
this.InsertAndRepaint(
strings.Replace(
strings.Replace(
strings.Replace(text, "\n", " ", -1),
"\r", "", -1),
"\t", " ", -1))
}
return CONTINUE
}
示例10: copyThenClear
func copyThenClear(text string, d time.Duration) error {
signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt, os.Kill)
defer signal.Stop(signals)
original, err := clipboard.ReadAll()
if err != nil {
return err
}
err = clipboard.WriteAll(text)
if err != nil {
return err
}
select {
case <-signals:
case <-time.After(d):
}
current, _ := clipboard.ReadAll()
if current == text {
return clipboard.WriteAll(original)
}
return nil
}
示例11: main
func main() {
r := regexp.MustCompile(`^“([^“”]+)”[^“”]+Excerpt From:[^“”]+“[^“”]+” iBooks.`)
for true {
clipContent, _ := clipboard.ReadAll()
matchedGroups := r.FindStringSubmatch(clipContent)
if len(matchedGroups) > 0 {
stripped := matchedGroups[1]
clipboard.WriteAll(stripped)
fmt.Println("\n\n" + stripped)
}
time.Sleep(50)
}
}
示例12: main
func main() {
text, err := clipboard.ReadAll()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
re := regexp.MustCompile(`\r?\n`)
line := re.ReplaceAllString(text, "")
if err := clipboard.WriteAll(line); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Print(line)
os.Exit(0)
}
示例13: getClipboard
func getClipboard() (string, error) {
return clipboard.ReadAll()
}
示例14: ProcessEvent
/*
ProcessEvent processes all events come from the control parent. If a control
processes an event it should return true. If the method returns false it means
that the control do not want or cannot process the event and the caller sends
the event to the control parent
*/
func (e *EditField) ProcessEvent(event Event) bool {
if !e.Active() || !e.Enabled() {
return false
}
if event.Type == EventActivate && event.X == 0 {
term.HideCursor()
}
if event.Type == EventKey && event.Key != term.KeyTab {
if e.onKeyPress != nil {
res := e.onKeyPress(event.Key)
if res {
return true
}
}
switch event.Key {
case term.KeyEnter:
return false
case term.KeySpace:
e.insertRune(' ')
return true
case term.KeyBackspace:
e.backspace()
return true
case term.KeyDelete:
e.del()
return true
case term.KeyArrowLeft:
e.charLeft()
return true
case term.KeyHome:
e.home()
return true
case term.KeyEnd:
e.end()
return true
case term.KeyCtrlR:
if !e.readonly {
e.Clear()
}
return true
case term.KeyArrowRight:
e.charRight()
return true
case term.KeyCtrlC:
clipboard.WriteAll(e.Title())
return true
case term.KeyCtrlV:
if !e.readonly {
s, _ := clipboard.ReadAll()
e.SetTitle(s)
e.end()
}
return true
default:
if event.Ch != 0 {
e.insertRune(event.Ch)
return true
}
}
return false
}
return false
}
示例15: readClipBoard
func readClipBoard() {
clip, _ := clipboard.ReadAll()
if isUrl(clip) && len(clip) > 50 {
readerChan <- clip
}
}