fmt.Println("Fatal: Micro could not initialize a Screen.")
os.Exit(1)
}
-
- sigterm = make(chan os.Signal, 1)
- sighup = make(chan os.Signal, 1)
- signal.Notify(sigterm, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT)
- signal.Notify(sighup, syscall.SIGHUP)
-
m := clipboard.SetMethod(config.GetGlobalOption("clipboard").(string))
clipErr := clipboard.Initialize(m)
screen.Events = make(chan tcell.Event)
+ sigterm = make(chan os.Signal, 1)
+ sighup = make(chan os.Signal, 1)
+ signal.Notify(sigterm, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT)
+ signal.Notify(sighup, syscall.SIGHUP)
+
// Here is the event loop which runs in a separate thread
go func() {
for {
When the buffer is closed, the backup will be removed.
* 'ignore' will ignore the backup, discarding its changes. The backup file
will be removed.
+* 'abort' will abort the open operation, and instead open an empty buffer.
-Options: [r]ecover, [i]gnore: `
+Options: [r]ecover, [i]gnore, [a]bort: `
var backupRequestChan chan *Buffer
// ApplyBackup applies the corresponding backup file to this buffer (if one exists)
// Returns true if a backup was applied
-func (b *Buffer) ApplyBackup(fsize int64) bool {
+func (b *Buffer) ApplyBackup(fsize int64) (bool, bool) {
if b.Settings["backup"].(bool) && !b.Settings["permbackup"].(bool) && len(b.Path) > 0 && b.Type == BTDefault {
backupfile := filepath.Join(config.ConfigDir, "backups", util.EscapePath(b.AbsPath))
if info, err := os.Stat(backupfile); err == nil {
defer backup.Close()
t := info.ModTime()
msg := fmt.Sprintf(backupMsg, t.Format("Mon Jan _2 at 15:04, 2006"), util.EscapePath(b.AbsPath))
- choice := screen.TermPrompt(msg, []string{"r", "i", "recover", "ignore"}, true)
+ choice := screen.TermPrompt(msg, []string{"r", "i", "a", "recover", "ignore", "abort"}, true)
- if choice%2 == 0 {
+ if choice%3 == 0 {
// recover
b.LineArray = NewLineArray(uint64(fsize), FFAuto, backup)
b.isModified = true
- return true
- } else if choice%2 == 1 {
+ return true, true
+ } else if choice%3 == 1 {
// delete
os.Remove(backupfile)
+ } else if choice%3 == 2 {
+ return false, false
}
}
}
}
- return false
+ return false, true
}
return nil, err
} else {
buf = NewBuffer(file, util.FSize(file), filename, cursorLoc, btype)
+ if buf == nil {
+ return nil, errors.New("could not open file")
+ }
}
if readonly && prompt != nil {
b.Settings["encoding"] = "utf-8"
}
- hasBackup = b.ApplyBackup(size)
+ var ok bool
+ hasBackup, ok = b.ApplyBackup(size)
+ if !ok {
+ return NewBufferFromString("", "", btype)
+ }
if !hasBackup {
reader := bufio.NewReader(transform.NewReader(r, enc.NewDecoder()))