Compare commits
3 Commits
c198177284
...
8ef90ffd66
Author | SHA1 | Date |
---|---|---|
|
8ef90ffd66 | |
|
9c73761827 | |
|
2ad513de61 |
|
@ -8,6 +8,8 @@ import (
|
|||
"os"
|
||||
|
||||
"git.kettek.net/accord/service/internal/cfg"
|
||||
"git.kettek.net/accord/service/internal/version"
|
||||
"git.kettek.net/accord/service/pkg/istty"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -18,9 +20,14 @@ func main() {
|
|||
readChannel := make(chan AMessage)
|
||||
quitChannel := make(chan error)
|
||||
|
||||
// Start our STDIN read loop
|
||||
if cfg.UsePipes {
|
||||
go readLoop(os.Stdin, quitChannel, readChannel)
|
||||
if istty.Is() {
|
||||
fmt.Println("Running from TTY, starting as stand-alone service.")
|
||||
fmt.Printf(" Git Id: %s\n", version.GitCommitId)
|
||||
} else {
|
||||
// Start our STDIN read loop
|
||||
if cfg.UsePipes {
|
||||
go readLoop(os.Stdin, quitChannel, readChannel)
|
||||
}
|
||||
}
|
||||
|
||||
// Begin waiting for data on our channels.
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
// +build darwin,dragonfly,freebsd,linux,netbsd,openbsd,solaris
|
||||
package version
|
||||
|
||||
//go:generate sh ./generate_nix.sh
|
|
@ -0,0 +1,9 @@
|
|||
echo "// Code generated automatically; DO NOT EDIT." > version.go
|
||||
echo "package version" >> version.go
|
||||
echo "" >> version.go
|
||||
echo "var (" >> version.go
|
||||
echo " // GitCommitId provides the git commit id used to build this service." >> version.go
|
||||
echo -n " GitCommitId string = \"" >> version.go
|
||||
git log -n1 --format="%h" | tr -d '\n' >> version.go
|
||||
echo "\"" >> version.go
|
||||
echo ")" >> version.go
|
|
@ -0,0 +1,7 @@
|
|||
// Code generated automatically; DO NOT EDIT.
|
||||
package version
|
||||
|
||||
var (
|
||||
// GitCommitId provides the git commit id used to build this service.
|
||||
GitCommitId string = "c198177"
|
||||
)
|
|
@ -0,0 +1,17 @@
|
|||
package istty
|
||||
|
||||
// #cgo CFLAGS: -g -Wall
|
||||
// #include "istty.h"
|
||||
import "C"
|
||||
|
||||
// Is returns if the process context is a TTY.
|
||||
func Is() bool {
|
||||
t := C.isTTY()
|
||||
|
||||
return bool(t)
|
||||
}
|
||||
|
||||
// Close closes the TTY if possible.
|
||||
func Close() {
|
||||
C.closeTTY()
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
#ifdef _WIN32
|
||||
#if _WIN32_WINNT < 0x0500
|
||||
#undef _WIN32_WINNT
|
||||
#define _WIN32_WINNT 0x0500
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#include <stdbool.h>
|
||||
#include "Wincon.h"
|
||||
|
||||
bool isTTY() {
|
||||
HWND consoleWnd = GetConsoleWindow();
|
||||
DWORD dwProcessId;
|
||||
GetWindowThreadProcessId(consoleWnd, &dwProcessId);
|
||||
if (GetCurrentProcessId()==dwProcessId) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void closeTTY() {
|
||||
ShowWindow(GetConsoleWindow(), SW_HIDE);
|
||||
}
|
||||
#elif defined(__APPLE__) || defined(__linux) || defined(__unix) || defined(__posix)
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
bool isTTY() {
|
||||
if (isatty(fileno(stdin))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void closeTTY() {}
|
||||
#endif
|
Loading…
Reference in New Issue