From af0471794c91e862c2a21bc0439837c39c980348 Mon Sep 17 00:00:00 2001 From: Fred Date: Sat, 18 Jul 2020 20:52:12 +0100 Subject: [PATCH] redirect terminal when elevated mode --- commands.go | 1 - logger.go | 3 +-- main.go | 8 +++++++- win/taskscheduler.go | 3 +-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/commands.go b/commands.go index d726d3fe..8b8ab870 100644 --- a/commands.go +++ b/commands.go @@ -324,7 +324,6 @@ func statusSchedule(c *config.Config, flags commandLineFlags, args []string) err func testElevationCommand(c *config.Config, flags commandLineFlags, args []string) error { if flags.isChild { client := remote.NewClient(flags.parentPort) - term.SetOutput(term.NewRemoteTerm(client)) term.Print("first line", "\n") term.Println("second", "one") term.Printf("value = %d", 11) diff --git a/logger.go b/logger.go index 4e735f4a..98caa5ad 100644 --- a/logger.go +++ b/logger.go @@ -7,8 +7,7 @@ import ( "github.com/creativeprojects/resticprofile/remote" ) -func setupRemoteLogger(flags commandLineFlags) { - client := remote.NewClient(flags.parentPort) +func setupRemoteLogger(client *remote.Client) { logger := clog.NewLogger(client) client.SetLogPrefix("elevated user: ") clog.SetDefaultLogger(logger) diff --git a/main.go b/main.go index b7e6296e..02e29f4c 100644 --- a/main.go +++ b/main.go @@ -11,11 +11,14 @@ import ( "text/tabwriter" "time" + "github.com/creativeprojects/resticprofile/term" + "github.com/creativeprojects/clog" "github.com/creativeprojects/resticprofile/config" "github.com/creativeprojects/resticprofile/constants" "github.com/creativeprojects/resticprofile/filesearch" "github.com/creativeprojects/resticprofile/priority" + "github.com/creativeprojects/resticprofile/remote" "github.com/mackerelio/go-osstat/memory" ) @@ -82,7 +85,10 @@ func main() { } } else if flags.isChild { // use a remote logger - setupRemoteLogger(flags) + client := remote.NewClient(flags.parentPort) + setupRemoteLogger(client) + // also redirect the terminal through the client + term.SetOutput(term.NewRemoteTerm(client)) } else { // Use the console logger setupConsoleLogger(flags) diff --git a/win/taskscheduler.go b/win/taskscheduler.go index 50fc21b6..c4d3deb7 100644 --- a/win/taskscheduler.go +++ b/win/taskscheduler.go @@ -4,7 +4,6 @@ package win import ( "fmt" - "os" "os/user" "strings" "text/tabwriter" @@ -251,7 +250,7 @@ func (s *TaskScheduler) Status() error { if registeredTask == nil { return fmt.Errorf("%w: %s", ErrorNotRegistered, taskName) } - writer := tabwriter.NewWriter(os.Stdout, 2, 2, 2, ' ', 0) + writer := tabwriter.NewWriter(term.GetOutput(), 2, 2, 2, ' ', 0) fmt.Fprintf(writer, "Task\t%s\n", registeredTask.Path) fmt.Fprintf(writer, "User\t%s\n", registeredTask.Definition.Principal.UserID) if registeredTask.Definition.Actions != nil && len(registeredTask.Definition.Actions) > 0 {