2019-11-02 10:54:41 +09:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-12-23 00:07:42 +09:00
|
|
|
"fmt"
|
2020-12-21 19:57:18 +09:00
|
|
|
"os"
|
2022-04-24 15:46:56 +09:00
|
|
|
"runtime"
|
2020-12-23 00:07:42 +09:00
|
|
|
|
|
|
|
// "runtime/pprof"
|
2021-05-20 17:37:09 +09:00
|
|
|
// "github.com/felixge/fgprof"
|
2020-12-21 19:57:18 +09:00
|
|
|
|
2019-11-02 10:54:41 +09:00
|
|
|
"github.com/akiyosi/goneovim/editor"
|
2020-12-23 00:07:42 +09:00
|
|
|
"github.com/jessevdk/go-flags"
|
2022-04-24 15:46:56 +09:00
|
|
|
"github.com/mattn/go-isatty"
|
|
|
|
"github.com/therecipe/qt/core"
|
2019-11-02 10:54:41 +09:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2020-12-23 00:07:42 +09:00
|
|
|
// // profile the application
|
|
|
|
// // https://blog.golang.org/pprof
|
|
|
|
// // After running the app, do the following:
|
|
|
|
// // $ go tool pprof -http=localhost:9090 cpuprofile
|
|
|
|
// f, err := os.Create("cpuprofile")
|
|
|
|
// if err != nil {
|
|
|
|
// os.Exit(1)
|
|
|
|
// }
|
|
|
|
// defer f.Close()
|
|
|
|
// pprof.StartCPUProfile(f)
|
|
|
|
// defer pprof.StopCPUProfile()
|
|
|
|
|
2021-05-20 17:37:09 +09:00
|
|
|
// // fgprof
|
|
|
|
// f, err := os.Create("cpuprofile")
|
|
|
|
// if err != nil {
|
|
|
|
// os.Exit(1)
|
|
|
|
// }
|
|
|
|
// fgprofStop := fgprof.Start(f, fgprof.FormatPprof)
|
|
|
|
// defer func() {
|
|
|
|
// err = fgprofStop()
|
|
|
|
// if err != nil {
|
|
|
|
// fmt.Println(err)
|
|
|
|
// }
|
|
|
|
// err = f.Close()
|
|
|
|
// if err != nil {
|
|
|
|
// fmt.Println(err)
|
|
|
|
// }
|
|
|
|
// }()
|
|
|
|
|
2020-12-23 00:07:42 +09:00
|
|
|
// parse args
|
|
|
|
options, args := parseArgs()
|
2021-08-02 23:08:12 +09:00
|
|
|
if options.Version {
|
2022-04-24 15:46:56 +09:00
|
|
|
fmt.Println(editor.Version)
|
|
|
|
os.Exit(0)
|
2021-08-02 23:08:12 +09:00
|
|
|
}
|
2021-01-17 11:24:13 +09:00
|
|
|
|
2022-04-24 15:46:56 +09:00
|
|
|
nofork := options.Nofork
|
|
|
|
|
|
|
|
// In Windows, nofork always true
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
nofork = true
|
|
|
|
}
|
|
|
|
// In MacOS X do not fork when the process is not launched from a tty
|
|
|
|
if runtime.GOOS == "darwin" {
|
|
|
|
if !isatty.IsTerminal(os.Stdin.Fd()) {
|
|
|
|
nofork = true
|
|
|
|
}
|
|
|
|
}
|
2022-07-05 23:21:15 +09:00
|
|
|
// If ssh option specified
|
|
|
|
if options.Ssh != "" {
|
|
|
|
nofork = true
|
|
|
|
}
|
2021-01-17 11:24:13 +09:00
|
|
|
// start editor
|
2022-04-24 15:46:56 +09:00
|
|
|
if nofork {
|
|
|
|
editor.InitEditor(options, args)
|
|
|
|
} else {
|
|
|
|
p := core.NewQProcess(nil)
|
|
|
|
var pid int64
|
2022-06-19 00:40:50 +09:00
|
|
|
goneovim := core.NewQCoreApplication(len(os.Args), os.Args)
|
2022-04-24 15:46:56 +09:00
|
|
|
if !p.StartDetached2(
|
2022-06-19 00:40:50 +09:00
|
|
|
goneovim.ApplicationFilePath(),
|
|
|
|
append([]string{"--nofork"}, goneovim.Arguments()[1:]...),
|
2022-04-24 15:46:56 +09:00
|
|
|
"",
|
|
|
|
pid,
|
|
|
|
) {
|
|
|
|
fmt.Println("Unable to fork into background")
|
|
|
|
os.Exit(-1)
|
|
|
|
}
|
|
|
|
}
|
2020-12-23 00:07:42 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// parsArgs parse args
|
|
|
|
func parseArgs() (editor.Options, []string) {
|
|
|
|
var options editor.Options
|
|
|
|
parser := flags.NewParser(&options, flags.HelpFlag|flags.PassDoubleDash)
|
|
|
|
args, err := parser.ParseArgs(os.Args[1:])
|
|
|
|
if flagsErr, ok := err.(*flags.Error); ok {
|
|
|
|
switch flagsErr.Type {
|
|
|
|
case flags.ErrDuplicatedFlag:
|
|
|
|
case flags.ErrHelp:
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2020-12-21 19:57:18 +09:00
|
|
|
}
|
2020-12-17 01:31:07 +09:00
|
|
|
|
2020-12-23 00:07:42 +09:00
|
|
|
return options, args
|
2019-11-02 10:54:41 +09:00
|
|
|
}
|