Skip to content

Commit

Permalink
cmd: ipfs handle GUI environment on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
djdv committed Sep 15, 2019
1 parent 8c033f1 commit cee93bd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cmd/ipfs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import (
repo "github.com/ipfs/go-ipfs/repo"
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"

"github.com/ipfs/go-ipfs-cmds"
cmds "github.com/ipfs/go-ipfs-cmds"
"github.com/ipfs/go-ipfs-cmds/cli"
"github.com/ipfs/go-ipfs-cmds/http"
"github.com/ipfs/go-ipfs-config"
config "github.com/ipfs/go-ipfs-config"
u "github.com/ipfs/go-ipfs-util"
logging "github.com/ipfs/go-log"
loggables "github.com/libp2p/go-libp2p-loggables"
Expand Down Expand Up @@ -111,6 +111,9 @@ func mainRet() int {
os.Args[1] = "--help"
}
}
} else if insideGUI() { // if no args were passed, and we're in a GUI environment
// launch the daemon instead of launching a ghost window
os.Args = append(os.Args, "daemon")
}

// output depends on executable name passed in os.Args
Expand Down Expand Up @@ -170,6 +173,10 @@ func mainRet() int {
return 0
}

func insideGUI() bool {
return util.InsideGUI()
}

func checkDebug(req *cmds.Request) {
// check if user wants to debug. option OR env var.
debug, _ := req.Options["debug"].(bool)
Expand Down
7 changes: 7 additions & 0 deletions cmd/ipfs/util/ui.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//+build !windows

package util

func InsideGUI() bool {
return false
}
18 changes: 18 additions & 0 deletions cmd/ipfs/util/ui_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package util

import "golang.org/x/sys/windows"

func InsideGUI() bool {
conhostInfo := &windows.ConsoleScreenBufferInfo{}
if err := windows.GetConsoleScreenBufferInfo(windows.Stdout, conhostInfo); err != nil {
return false
}

if (conhostInfo.CursorPosition.X | conhostInfo.CursorPosition.Y) == 0 {
// console cursor has not moved prior to our execution
// high probability that we're not in a terminal
return true
}

return false
}

0 comments on commit cee93bd

Please sign in to comment.