Skip to content

Commit

Permalink
checkpoint cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kristofer committed Nov 18, 2021
1 parent a77fa3f commit b2b97b2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 28 deletions.
9 changes: 5 additions & 4 deletions buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

/*
* Buffer is where all the opertions on the main rune array are implemented.
* Buffer is where all the operations on the main rune array are implemented.
* Because of the Gap, all the indexing around it should be done by these routines.
*/

Expand All @@ -19,7 +19,7 @@ type Buffer struct {

Next *Buffer
Mark int
OrigPoint int /* b_cpoint the original current point, used for mutliple window displaying */
OrigPoint int /* b_cpoint the original current point, used for multiple window displaying */
PageStart int /* start of page */
PageEnd int /* end of page */
Reframe bool /* force a reframe of the display */
Expand Down Expand Up @@ -67,15 +67,15 @@ func (bp *Buffer) getText() string {
// RuneAt finally reliable!!
func (bp *Buffer) RuneAt(pt int) (rune, error) {
if pt >= len(bp.data) {
return 0, errors.New("Beyond data buffer in RuneAt")
return 0, errors.New("beyond data buffer in RuneAt")
}
if pt < 0 {
return '\u0000', errors.New("negative buffer pointer in RuneAt")
}
if npt := bp.dataPointForBufferPoint(pt); npt < len(bp.data) {
return bp.data[npt], nil
}
return 0, errors.New("Ran over end of data buffer in RuneAt")
return 0, errors.New("ran over end of data buffer in RuneAt")
}

func (bp *Buffer) dataPointForBufferPoint(pt int) int {
Expand Down Expand Up @@ -227,6 +227,7 @@ func (bp *Buffer) LineStart(point int) int {
}
sp := point - 1
p, err := bp.RuneAt(sp)
checkErr(err)
if p == '\n' {
sp++
return sp
Expand Down
2 changes: 1 addition & 1 deletion command.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (e *Editor) copyCut(cut bool) {

func (e *Editor) paste() {
if len(e.PasteBuffer) <= 0 {
e.msg("PasterBuffer is empty. Nothing to paste.")
e.msg("PasteBuffer is empty. Nothing to paste.")
} else {
e.CurrentBuffer.Insert(e.PasteBuffer)
}
Expand Down
Binary file modified docs/foo
Binary file not shown.
Binary file added docs/foo1
Binary file not shown.
42 changes: 19 additions & 23 deletions editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func checkErr(e error) {
}

const (
version = "kg 1.0, Public Domain, November 2018, Kristofer Younger, No warranty."
version = "kg 1.1, Public Domain, November 2021, Kristofer Younger, No warranty."
nomark = -1
gapchunk = 16 //= 8096
idDefault = 1
Expand Down Expand Up @@ -107,23 +107,19 @@ func (e *Editor) StartEditor(argv []string, argc int) {
e.EventChan <- termbox.PollEvent()
}
}()
for {
select {
case ev := <-e.EventChan:
//// log.Printf("%#v\n", ev)
//// log.Println(">>\n ", time.Now().Unix(), "\n>>")

ok := e.handleEvent(&ev)
if !ok {
return
}
//e.ConsumeMoreEvents()
e.updateDisplay()
termbox.Flush()
// }

// Instead of using for {
// select {
// case ev := <-e.EventChan:

for ev := range e.EventChan {
ok := e.handleEvent(&ev)
if !ok {
return
}
e.updateDisplay()
termbox.Flush()
}
//return
}

// handleEvent
Expand Down Expand Up @@ -245,8 +241,8 @@ func (e *Editor) OnAltKey(ev *termbox.Event) bool {
func (e *Editor) msg(fm string, args ...interface{}) {
e.Msgline = fmt.Sprintf(fm, args...)
e.Msgflag = true
return
}

func (e *Editor) drawString(x, y int, fg, bg termbox.Attribute, msg string) {
for _, c := range msg {
termbox.SetCell(x, y, c, fg, bg)
Expand All @@ -270,12 +266,12 @@ func (e *Editor) Display(wp *Window, shouldDrawCursor bool) {
bp.PageStart = bp.SegStart(bp.LineStart(pt), pt, e.Cols)
}

if bp.Reframe == true || (pt > bp.PageEnd && pt != bp.PageEnd && !(pt >= bp.TextSize)) {
if bp.Reframe || (pt > bp.PageEnd && pt != bp.PageEnd && !(pt >= bp.TextSize)) {
bp.Reframe = false
i := 0
/* Find end of screen plus one. */
bp.PageStart = bp.DownDown(pt, e.Cols)
/* if we scoll to EOF we show 1 blank line at bottom of screen */
/* if we scroll to EOF we show 1 blank line at bottom of screen */
if bp.PageEnd <= bp.PageStart {
bp.PageStart = bp.PageEnd
i = wp.Rows - 1 // 1
Expand All @@ -301,7 +297,7 @@ func (e *Editor) Display(wp *Window, shouldDrawCursor bool) {
}
rch, err := bp.RuneAt(k)
if err != nil {
// log.Println("Error on RuneAt", err)
e.msg("Error on RuneAt", err)
}
if rch != '\r' {
if unicode.IsPrint(rch) || rch == '\t' || rch == '\n' {
Expand Down Expand Up @@ -555,7 +551,7 @@ func (e *Editor) ModifiedBuffers() bool {
var bp *Buffer

for bp = e.RootBuffer; bp != nil; bp = bp.Next {
if bp.modified == true {
if bp.modified {
return true
}
}
Expand All @@ -571,7 +567,7 @@ func (e *Editor) FindBuffer(fname string, cflag bool) *Buffer {
}
bp = bp.Next
}
if cflag != false {
if cflag {
bp = NewBuffer()
/* find the place in the list to insert this buffer */
if e.RootBuffer == nil {
Expand Down Expand Up @@ -613,7 +609,7 @@ func (e *Editor) splitWindow() {
e.CurrentWindow.Rows = ntru
nwp.TopPt = e.CurrentWindow.TopPt + ntru + 2
nwp.Rows = ntrl - 1

/* insert it in the list */
wp2 := e.CurrentWindow.Next
e.CurrentWindow.Next = nwp
Expand Down

0 comments on commit b2b97b2

Please sign in to comment.