Created
February 23, 2021 21:28
-
-
Save rexroof/3a1384dcb43797c48dd415b5f367a489 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
/* | |
this code will fill your current terminal with a screen full of flowery emoji with optional message in the middle | |
inspired by this twitter thread: https://twitter.com/Dixie3Flatline/status/1363897259297972224 | |
and this gist: | |
https://gist.github.com/april/a4010daa8581626eb4670a08df558311 | |
*/ | |
import ( | |
"fmt" | |
"math/rand" | |
"os" | |
"strings" | |
"syscall" | |
"time" | |
"unsafe" | |
) | |
type winsize struct { | |
Row uint16 | |
Col uint16 | |
Xpixel uint16 | |
Ypixel uint16 | |
} | |
func getWindow() (int, int) { | |
ws := &winsize{} | |
retCode, _, errno := syscall.Syscall(syscall.SYS_IOCTL, | |
uintptr(syscall.Stdin), | |
uintptr(syscall.TIOCGWINSZ), | |
uintptr(unsafe.Pointer(ws))) | |
if int(retCode) == -1 { | |
panic(errno) | |
} | |
return int(ws.Col), int(ws.Row) | |
} | |
func printRow(width int, insert string) { | |
emoji := []string{"π¦", "π³", "π·", "πΈ", "πΊ", "π»", "πΌ", "π", "π", "π’", "π£", "π¦", "π°", "πΉ", "π¦"} | |
_width := int(width / 4) | |
if len(insert) > 0 { | |
insert = fmt.Sprintf(" %s ", insert) | |
_width = int((width - (len(insert) + 2)) / 4) | |
} | |
for i := 0; i < _width; i++ { // divide by two because our emoji take two chars? | |
randomIndex := rand.Intn(len(emoji)) | |
pick := emoji[randomIndex] | |
fmt.Print(pick) | |
} | |
fmt.Print(insert) | |
for i := 0; i < _width; i++ { // divide by two because our emoji take two chars? | |
randomIndex := rand.Intn(len(emoji)) | |
pick := emoji[randomIndex] | |
fmt.Print(pick) | |
} | |
fmt.Println() | |
} | |
func main() { | |
rand.Seed(time.Now().UnixNano()) | |
outputText := strings.Join(os.Args[1:], " ") | |
col, row := getWindow() | |
for x := 0; x < row-1; x++ { | |
// if we're in the middle | |
if x == int(row/2) { | |
printRow(col, outputText) | |
// blank box above and below our text | |
} else if x == int(row/2)-1 { | |
printRow(col, strings.Repeat(" ", len(outputText))) | |
} else if x == int(row/2)+1 { | |
printRow(col, strings.Repeat(" ", len(outputText))) | |
} else { | |
printRow(col, "") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment