mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-30 14:47:16 +09:00
Add autosave option
This commit is contained in:
30
internal/config/autosave.go
Normal file
30
internal/config/autosave.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
var Autosave chan bool
|
||||
|
||||
func init() {
|
||||
Autosave = make(chan bool)
|
||||
}
|
||||
|
||||
func StartAutoSave() {
|
||||
go func() {
|
||||
for {
|
||||
autotime := time.Duration(GlobalSettings["autosave"].(float64))
|
||||
if autotime < 1 {
|
||||
break
|
||||
}
|
||||
time.Sleep(autotime * time.Second)
|
||||
log.Println("Autosave")
|
||||
Autosave <- true
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func StopAutoSave() {
|
||||
GlobalSettings["autosave"] = float64(0)
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package config
|
||||
|
||||
const (
|
||||
DoubleClickThreshold = 400 // How many milliseconds to wait before a second click is not a double click
|
||||
AutosaveTime = 8 // Number of seconds to wait before autosaving
|
||||
)
|
||||
|
||||
var Bindings map[string]string
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -30,6 +30,7 @@ var (
|
||||
|
||||
// Options with validators
|
||||
var optionValidators = map[string]optionValidator{
|
||||
"autosave": validateNonNegativeValue,
|
||||
"tabsize": validatePositiveValue,
|
||||
"scrollmargin": validateNonNegativeValue,
|
||||
"scrollspeed": validateNonNegativeValue,
|
||||
@@ -150,7 +151,6 @@ func GetGlobalOption(name string) interface{} {
|
||||
|
||||
var defaultCommonSettings = map[string]interface{}{
|
||||
"autoindent": true,
|
||||
"autosave": false,
|
||||
"basename": false,
|
||||
"colorcolumn": float64(0),
|
||||
"cursorline": true,
|
||||
@@ -209,6 +209,7 @@ func DefaultCommonSettings() map[string]interface{} {
|
||||
}
|
||||
|
||||
var defaultGlobalSettings = map[string]interface{}{
|
||||
"autosave": float64(0),
|
||||
"colorscheme": "default",
|
||||
"infobar": true,
|
||||
"keymenu": false,
|
||||
|
||||
Reference in New Issue
Block a user