mirror of
https://github.com/zyedidia/micro.git
synced 2026-02-05 14:40:20 +09:00
Synchronize screen
This commit is contained in:
@@ -13,12 +13,7 @@ import (
|
||||
// This only works on linux and has no default binding.
|
||||
// This code was adapted from the suspend code in nsf/godit
|
||||
func (*BufHandler) Suspend() bool {
|
||||
screenWasNil := screen.Screen == nil
|
||||
|
||||
if !screenWasNil {
|
||||
screen.Screen.Fini()
|
||||
screen.Screen = nil
|
||||
}
|
||||
screen.TempFini()
|
||||
|
||||
// suspend the process
|
||||
pid := syscall.Getpid()
|
||||
@@ -27,9 +22,7 @@ func (*BufHandler) Suspend() bool {
|
||||
util.TermMessage(err)
|
||||
}
|
||||
|
||||
if !screenWasNil {
|
||||
screen.Init()
|
||||
}
|
||||
screen.TempStart()
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -144,8 +144,9 @@ func main() {
|
||||
go func() {
|
||||
events = make(chan tcell.Event)
|
||||
for {
|
||||
// TODO: fix race condition with screen.Screen = nil
|
||||
screen.Lock()
|
||||
events <- screen.Screen.PollEvent()
|
||||
screen.Unlock()
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package screen
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"github.com/zyedidia/micro/cmd/micro/config"
|
||||
"github.com/zyedidia/micro/cmd/micro/terminfo"
|
||||
@@ -10,6 +11,34 @@ import (
|
||||
)
|
||||
|
||||
var Screen tcell.Screen
|
||||
var lock sync.Mutex
|
||||
|
||||
func Lock() {
|
||||
lock.Lock()
|
||||
}
|
||||
|
||||
func Unlock() {
|
||||
lock.Unlock()
|
||||
}
|
||||
|
||||
var screenWasNil bool
|
||||
|
||||
func TempFini() {
|
||||
screenWasNil := Screen == nil
|
||||
|
||||
if !screenWasNil {
|
||||
Lock()
|
||||
Screen.Fini()
|
||||
Screen = nil
|
||||
}
|
||||
}
|
||||
|
||||
func TempStart() {
|
||||
if !screenWasNil {
|
||||
Init()
|
||||
Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
// Init creates and initializes the tcell screen
|
||||
func Init() {
|
||||
@@ -64,6 +93,4 @@ func Init() {
|
||||
}
|
||||
|
||||
os.Setenv("TCELLDB", tcelldb)
|
||||
|
||||
// Screen.SetStyle(defStyle)
|
||||
}
|
||||
|
||||
@@ -16,11 +16,7 @@ import (
|
||||
// This will write the message, and wait for the user
|
||||
// to press and key to continue
|
||||
func TermMessage(msg ...interface{}) {
|
||||
screenWasNil := screen.Screen == nil
|
||||
if !screenWasNil {
|
||||
screen.Screen.Fini()
|
||||
screen.Screen = nil
|
||||
}
|
||||
screen.TempFini()
|
||||
|
||||
fmt.Println(msg...)
|
||||
fmt.Print("\nPress enter to continue")
|
||||
@@ -28,9 +24,7 @@ func TermMessage(msg ...interface{}) {
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
reader.ReadString('\n')
|
||||
|
||||
if !screenWasNil {
|
||||
screen.Init()
|
||||
}
|
||||
screen.TempStart()
|
||||
}
|
||||
|
||||
// TermError sends an error to the user in the terminal. Like TermMessage except formatted
|
||||
|
||||
Reference in New Issue
Block a user