Esempio n. 1
0
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
				}
			}()
		}
	}
}
Esempio n. 2
0
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")
}
Esempio n. 3
0
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()
}
Esempio n. 4
0
// 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
}
Esempio n. 5
0
File: main.go Progetto: kkdai/webpic
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()
}
Esempio n. 6
0
func readClipboard() string {
	text, err := clipboard.ReadAll()
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	return text
}
Esempio n. 7
0
func main() {
	text, err := clipboard.ReadAll()
	if err != nil {
		panic(err)
	}

	fmt.Print(text)
}
Esempio n. 8
0
func Example() {
	clipboard.WriteAll("日本語")
	text, _ := clipboard.ReadAll()
	fmt.Println(text)

	// Output:
	// 日本語
}
Esempio n. 9
0
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
}
Esempio n. 10
0
// Paste whatever is in the system clipboard into the buffer
// Delete and paste if the user has a selection
func (v *View) Paste() {
	if !clipboard.Unsupported {
		if v.cursor.HasSelection() {
			v.cursor.DeleteSelection()
			v.cursor.ResetSelection()
		}
		clip, _ := clipboard.ReadAll()
		v.eh.Insert(v.cursor.Loc(), clip)
		v.cursor.SetLoc(v.cursor.Loc() + Count(clip))
	} else {
		messenger.Error("Clipboard is not supported on your system")
	}
}
Esempio n. 11
0
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
}
Esempio n. 12
0
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)
	}
}
Esempio n. 13
0
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)
}
Esempio n. 14
0
func getClipboard() (string, error) {
	return clipboard.ReadAll()
}
Esempio n. 15
0
/*
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
}
Esempio n. 16
0
func readClipBoard() {
	clip, _ := clipboard.ReadAll()
	if isUrl(clip) && len(clip) > 50 {
		readerChan <- clip
	}
}