Passed
Pull Request — master (#1074)
by Tolga
02:29
created

internal.createLine   A

Complexity

Conditions 2

Size

Total Lines 11
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nop 4
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
1
package internal
2
3
import (
4
	"fmt"
5
	"strings"
6
7
	"github.com/fatih/color"
8
)
9
10
// Identifier is the unique identifier for the Permify.
11
var Identifier = ""
12
13
/*
14
✨ OneLiner: Open-source authorization service inspired by Google Zanzibar
15
16
📚 Docs: https://docs.permify.co
17
🐙 GitHub: https://github.com/Permify/permify
18
📝 Blog: https://permify.co/blog
19
20
💬 Discord: https://discord.gg/n6KfzYxhPp
21
🐦 Twitter: https://twitter.com/GetPermify
22
💼 LinkedIn: https://www.linkedin.com/company/permifyco
23
*/
24
const (
25
	// Version is the last release of the Permify (e.g. v0.1.0)
26
	Version = "v0.7.5"
27
)
28
29
// Function to create a single line of the ASCII art with centered content and color
30
func createLine(content string, totalWidth int, borderColor, contentColor *color.Color) string {
31
	contentLength := len(content)
32
	paddingWidth := (totalWidth - contentLength - 4) / 2
33
	if paddingWidth < 0 {
34
		paddingWidth = 0
35
	}
36
	leftPadding := strings.Repeat(" ", paddingWidth)
37
	rightPadding := strings.Repeat(" ", totalWidth-2-contentLength-paddingWidth)
38
	border := borderColor.Sprint("│")
39
	contentWithColor := contentColor.Sprintf("%s%s%s", leftPadding, content, rightPadding)
40
	return fmt.Sprintf("%s%s%s", border, contentWithColor, border)
41
}
42
43
func PrintBanner() {
44
	borderColor := color.New(color.FgWhite)
45
	contentColor := color.New(color.FgWhite)
46
47
	versionInfo := fmt.Sprintf("Permify %s", Version)
48
49
	lines := []string{
50
		borderColor.Sprint("┌────────────────────────────────────────────────────────┐"),
51
		createLine(versionInfo, 58, borderColor, color.New(color.FgBlue)),
52
		createLine("Fine-grained Authorization Service", 58, borderColor, contentColor),
53
		createLine("", 58, borderColor, contentColor),
54
		createLine("docs: ............... https://docs.permify.co", 58, borderColor, contentColor),
55
		createLine("github: .. https://github.com/Permify/permify", 58, borderColor, contentColor),
56
		createLine("blog: ............... https://permify.co/blog", 58, borderColor, contentColor),
57
		createLine("", 58, borderColor, contentColor),
58
		borderColor.Sprint("└────────────────────────────────────────────────────────┘"),
59
	}
60
61
	for _, line := range lines {
62
		fmt.Println(line)
63
	}
64
}
65