mirror of
https://github.com/zyedidia/micro.git
synced 2024-10-28 05:21:40 +03:00
Merge branch 'messages'
This commit is contained in:
commit
338b086756
@ -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
39
src/message.go
Normal 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)
|
||||
}
|
||||
}
|
@ -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()
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user