Skip to content

Commit 1482f4a

Browse files
author
asvvvad
committed
Initial commit
1 parent 03efdca commit 1482f4a

File tree

9 files changed

+251
-0
lines changed

9 files changed

+251
-0
lines changed

README.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# C👏️L👏️A👏️P
2+
Add👏️emojis👏️between👏️letters👏️and👏️words
3+
4+
## Installation:
5+
6+
### For the CLI app:
7+
`go install github.com/asvvvad/clap`
8+
9+
#### Usage:
10+
1. Copy text you want to *clap*
11+
2. `clap`
12+
3. Clapped👏️and👏️copied!
13+
4. <key>ctrl</key>+<key>v</key> to paste anywhere
14+
5. ??
15+
6. P👏️R👏️O👏️F👏️I👏️T
16+
17+
#### Additional Tip:
18+
1. Add a system shortcut for `clap -no-out` with a keybinding like <key>ctrl</key>+<key>shift</key>+<key>l</key>
19+
2. in a browser or an app copy the text you want to clap
20+
- if you are sending a message for example <key>ctrl</key>+<key>x</key> to cut it then do the following steps
21+
3. <key>ctrl</key>+<key>shift</key>+<key>l</key> to clap it
22+
4. <key>ctrl</key>+<key>v</key> to paste it somewhere
23+
5. ??
24+
6. P👏️R👏️O👏️F👏️I👏️T
25+
26+
run `clap -h` for more help
27+
28+
### For the module:
29+
`go get github.com/asvvvad/clap/clap`
30+
31+
run `go doc github.com/asvvvad/clap/clap` for help
32+
33+
There is also `github.com/asvvvad/clap/clap/b` which simply replace the letter "b" in a string with the emoji 🅱️
34+
To use it in the CLI app use the `-b` flag
35+
36+
### Why??
37+
You👏️know👏️I👏️had👏️to👏️do👏️it👏️to👏️'em

clap/b/b.go

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package b
2+
3+
import (
4+
"strings"
5+
)
6+
7+
// B replace the letter B and O in a string with the emojis 🅱️ and 🅾️, respectively.
8+
func B(text string) string {
9+
result := strings.ReplaceAll(text, "b", "🅱️")
10+
result = strings.ReplaceAll(result, "B", "🅱️")
11+
return result
12+
}

clap/b/b_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package b
2+
3+
import "testing"
4+
5+
func TestB(t *testing.T) {
6+
result := B("DAMN BOI")
7+
expected := "DAMN 🅱️OI"
8+
9+
if result != expected {
10+
t.Errorf("FAILED: Expected "+expected+"\" got %v", result)
11+
} else {
12+
t.Log("PASSED")
13+
}
14+
}

clap/b/go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/asvvvad/clap/clap/b
2+
3+
go 1.14

clap/clap.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package clap
2+
3+
import (
4+
"strings"
5+
)
6+
7+
// Clap adds clap emoji between words or letters
8+
func Clap(text string) string {
9+
return Emoji(text, "👏️")
10+
}
11+
12+
// Emoji adds an emoji between words or letters, when text is a sentence or when it's a word, respectively
13+
func Emoji(text string, emoji string) string {
14+
// If text is a sentence (with spaces)
15+
if strings.Contains(text, " ") {
16+
return BetweenWords(text, emoji)
17+
}
18+
// If text is a word (no space)
19+
return BetweenLetters(text, emoji)
20+
}
21+
22+
// BetweenWords adds emoji between words by replacing the spaces with the emoji
23+
func BetweenWords(sentence string, emoji string) string {
24+
return strings.ReplaceAll(sentence, " ", emoji)
25+
}
26+
27+
// BetweenLetters adds emoji between words by replacing the spaces with the emoji
28+
func BetweenLetters(sentence string, emoji string) string {
29+
return strings.ToUpper(strings.Join(strings.Split(sentence, ""), emoji))
30+
}

