summaryrefslogtreecommitdiff
path: root/ui/views/views.go
blob: 18c112479220ee8b134ddf75bf5b1a68c4a7a450 (plain)
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
package views

import (
	"os"
	"os/exec"

	"golang.org/x/term"
)

var logo = `
▗▄▄▖  ▗▄▖ ▗▖ ▗▖ ▗▄▖ ▗▖  ▗▖▗▖  ▗▖ ▗▄▖ 
▐▌ ▐▌▐▌ ▐▌▐▌ ▐▌▐▌ ▐▌▐▛▚▖▐▌▐▛▚▖▐▌▐▌ ▐▌
▐▛▀▚▖▐▛▀▜▌▐▛▀▜▌▐▛▀▜▌▐▌ ▝▜▌▐▌ ▝▜▌▐▛▀▜▌
▐▌ ▐▌▐▌ ▐▌▐▌ ▐▌▐▌ ▐▌▐▌  ▐▌▐▌  ▐▌▐▌ ▐▌
`

// Get terminal size dynamically
func GetTerminalSize() (width, height int) {
	fd := int(os.Stdin.Fd())
	if w, h, err := term.GetSize(fd); err == nil {
		return w, h
	}
	return 80, 24 // Default size if detection fails
}

// Clear terminal screen
func ClearScreen() {
	cmd := exec.Command("clear") // Unix (Linux/macOS)
	if os.Getenv("OS") == "Windows_NT" {
		cmd = exec.Command("cmd", "/c", "cls") // Windows
	}
	cmd.Stdout = os.Stdout
	cmd.Run()
}

func getFormWidth(width int) int {
	formWidth := width * 2 / 3
	if formWidth > 80 {
		formWidth = 80 // Cap at 80 chars for readability
	} else if formWidth < 40 {
		formWidth = width - 4 // For small terminals
	}

	return formWidth
}