diff --git a/go.mod b/go.mod index 34864fe..f91e102 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,8 @@ module github.com/asrul/linux-command-gpt go 1.18 + +require ( + golang.org/x/sys v0.6.0 // indirect + golang.org/x/term v0.6.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..275ee62 --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw= +golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= diff --git a/main.go b/main.go index 12a305c..1e4f0ce 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "time" "github.com/asrul/linux-command-gpt/gpt" + "golang.org/x/term" ) const ( @@ -58,6 +59,10 @@ func handleCommand(cmd string) int { } func main() { + width, _, err := term.GetSize(0) + if err != nil { + panic(err) + } currentUser, err := user.Current() if err != nil { panic(err) @@ -127,9 +132,9 @@ func main() { elapsed := time.Since(s).Seconds() elapsed = math.Round(elapsed*100) / 100 fmt.Printf("Completed in %v seconds\n", elapsed) - fmt.Printf("┌%s┐\n", strings.Repeat("─", len(r)+2)) - fmt.Printf("│ %s │\n", r) - fmt.Printf("└%s┘\n", strings.Repeat("─", len(r)+2)) + fmt.Println(strings.Repeat("─", width)) + fmt.Println(r) + fmt.Println(strings.Repeat("─", width)) fmt.Print("Are you sure you want to execute the command? (Y/n): ") fmt.Scanln(&c) if c != "Y" && c != "y" {