mirror of
https://github.com/felixangell/phi.git
synced 2024-08-16 19:20:21 +03:00
hacked in a visual indicator for unsaved file; closes #65
This commit is contained in:
parent
c03af2199f
commit
c383c81178
@ -55,6 +55,7 @@ type Buffer struct {
|
||||
filePath string
|
||||
languageInfo *cfg.LanguageSyntaxConfig
|
||||
ex, ey int
|
||||
modified bool
|
||||
}
|
||||
|
||||
func NewBuffer(conf *cfg.TomlConfig, buffOpts BufferConfig, parent *View, index int) *Buffer {
|
||||
@ -135,9 +136,16 @@ func (b *Buffer) OpenFile(filePath string) {
|
||||
for _, line := range lines {
|
||||
b.appendLine(line)
|
||||
}
|
||||
|
||||
// because appendLine sets modified to true
|
||||
// we should reset this to false since weve
|
||||
// only loaded a file.
|
||||
b.modified = false
|
||||
}
|
||||
|
||||
func (b *Buffer) setLine(idx int, val string) {
|
||||
b.modified = true
|
||||
|
||||
b.contents[idx] = rope.New(val)
|
||||
if b.curs.y == idx {
|
||||
b.moveToEndOfLine()
|
||||
@ -145,6 +153,8 @@ func (b *Buffer) setLine(idx int, val string) {
|
||||
}
|
||||
|
||||
func (b *Buffer) appendLine(val string) {
|
||||
b.modified = true
|
||||
|
||||
b.contents = append(b.contents, rope.New(val))
|
||||
// because we've added a new line
|
||||
// we have to set the x to the start
|
||||
@ -153,6 +163,8 @@ func (b *Buffer) appendLine(val string) {
|
||||
|
||||
// inserts a string, handling all of the newlines etc
|
||||
func (b *Buffer) insertString(idx int, val string) {
|
||||
b.modified = true
|
||||
|
||||
lines := strings.Split(val, "\n")
|
||||
|
||||
for _, l := range lines {
|
||||
@ -165,6 +177,8 @@ func (b *Buffer) insertString(idx int, val string) {
|
||||
}
|
||||
|
||||
func (b *Buffer) insertRune(r rune) {
|
||||
b.modified = true
|
||||
|
||||
log.Println("Inserting rune ", r, " into current line at ", b.curs.x, ":", b.curs.y)
|
||||
log.Println("Line before insert> ", b.contents[b.curs.y])
|
||||
|
||||
@ -224,6 +238,9 @@ var altAlternative = map[rune]rune{
|
||||
}
|
||||
|
||||
func (b *Buffer) deleteLine() {
|
||||
// HACK FIXME
|
||||
b.modified = true
|
||||
|
||||
if len(b.contents) > 1 {
|
||||
b.contents = remove(b.contents, b.curs.y)
|
||||
} else {
|
||||
@ -313,6 +330,9 @@ func (b *Buffer) processTextInput(r rune) bool {
|
||||
}
|
||||
}
|
||||
|
||||
// HACK FIXME
|
||||
b.modified = true
|
||||
|
||||
b.contents[b.curs.y] = b.contents[b.curs.y].Insert(b.curs.x, string(r))
|
||||
b.curs.move(1, 0)
|
||||
|
||||
@ -584,6 +604,9 @@ func (b *Buffer) processActionKey(key int) bool {
|
||||
// nicely indented!
|
||||
}
|
||||
|
||||
// HACK FIXME
|
||||
b.modified = true
|
||||
|
||||
initial_x := b.curs.x
|
||||
prevLineLen := b.contents[b.curs.y].Len()
|
||||
|
||||
@ -621,6 +644,9 @@ func (b *Buffer) processActionKey(key int) bool {
|
||||
b.contents[b.curs.y] = newRope
|
||||
|
||||
case sdl.K_BACKSPACE:
|
||||
// HACK FIXME
|
||||
b.modified = true
|
||||
|
||||
if SUPER_DOWN {
|
||||
b.deleteBeforeCursor()
|
||||
} else {
|
||||
@ -738,6 +764,9 @@ func (b *Buffer) processActionKey(key int) bool {
|
||||
}
|
||||
|
||||
case sdl.K_TAB:
|
||||
// HACK FIXME
|
||||
b.modified = true
|
||||
|
||||
if b.cfg.Editor.Tabs_Are_Spaces {
|
||||
// make an empty rune array of TAB_SIZE, cast to string
|
||||
// and insert it.
|
||||
|
@ -43,7 +43,12 @@ func (b *BufferPane) renderMetaPanel(ctx *strife.Renderer) {
|
||||
}
|
||||
|
||||
{
|
||||
infoLine := fmt.Sprintf("Line %d, Column %d", b.Buff.curs.y, b.Buff.curs.x)
|
||||
modified := ' '
|
||||
if b.Buff.modified {
|
||||
modified = '*'
|
||||
}
|
||||
|
||||
infoLine := fmt.Sprintf("%s%c Line %d, Column %d", b.Buff.filePath, modified, b.Buff.curs.y, b.Buff.curs.x)
|
||||
ctx.SetColor(strife.HexRGB(conf.Suggestion.Foreground))
|
||||
_, strHeight := ctx.String(infoLine, b.x+pad, mpY+(pad/2)+1)
|
||||
metaPanelHeight = strHeight + pad
|
||||
|
@ -64,10 +64,18 @@ func Save(v *View, commands []string) bool {
|
||||
// - lots of checks to do here: does the file exist/not exist
|
||||
// handle the errors... etc.
|
||||
|
||||
// ALWAYS use atomic save possibly?
|
||||
// start writing the file on a gothread
|
||||
// and then move the file overwriting when the
|
||||
// file has been written?
|
||||
|
||||
err := ioutil.WriteFile(b.filePath, buffer.Bytes(), 0775)
|
||||
if err != nil {
|
||||
log.Println(err.Error())
|
||||
}
|
||||
log.Println("Wrote file '" + b.filePath + "' to disk")
|
||||
|
||||
b.modified = false
|
||||
|
||||
return false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user