From 400a81fdae4ea1ff2263024a7cd0618fc31076ca Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Thu, 3 Apr 2025 21:47:18 +0200 Subject: Use TUI instead of Web --- ui/views/views.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 ui/views/views.go (limited to 'ui/views/views.go') diff --git a/ui/views/views.go b/ui/views/views.go new file mode 100644 index 0000000..18c1124 --- /dev/null +++ b/ui/views/views.go @@ -0,0 +1,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 +} -- cgit v1.2.3-18-g5258