1
0
Fork 0

Fix save as
timw4mail/gilo/pipeline/head This commit looks good Details

This commit is contained in:
Timothy Warren 2021-04-06 09:58:45 -04:00
parent 52aa174091
commit 4668ba5628
2 changed files with 12 additions and 11 deletions

View File

@ -67,11 +67,11 @@ func (d *Document) Save() int {
} }
if fileLen == size { if fileLen == size {
d.dirty = false
return size return size
} }
d.dirty = false
return 0 return 0
} }

View File

@ -59,9 +59,9 @@ func (e *editor) Open(filename string) {
} }
func (e *editor) Save() { func (e *editor) Save() {
//if e.document.Filename == "" { if e.document.Filename == "" {
// e.document.Filename = e.Prompt("Save as: %s") e.document.Filename = e.Prompt("Save as: %s")
//} }
size := e.document.Save() size := e.document.Save()
@ -88,24 +88,25 @@ func (e *editor) ProcessKeypress() bool {
func (e *editor) Prompt(prompt string) string { func (e *editor) Prompt(prompt string) string {
buf := gilo.NewBuffer() buf := gilo.NewBuffer()
// Show the prompt message
e.SetStatusMessage(prompt, "")
e.RefreshScreen()
for { for {
if buf.Len() > 0 { if buf.Len() > 0 {
e.SetStatusMessage(prompt, buf.ToString()) e.SetStatusMessage(prompt, buf.ToString())
} else { e.RefreshScreen()
e.SetStatusMessage(prompt)
} }
e.RefreshScreen()
ch, _ := terminal.ReadKey() ch, _ := terminal.ReadKey()
if ch == key.Enter { if ch == key.Enter {
if buf.Len() != 0 { if buf.Len() != 0 {
e.SetStatusMessage("") e.SetStatusMessage("")
return buf.ToString() return buf.ToString()
} else if !key.IsCtrl(ch) && key.IsAscii(ch) {
buf.AppendRune(ch)
} }
} else if key.IsAscii(ch) && !key.IsCtrl(ch) {
buf.AppendRune(ch)
} }
} }
} }