aboutsummaryrefslogtreecommitdiffhomepage
path: root/cmd/util.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/util.go')
-rw-r--r--cmd/util.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/cmd/util.go b/cmd/util.go
new file mode 100644
index 0000000..93199da
--- /dev/null
+++ b/cmd/util.go
@@ -0,0 +1,29 @@
+package cmd
+
+import (
+ "github.com/nsfisis/term-clock/internal/term"
+)
+
+func calcSquareSize(scr *term.Screen) (int, int, int, int) {
+ // Calculate square width/height and offset.
+ scrW, scrH := scr.Size()
+ // 17
+ // <--------------->
+ // ### ### ### ### ^
+ // # # # # # # # # # |
+ // # # # # # # # # | 5
+ // # # # # # # # # # |
+ // ### ### ### ### v
+ squareW := scrW / (17 + 2)
+ squareH := scrH / (5 + 2)
+ if squareH > squareW {
+ squareH = squareW
+ }
+ if squareW > squareH*3/2 {
+ squareW = squareH * 3 / 2
+ }
+ xOffset := (scrW - squareW*17) / 2
+ yOffset := (scrH - squareH*5) / 2
+
+ return squareW, squareH, xOffset, yOffset
+}