github.com/jmigpin/editor@v1.6.0/editor.go (about) 1 // Source code editor in pure Go. 2 package main 3 4 import ( 5 "flag" 6 "fmt" 7 "log" 8 "os" 9 "runtime/pprof" 10 "strings" 11 12 "github.com/jmigpin/editor/core" 13 "github.com/jmigpin/editor/core/lsproto" 14 15 // imports that can't be imported from core (cyclic import) 16 _ "github.com/jmigpin/editor/core/contentcmds" 17 _ "github.com/jmigpin/editor/core/internalcmds" 18 ) 19 20 func main() { 21 opt := &core.Options{} 22 23 // flags 24 flag.StringVar(&opt.Font, "font", "regular", "font: regular, medium, mono, or a filename") 25 flag.Float64Var(&opt.FontSize, "fontsize", 12, "") 26 flag.StringVar(&opt.FontHinting, "fonthinting", "full", "font hinting: none, vertical, full") 27 flag.Float64Var(&opt.DPI, "dpi", 72, "monitor dots per inch") 28 flag.IntVar(&opt.TabWidth, "tabwidth", 8, "") 29 flag.IntVar(&opt.WrapLineRune, "wraplinerune", int('←'), "code for wrap line rune, can be set to zero") 30 flag.StringVar(&opt.ColorTheme, "colortheme", "light", "available: light, dark, acme") 31 flag.IntVar(&opt.CommentsColor, "commentscolor", 0, "Colorize comments. Can be set to zero to use a percentage of the font color. Ex: 0=auto, 1=Black, 0xff0000=red.") 32 flag.IntVar(&opt.StringsColor, "stringscolor", 0, "Colorize strings. Can be set to zero to not colorize. Ex: 0xff0000=red.") 33 flag.IntVar(&opt.ScrollBarWidth, "scrollbarwidth", 0, "Textarea scrollbar width in pixels. A value of 0 takes 3/4 of the font size.") 34 flag.BoolVar(&opt.ScrollBarLeft, "scrollbarleft", true, "set scrollbars on the left side") 35 flag.BoolVar(&opt.Shadows, "shadows", true, "shadow effects on some elements") 36 flag.StringVar(&opt.SessionName, "sn", "", "open existing session") 37 flag.StringVar(&opt.SessionName, "sessionname", "", "open existing session") 38 flag.BoolVar(&opt.UseMultiKey, "usemultikey", false, "use multi-key to compose characters (Ex: [multi-key, ~, a] = ã)") 39 flag.StringVar(&opt.Plugins, "plugins", "", "comma separated string of plugin filenames") 40 flag.Var(&opt.LSProtos, "lsproto", "Language-server-protocol register options. Can be specified multiple times.\nFormat: language,fileExtensions,network{tcp|tcpclient|stdio},command,optional{stderr,nogotoimpl}\nFormat notes:\n\tif network is tcp, the command runs in a template with vars: {{.Addr}}.\n\tif network is tcpclient, the command should be an ipaddress.\nExamples:\n"+"\t"+strings.Join(lsproto.RegistrationExamples(), "\n\t")) 41 flag.Var(&opt.PreSaveHooks, "presavehook", "Run program before saving a file. Uses stdin/stdout. Can be specified multiple times. By default, a \"goimports\" entry is auto added if no entry is defined for the \"go\" language.\nFormat: language,fileExtensions,cmd\nExamples:\n"+ 42 "\tgo,.go,goimports\n"+ 43 "\tcpp,\".c .h .cpp .hpp\",clang-format\n"+ 44 "\tpython,.py,python_formatter") 45 cpuProfileFlag := flag.String("cpuprofile", "", "profile cpu filename") 46 version := flag.Bool("version", false, "output version and exit") 47 48 flag.Parse() 49 opt.Filenames = flag.Args() 50 51 log.SetFlags(log.Lshortfile) 52 53 if *version { 54 fmt.Printf("version: %v\n", core.Version()) 55 return 56 } 57 58 if *cpuProfileFlag != "" { 59 f, err := os.Create(*cpuProfileFlag) 60 if err != nil { 61 log.Println(err) 62 return 63 } 64 pprof.StartCPUProfile(f) 65 defer pprof.StopCPUProfile() 66 } 67 68 if err := core.RunEditor(opt); err != nil { 69 log.Println(err) // fatal() (os.exit) won't allow godebug to complete 70 return 71 } 72 }