clap/clap_test.go

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package clap
2+
3+
import "testing"
4+
5+
func TestBetweenWords(t *testing.T) {
6+
result := BetweenWords("mitochondria is the powerhouse of the cell", "🔪️")
7+
expected := "mitochondria🔪️is🔪️the🔪️powerhouse🔪️of🔪️the🔪️cell"
8+
9+
if result != expected {
10+
t.Errorf("FAILED: Expected "+expected+"\" got %v", result)
11+
} else {
12+
t.Log("PASSED")
13+
}
14+
}
15+
16+
func TestBetweenLetter(t *testing.T) {
17+
result := BetweenLetters("mitochondria", "🔪️")
18+
expected := "M🔪️I🔪️T🔪️O🔪️C🔪️H🔪️O🔪️N🔪️D🔪️R🔪️I🔪️A"
19+
20+
if result != expected {
21+
t.Errorf("FAILED: Expected "+expected+"\" got %v", result)
22+
} else {
23+
t.Log("PASSED")
24+
}
25+
}
26+
27+
func TestClap(t *testing.T) {
28+
result := Clap("mitochondria is the powerhouse of the cell")
29+
expected := "mitochondria👏️is👏️the👏️powerhouse👏️of👏️the👏️cell"
30+
31+
if result != expected {
32+
t.Errorf("FAILED: Expected "+expected+"\" got %v", result)
33+
} else {
34+
t.Log("PASSED")
35+
}
36+
37+
result = Clap("mitochondria")
38+
expected = "M👏️I👏️T👏️O👏️C👏️H👏️O👏️N👏️D👏️R👏️I👏️A"
39+
40+
if result != expected {
41+
t.Errorf("FAILED: Expected "+expected+"\" got %v", result)
42+
} else {
43+
t.Log("PASSED")
44+
}
45+
}
46+
47+
func TesEmoji(t *testing.T) {
48+
result := Emoji("mitochondria is the powerhouse of the cell", "🔪️")
49+
expected := "mitochondria🔪️is🔪️the🔪️powerhouse🔪️of🔪️the🔪️cell"
50+
51+
if result != expected {
52+
t.Errorf("FAILED: Expected "+expected+"\" got %v", result)
53+
} else {
54+
t.Log("PASSED")
55+
}
56+
57+
result = Emoji("mitochondria", "🔪️")
58+
expected = "M🔪️I🔪️T🔪️O🔪️C🔪️H🔪️O🔪️N🔪️D🔪️R🔪️I🔪️A"
59+
60+
if result != expected {
61+
t.Errorf("FAILED: Expected "+expected+"\" got %v", result)
62+
} else {
63+
t.Log("PASSED")
64+
}
65+
}

clap/go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/asvvvad/clap/clap
2+
3+
go 1.14

go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/asvvvad/clap
2+
3+
go 1.14

main.go

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"io/ioutil"
7+
"os"
8+
9+
"github.com/asvvvad/clap/clap"
10+
"github.com/asvvvad/clap/clap/b"
11+
"github.com/atotto/clipboard"
12+
)
13+
14+
func main() {
15+
var emoji string
16+
var file string
17+
var stdin bool
18+
var bf bool
19+
var print bool
20+
var noOutput bool
21+
22+
flag.StringVar(&emoji, "emoji", "👏️", "Set emoji to use.")
23+
flag.StringVar(&file, "file", "", "Use text from file")
24+
flag.BoolVar(&stdin, "stdin", false, "Use text from stdin")
25+
flag.BoolVar(&bf, "b", false, "Replace the letter B with 🅱️ emoji")
26+
flag.BoolVar(&print, "print", false, "Print result.")
27+
flag.BoolVar(&noOutput, "no-out", false, "No output on success; use when starting it with a system shortcut")
28+
29+
flag.Usage = func() {
30+
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
31+
flag.PrintDefaults()
32+
fmt.Println("C👏️L👏️A👏️P by asvvvad (c)lap 2020 - https://github.com/asvvvad/clap")
33+
}
34+
35+
flag.Parse()
36+
37+
// The string that will contain the input text
38+
var text string
39+
var err error
40+
var bytes []byte
41+
42+
if stdin {
43+
bytes, err = ioutil.ReadAll(os.Stdin)
44+
text = string(bytes)
45+
} else if file != "" {
46+
bytes, err = ioutil.ReadFile(file)
47+
text = string(bytes)
48+
} else {
49+
text, err = clipboard.ReadAll()
50+
}
51+
52+
if err != nil {
53+
fmt.Println(err)
54+
os.Exit(1)
55+
}
56+
57+
// The string that will contain the final result
58+
result := ""
59+
60+
if emoji != "" {
61+
result = clap.Emoji(text, emoji)
62+
} else {
63+
result = clap.Clap(text)
64+
}
65+
66+
if bf {
67+
result = b.B(result)
68+
}
69+
70+
if print {
71+
fmt.Println(result)
72+
} else {
73+
err := clipboard.WriteAll(result)
74+
if err != nil {
75+
fmt.Println(err)
76+
// Print out in case of unsupported system
77+
fmt.Println(result)
78+
os.Exit(1)
79+
}
80+
if !noOutput {
81+
fmt.Println("Clapped👏️and👏️copied!")
82+
}
83+
}
84+
}

0 commit comments

Comments
 (0)