Warn for readonly instead of setting option

Fixes #2106
This commit is contained in:
Zachary Yedidia
2021-05-19 14:58:00 -04:00
parent 6bc498e625
commit 0b0c99f1f5
3 changed files with 15 additions and 3 deletions

View 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 {

View 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

View 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
}