Ejemplo n.º 1
0
func loop(x, y int) {
	quit := false

	for {
		curses.Stdwin.Addstr(0, 0, "Hello,\nworld!", 0)
		curses.Stdwin.Addstr(3, 0, "use the cursor keys to move around", 0)
		curses.Stdwin.Addstr(4, 0, "press the 'q' key to quit", 0)
		inp := curses.Stdwin.Getch()
		quit = false

		switch inp {
		case 'q':
			quit = true
		case curses.KEY_LEFT:
			x = x - 1
		case curses.KEY_RIGHT:
			x = x + 1
		case curses.KEY_UP:
			y = y - 1
		case curses.KEY_DOWN:
			y = y + 1
		}

		if quit {
			break
		}

		curses.Stdwin.Clear()
		curses.Stdwin.Mvaddch(y, x, '@', curses.Color_pair(1))
		curses.Stdwin.Refresh()
	}
}
Ejemplo n.º 2
0
func main() {

	startGoCurses()
	defer stopGoCurses()

	curses.Init_pair(1, curses.COLOR_YELLOW, curses.COLOR_GREEN)

	smallwin, _ := curses.Stdwin.Derwin(1, 10, 10, 10)
	smallwin.Attron(curses.Color_pair(1))
	smallwin.Attron(curses.A_BOLD)

	smallwin.Addstr(0, 0, "Hello here", 0)
	smallwin.Getch()

	curses.Stdwin.Clear()
	curses.Stdwin.Refresh()

	smallwin.Resize(1, 5)
	smallwin.Mvwin(20, 20)
	smallwin.Addstr(0, 0, "There", 0)
	smallwin.Getch()

}
Ejemplo n.º 3
0
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
}