-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_cli.go
More file actions
99 lines (88 loc) · 2.4 KB
/
main_cli.go
File metadata and controls
99 lines (88 loc) · 2.4 KB
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
// main_cli.go
//go:build cli
// +build cli
package main
import (
"io"
"log"
"os"
"telewindow/lumberjack"
"telewindow/window"
)
func main() {
// Create a multi-writer that writes to both file and stdout
multiWriter := io.MultiWriter(&lumberjack.Logger{
Filename: "./telewindow.log",
MaxSize: 1, // megabytes
MaxBackups: 5,
MaxAge: 28, //days
Compress: false, // disabled by default
})
// Set the output of the default logger to the multi-writer
log.SetOutput(multiWriter)
if len(os.Args) < 2 {
log.Println("Usage: telewindow [command]")
log.Println("Commands:")
log.Println(" -Right Move window right")
log.Println(" -Left Move window left")
log.Println(" -Up Move window up")
log.Println(" -Down Move window down")
log.Println(" -Maximize Maximize active window")
log.Println(" -Restore Restore active window")
log.Println(" -SplitRight Split window right")
log.Println(" -SplitLeft Split window left")
log.Println(" -SplitUp Split window up")
log.Println(" -SplitDown Split window down")
log.Println(" -ToggleMaximize Toggle maximize/restore")
log.Println(" -NoOp No Operation (Used to bind over existing shortcuts)")
os.Exit(0)
}
command := os.Args[1]
log.Println("Received command:", command)
switch command {
case "-Right":
window.MoveActiveWindow(RightDirection)
case "-Left":
window.MoveActiveWindow(LeftDirection)
case "-Up":
window.MoveActiveWindow(UpDirection)
case "-Down":
window.MoveActiveWindow(DownDirection)
case "-Maximize":
window.MaximizeActiveWindow(nil)
case "-Restore":
window.RestoreActiveWindow(nil)
case "-SplitRight":
window.SplitActiveWindow(RightDirection)
case "-SplitLeft":
window.SplitActiveWindow(LeftDirection)
case "-SplitUp":
window.SplitActiveWindow(UpDirection)
case "-SplitDown":
window.SplitActiveWindow(DownDirection)
case "-ToggleMaximize":
maximized, err := window.IsActiveWindowMaximized(nil)
if err != nil {
log.Println("Error checking if window is maximized:", err)
exit(1)
}
if maximized {
window.RestoreActiveWindow(nil)
} else {
window.MaximizeActiveWindow(nil)
}
case "-NoOp":
// Do nothing
log.Println("No operation performed.")
exit(0)
default:
log.Println("Unknown command:", command)
exit(1)
}
exit(0)
}
func exit(code int) {
log.Println("")
log.Println("")
os.Exit(code)
}