]> git.lizzy.rs Git - micro.git/commitdiff
Warn for readonly instead of setting option
authorZachary Yedidia <zyedidia@gmail.com>
Wed, 19 May 2021 18:58:00 +0000 (14:58 -0400)
committerZachary Yedidia <zyedidia@gmail.com>
Wed, 19 May 2021 18:58:00 +0000 (14:58 -0400)
Fixes #2106

cmd/micro/micro.go
internal/buffer/buffer.go
internal/buffer/message.go

index 049be3370f107b2d10c95c751e0db22524857ec7..5427b7073288fd704da2eea71169349a237c7a68 100644 (file)
@@ -319,6 +319,8 @@ func main() {
                screen.TermMessage(err)
        }
 
+       action.InitGlobals()
+       buffer.SetMessager(action.InfoBar)
        args := flag.Args()
        b := LoadInput(args)
 
@@ -329,7 +331,6 @@ func main() {
        }
 
        action.InitTabs(b)
-       action.InitGlobals()
 
        err = config.RunPluginFn("init")
        if err != nil {
index 034e28e5686576d69366bc575b0a278d2d632285..99921dfae254203b21f393e7a5462589a2ac3e81 100644 (file)
@@ -252,8 +252,9 @@ func NewBufferFromFileAtLoc(path string, btype BufType, cursorLoc Loc) (*Buffer,
                buf = NewBuffer(file, util.FSize(file), filename, cursorLoc, btype)
        }
 
-       if readonly {
-               buf.SetOptionNative("readonly", true)
+       if readonly && prompt != nil {
+               prompt.Message("Warning: file is readonly - sudo will be attempted when saving")
+               // buf.SetOptionNative("readonly", true)
        }
 
        return buf, nil
index 31c963265792b62cf1a1475349c83e37aa7087f3..dfff37b5f0e2b16c3190b0cb7b3f4432e1220e2b 100644 (file)
@@ -82,3 +82,13 @@ func (b *Buffer) ClearMessages(owner string) {
 func (b *Buffer) ClearAllMessages() {
        b.Messages = make([]*Message, 0)
 }
+
+type Messager interface {
+       Message(msg ...interface{})
+}
+
+var prompt Messager
+
+func SetMessager(m Messager) {
+       prompt = m
+}