]> git.lizzy.rs Git - micro.git/blob - internal/config/autosave.go
Adds options for tab bar and tab color reversing (#2480)
[micro.git] / internal / config / autosave.go
1 package config
2
3 import (
4         "sync"
5         "time"
6 )
7
8 var Autosave chan bool
9 var autotime int
10
11 // lock for autosave
12 var autolock sync.Mutex
13
14 func init() {
15         Autosave = make(chan bool)
16 }
17
18 func SetAutoTime(a int) {
19         autolock.Lock()
20         autotime = a
21         autolock.Unlock()
22 }
23
24 func GetAutoTime() int {
25         autolock.Lock()
26         a := autotime
27         autolock.Unlock()
28         return a
29 }
30
31 func StartAutoSave() {
32         go func() {
33                 for {
34                         autolock.Lock()
35                         a := autotime
36                         autolock.Unlock()
37                         if a < 1 {
38                                 break
39                         }
40                         time.Sleep(time.Duration(a) * time.Second)
41                         Autosave <- true
42                 }
43         }()
44 }