Merge branch 'messages'

This commit is contained in:
Zachary Yedidia 2016-03-23 10:28:26 -04:00
commit 338b086756
4 changed files with 47 additions and 2 deletions

View File

@ -60,8 +60,10 @@ func (b *Buffer) Save() error {
// SaveAs saves the buffer to a specified path (filename), creating the file if it does not exist
func (b *Buffer) SaveAs(filename string) error {
b.savedText = b.text
err := ioutil.WriteFile(filename, []byte(b.text), 0644)
if err == nil {
b.savedText = b.text
}
return err
}

39
src/message.go Normal file
View File

@ -0,0 +1,39 @@
package main
import (
"github.com/zyedidia/tcell"
)
var (
curMessage string
curStyle tcell.Style
)
func Message(msg string) {
curMessage = msg
curStyle = tcell.StyleDefault
if _, ok := colorscheme["message"]; ok {
curStyle = colorscheme["message"]
}
}
func Error(msg string) {
curMessage = msg
curStyle = tcell.StyleDefault.
Foreground(tcell.ColorBlack).
Background(tcell.ColorRed)
if _, ok := colorscheme["error-message"]; ok {
curStyle = colorscheme["error-message"]
}
}
func DisplayMessage(s tcell.Screen) {
_, h := s.Size()
runes := []rune(curMessage)
for x := 0; x < len(runes); x++ {
s.SetContent(x, h-1, runes[x], nil, curStyle)
}
}

View File

@ -84,18 +84,22 @@ func main() {
v := NewView(NewBuffer(string(input), filename), s)
Message("welcome to micro")
// Initially everything needs to be drawn
redraw := 2
for {
if redraw == 2 {
v.matches = Match(v.buf.rules, v.buf, v)
s.Clear()
DisplayMessage(s)
v.Display()
v.cursor.Display()
v.sl.Display()
s.Show()
} else if redraw == 1 {
v.cursor.Display()
DisplayMessage(s)
v.sl.Display()
s.Show()
}

View File

@ -191,7 +191,7 @@ func (v *View) HandleEvent(event tcell.Event) int {
case tcell.KeyCtrlS:
err := v.buf.Save()
if err != nil {
// Error!
Error(err.Error())
}
// Need to redraw the status line
ret = 1