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
Binary file modified .meta/demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func Execute() {
logLevel := uint8(logLevelParam)
logger.Setup(logLevel)
fullAddress := addressParam + ":" + strconv.Itoa(int(portParam))
// shell := fmt.Sprintf("[rcon@%v]", fullAddress)
password, err := determinePassword()
if err != nil {
logger.Critical.Fatal(err)
Expand Down
7 changes: 4 additions & 3 deletions cmd/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"
"strconv"
"strings"

"github.com/UltimateForm/tcprcon/internal/ansi"
"github.com/UltimateForm/tcprcon/internal/fullterm"
Expand Down Expand Up @@ -38,9 +39,9 @@ func runRconTerminal(client *client.RCONClient, ctx context.Context, logLevel ui
fmt.Fprintf(
app,
"(%v): RESPONSE TYPE %v\n%v\n",
ansi.Format(strconv.Itoa(int(streamedPacket.Id)), ansi.Yellow, ansi.Bold),
ansi.Format(strconv.Itoa(int(streamedPacket.Type)), ansi.Yellow, ansi.Bold),
ansi.Format(streamedPacket.BodyStr(), ansi.Yellow),
ansi.Format(strconv.Itoa(int(streamedPacket.Id)), ansi.Green, ansi.Bold),
ansi.Format(strconv.Itoa(int(streamedPacket.Type)), ansi.Green, ansi.Bold),
ansi.Format(strings.TrimRight(streamedPacket.BodyStr(), "\n\r")+"\n", ansi.Green),
)
}
}
Expand Down
3 changes: 3 additions & 0 deletions internal/ansi/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ const (
ExitAltScreen = "\033[?1049l"
Red = 31
Green = 32
BrightGreen = 92
Yellow = 33
Blue = 34
BrightBlue = 94
Magenta = 35
Cyan = 36
Bold = 1
DefaultColor = 39
Reset = 0
)
30 changes: 16 additions & 14 deletions internal/logger/logwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"io"
"log"
"os"

"github.com/UltimateForm/tcprcon/internal/ansi"
)

const (
Expand Down Expand Up @@ -91,30 +93,30 @@ func newWithCustomDestinations(level uint8, writer io.Writer) *LogWriter {
}

var (
Writer *LogWriter
writer *LogWriter
Info *log.Logger
Debug *log.Logger
Err *log.Logger
Warn *log.Logger
Critical *log.Logger
)

func SetupCustomDestination(level uint8, writer io.Writer) {
Writer = newWithCustomDestinations(level, writer)
Info = log.New(Writer.Info, "INF::", 0)
Debug = log.New(Writer.Debug, "DBG::", 0)
Err = log.New(Writer.Error, "ERR::", 0)
Warn = log.New(Writer.Warn, "WRN::", 0)
Critical = log.New(Writer.Critical, "CRT::", 0)
func setGlobalLoggers() {
Info = log.New(writer.Info, ansi.Format("INF::", ansi.DefaultColor), 0)
Debug = log.New(writer.Debug, ansi.Format("DBG::", ansi.Yellow), 0)
Err = log.New(writer.Error, ansi.Format("ERR::", ansi.Red), 0)
Warn = log.New(writer.Warn, ansi.Format("WRN::", ansi.Magenta), 0)
Critical = log.New(writer.Critical, ansi.Format("CRT::", ansi.Red), 0)
}

func SetupCustomDestination(level uint8, customWriter io.Writer) {
writer = newWithCustomDestinations(level, customWriter)
setGlobalLoggers()
}

func Setup(level uint8) {
Writer = New(level)
Info = log.New(Writer.Info, "INF::", 0)
Debug = log.New(Writer.Debug, "DBG::", 0)
Err = log.New(Writer.Error, "ERR::", 0)
Warn = log.New(Writer.Warn, "WRN::", 0)
Critical = log.New(Writer.Critical, "CRT::", 0)
writer = New(level)
setGlobalLoggers()
}

func init() {
Expand Down
29 changes: 0 additions & 29 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,4 @@ import (

func main() {
cmd.Execute()
// logger.Setup(logger.LevelDebug)
// ctx, cancel := context.WithCancel(context.Background())
// defer cancel()
// app := fullterm.CreateApp()
// errChan := make(chan error, 1)
// appRun := func() {
// errChan <- app.Run(ctx)
// }

// appWriter := func() {
// counter := 0
// for {
// select {
// case <-ctx.Done():
// return
// default:
// fmt.Fprintf(app, "Counter: %v\n\r", counter)
// counter++
// time.Sleep(time.Duration(time.Second * 1))
// }
// }
// }
// go appRun()
// go appWriter()

// if err := <-errChan; err != nil {
// cancel()
// logger.Critical.Fatal(app)
// }
}