예제 #1
0
파일: dvi.go 프로젝트: dforsyth/dvi-go
func insertmode(d *Dvi) {
	startpos := &Position{d.b.pos.line, d.b.pos.off}
	for {
		draw(d)
		k := getCh(d)
		switch k {
		case 27:
			if p := prevChar(*d.b.pos); p.line == d.b.pos.line {
				d.b.pos = p
			}
			return
		case curses.KEY_LEFT, curses.KEY_RIGHT, curses.KEY_UP, curses.KEY_DOWN:
			curses.Beep()
		case ctrl('H'), 127, curses.KEY_BACKSPACE:
			// TODO: Don't let backspace travel past starting point of input session
			pp := prevChar2(*d.b.pos)
			if posEq(d.b.pos, startpos) {
				d.queueMsg("", 1, true)
				continue
			}
			d.b.remove(*prevChar2(*d.b.pos), *d.b.pos, false)
			d.b.pos = pp
		default:
			d.b.pos = d.b.add(*d.b.pos, []byte{byte(k)})
			d.b.dirty = true
		}
	}
}
예제 #2
0
파일: draw.go 프로젝트: dforsyth/dvi-go
func draw(d *Dvi) os.Error {

	f := d.b
	if f == nil {
		return nil
	}

	// this is some slow ass scroll action, ill figure out a way to avoid this later
	for l := f.first; l != f.disp && l != nil; l = l.next {
		if l == f.pos.line {
			for l != f.disp {
				f.disp = f.disp.prev
			}
			break
		}
	}
	for i, l := 0, f.disp; l != nil; i, l = i+screenlines(l), l.next {
		if l == f.pos.line {
			for i+screenlines(l) > *curses.Rows-1 {
				f.disp = f.disp.next
				i -= screenlines(l)
			}
			break
		}
	}

	cursory := 0
	cursorx := 0
	y := 0
	for l := f.disp; y < *curses.Rows-1 && l != nil; y, l = y+1, l.next {
		x := 0
		d.w.Move(y, 0)
		d.w.Clrtoeol()

		if l == f.pos.line {
			cursory = y
			for i, c := range l.text {
				if i >= f.pos.off {
					break
				}
				cursorx += charlen(c)
				if cursorx > *curses.Cols-1 {
					cursory++
					cursorx = 0
				}
			}
		}

		x = 0
		colors := int32(0)
		if f.pos.line == l {
			colors = curses.Color_pair(1)
		}
		for _, c := range l.text {
			if x > *curses.Cols-1 {
				y++
				x = 0
				d.w.Move(y, 0)
				d.w.Clrtoeol()
			}
			for i := x; i < x+charlen(c); i++ {
				d.w.Mvaddch(y, i, int32(c), colors)
			}
			x += charlen(c)
		}
		if colors != 0 {
			for ; x < *curses.Cols; x++ {
				d.w.Mvaddch(y, x, int32(' '), colors)
			}
		}
	}

	for ; y < *curses.Rows-1; y++ {
		d.w.Move(y, 0)
		d.w.Clrtoeol()
		d.w.Mvaddch(y, 0, int32('~'), 0)
	}

	d.currx = cursorx
	d.curry = cursory

	msg := ""
	mcolor := 3
	beep := false
	select {
	case fromq := <-d.statusq:
		msg = fromq.Display()
		mcolor = fromq.Color()
		beep = fromq.Beep()
	default:
		msg, mcolor, beep = d.statusDisplay()
	}
	d.w.Move(*curses.Rows-1, 0)
	d.w.Clrtoeol()

	for i := 0; i < *curses.Cols && i < len(msg); i++ {
		d.w.Mvaddch(*curses.Rows-1, i, int32(msg[i]), curses.Color_pair(mcolor))
	}
	// s.w.Mvwaddnstr(*curses.Rows-1, 0, msg, *curses.Cols)

	d.w.Move(cursory, cursorx)
	if beep {
		curses.Beep()
	}
	d.w.Refresh()

	return nil
}
예제 #3
0
파일: window.go 프로젝트: dforsyth/dvi-go
func Beep() {
	curses.Beep()
}