Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
module servercommander

go 1.23.5

require fyne.io/fyne/v2 v2.4.5

replace fyne.io/fyne/v2 => ./third_party/fyne
8 changes: 4 additions & 4 deletions src/cmd/clear.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"os/exec"
"runtime"

"servercommander/src/ui"
"servercommander/src/console"
)

func clearCommand(args []string) error {
if ui.ClearConsole() {
ui.ApplicationBanner()
if console.ClearConsole() {
console.ApplicationBanner()
return nil
}

Expand All @@ -24,7 +24,7 @@ func clearCommand(args []string) error {
return fmt.Errorf("failed to clear the console: %w", err)
}

ui.ApplicationBanner()
console.ApplicationBanner()
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions src/cmd/exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"fmt"
"os"

"servercommander/src/ui"
"servercommander/src/console"
"servercommander/src/utils"
)

func exitCommand(args []string) error {
ui.GoodbyeBanner()
console.GoodbyeBanner()
fmt.Println(utils.Red, "Exiting the program...", utils.Reset)
os.Exit(0)
return nil
Expand Down
68 changes: 68 additions & 0 deletions src/console/console.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package console

import (
"bufio"
"fmt"
"os"
"runtime"
"strings"
"time"

"servercommander/src/utils"
)

// Run starts the interactive console loop using the provided executor to
// handle individual command lines.
func Run(executor func(string) error) error {
ApplicationBanner()

scanner := bufio.NewScanner(os.Stdin)
for {
fmt.Printf("%ssc>%s ", utils.Cyan, utils.Reset)

if !scanner.Scan() {
fmt.Println()
return scanner.Err()
}

line := strings.TrimSpace(scanner.Text())
if line == "" {
continue
}

if err := executor(line); err != nil {
fmt.Println(utils.Red, err.Error(), utils.Reset)
}
}
}

// ApplicationBanner prints the program banner in the console.
func ApplicationBanner() {
fmt.Println(utils.Cyan, "==============================")
fmt.Println(utils.Green, " Server Commander v1.0.1")
fmt.Println(utils.Cyan, "==============================", utils.Reset)
}

// GoodbyeBanner displays a small exit animation before terminating.
func GoodbyeBanner() {
fmt.Println(utils.Yellow, "Goodbye! The program will close in 3 seconds...", utils.Reset)
time.Sleep(time.Second)

for i := 3; i > 0; i-- {
fmt.Printf("%sClosing in %d seconds...\r", utils.Cyan, i)
time.Sleep(time.Second)
}

time.Sleep(2 * time.Second)
}

// ClearConsole tries to clear the terminal using ANSI escape sequences. It
// returns true when handled internally so callers can skip external commands.
func ClearConsole() bool {
if runtime.GOOS == "windows" {
return false
}

fmt.Print("\033[H\033[2J")
return true
}
4 changes: 2 additions & 2 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"log"

"servercommander/src/cmd"
"servercommander/src/ui"
"servercommander/src/console"
)

func main() {
if err := ui.RunStandaloneConsole(cmd.Execute); err != nil {
if err := console.Run(cmd.Execute); err != nil {
log.Fatal(err)
}
}
12 changes: 0 additions & 12 deletions src/ui/applicationBanner.go

This file was deleted.

Loading