-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
output.go
110 lines (93 loc) · 2.11 KB
/
output.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* Copyright (c) Cherri
*/
package main
import (
"fmt"
"github.com/electrikmilk/args-parser"
"os"
"os/exec"
)
// writeFile writes plist in bytes to filename.
func writeFile(filename string, debug string) {
var writeDebugOutput = args.Using("debug")
if writeDebugOutput {
fmt.Printf("Writing to %s...", debug)
}
writeErr := os.WriteFile(filename, []byte(compiled), 0600)
handle(writeErr)
if writeDebugOutput {
fmt.Println(ansi("Done.", green))
}
}
// createShortcut writes the Shortcut files to disk and signs them if the unsigned argument is not unused.
func createShortcut() {
var path = fmt.Sprintf("%s%s", relativePath, workflowName)
if args.Using("debug") {
writeFile(path+".plist", workflowName+".plist")
}
writeFile(path+unsignedEnd, workflowName+unsignedEnd)
inputPath = fmt.Sprintf("%s%s%s", relativePath, workflowName, unsignedEnd)
if !args.Using("skip-sign") {
if args.Using("hubsign") {
hubSign()
} else {
sign()
}
removeUnsigned()
}
if args.Using("import") {
openShortcut()
}
}
func openShortcut() {
var _, importErr = exec.Command("open", outputPath).Output()
handle(importErr)
}
func printChar(ch rune) {
var currentChar string
switch ch {
case ' ':
currentChar = "SPACE"
case '\t':
currentChar = "TAB"
case '\n':
currentChar = "LF"
case -1:
currentChar = "EMPTY"
default:
currentChar = string(ch)
}
fmt.Printf("%s %d:%d\n", currentChar, lineIdx+1, lineCharIdx)
}
type outputType int
const (
bold outputType = 1
dim outputType = 2
italic outputType = 3
underline outputType = 4
red outputType = 31
green outputType = 32
yellow outputType = 33
cyan outputType = 36
)
const CSI = "\033["
func ansi(message string, typeOf ...outputType) string {
if args.Using("no-ansi") {
return message
}
var formattedMessage string
for _, t := range typeOf {
formattedMessage += fmt.Sprintf("%s%dm", CSI, t)
}
formattedMessage += message + "\033[0m"
return formattedMessage
}
func exit(message string) {
fmt.Println(ansi("\nError: "+message+"\n", red))
if args.Using("debug") {
panicDebug(nil)
} else {
os.Exit(1)
}
}