8 "github.com/zyedidia/micro/internal/config"
9 "github.com/zyedidia/micro/pkg/terminfo"
10 "github.com/zyedidia/tcell"
13 // Screen is the tcell screen we use to draw to the terminal
14 // Synchronization is used because we poll the screen on a separate
15 // thread and sometimes the screen is shut down by the main thread
16 // (for example on TermMessage) so we don't want to poll a nil/shutdown
17 // screen. TODO: maybe we should worry about polling and drawing at the
19 var Screen tcell.Screen
21 var DrawChan chan bool
35 // TempFini shuts the screen down temporarily
36 func TempFini() bool {
37 screenWasNil := Screen == nil
47 // TempStart restarts the screen after it was temporarily disabled
48 func TempStart(screenWasNil bool) {
55 // Init creates and initializes the tcell screen
57 DrawChan = make(chan bool, 8)
59 // Should we enable true color?
60 truecolor := os.Getenv("MICRO_TRUECOLOR") == "1"
62 tcelldb := os.Getenv("TCELLDB")
63 os.Setenv("TCELLDB", config.ConfigDir+"/.tcelldb")
65 // In order to enable true color, we have to set the TERM to `xterm-truecolor` when
66 // initializing tcell, but after that, we can set the TERM back to whatever it was
67 oldTerm := os.Getenv("TERM")
69 os.Setenv("TERM", "xterm-truecolor")
74 Screen, err = tcell.NewScreen()
76 if err == tcell.ErrTermNotFound {
77 err = terminfo.WriteDB(config.ConfigDir + "/.tcelldb")
80 fmt.Println("Fatal: Micro could not create terminal database file", config.ConfigDir+"/.tcelldb")
83 Screen, err = tcell.NewScreen()
86 fmt.Println("Fatal: Micro could not initialize a Screen.")
91 fmt.Println("Fatal: Micro could not initialize a Screen.")
95 if err = Screen.Init(); err != nil {
100 // Now we can put the TERM back to what it was before
102 os.Setenv("TERM", oldTerm)
105 if config.GetGlobalOption("mouse").(bool) {
109 os.Setenv("TCELLDB", tcelldb)