package main
import (
- "io/ioutil"
+ "os"
"strconv"
"strings"
"time"
func (v *View) Open(filename string) {
home, _ := homedir.Dir()
filename = strings.Replace(filename, "~", home, 1)
- file, err := ioutil.ReadFile(filename)
+ file, err := os.Open(filename)
+ defer file.Close()
var buf *Buffer
if err != nil {
messenger.Message(err.Error())
// File does not exist -- create an empty buffer with that name
- buf = NewBuffer([]byte{}, filename)
+ buf = NewBuffer(strings.NewReader(""), filename)
} else {
buf = NewBuffer(file, filename)
}
v.ScrollDown(1)
y = v.Height + v.Topline - 1
}
- if y >= v.Buf.NumLines {
- y = v.Buf.NumLines - 1
- }
if y < 0 {
y = 0
}
if data, err := FindRuntimeFile(RTHelp, helpPage).Data(); err != nil {
TermMessage("Unable to load help text", helpPage, "\n", err)
} else {
- helpBuffer := NewBuffer(data, helpPage+".md")
+ helpBuffer := NewBuffer(strings.NewReader(string(data)), helpPage+".md")
helpBuffer.name = "Help"
if v.Type == vtHelp {
v.drawCell(screenX-v.leftCol, screenY, ' ', nil, lineStyle)
}
}
+ strWidth += remainder
} else if runewidth.RuneWidth(ch) > 1 {
if screenX-v.x-v.leftCol >= v.lineNumOffset {
v.drawCell(screenX, screenY, ch, nil, lineStyle)
v.drawCell(screenX-v.leftCol, screenY, '<', nil, lineStyle)
}
}
+ strWidth += StringWidth(string(ch), tabSize)
} else {
if screenX-v.x-v.leftCol >= v.lineNumOffset {
v.drawCell(screenX-v.leftCol, screenY, ch, nil, lineStyle)
}
+ strWidth += StringWidth(string(ch), tabSize)
}
charNum = charNum.Move(1, v.Buf)
screenX++
colN++
- strWidth += StringWidth(string(ch), tabSize)
}
// Here we are at a newline