예제 #1
0
파일: xmlview.go 프로젝트: Ebiroll/openvg
// loop through slides with a pause
func loop(filename string, w, h, slidenum int, n time.Duration) {
	openvg.SaveTerm()
	defer openvg.RestoreTerm()
	var d deck.Deck
	var err error
	d, err = deck.Read(filename, w, h)
	if err != nil {
		fmt.Fprintf(os.Stderr, "%v\n", err)
		return
	}
	openvg.RawTerm()
	r := bufio.NewReader(os.Stdin)
	imap := make(map[string]image.Image)
	loadimage(d, imap)
	var start int
	var sd time.Duration
	for pass := 0; ; pass++ {
		if pass == 0 {
			start = slidenum
		} else {
			start = 0
		}
		for i := start; i < len(d.Slide); i++ {
			if readcmd(r) == 'q' {
				return
			}
			showslide(d, imap, i)
			pd, err := time.ParseDuration(d.Slide[i].Duration)
			if err != nil {
				sd = n
			} else {
				sd = pd
			}
			time.Sleep(sd)
		}
	}
}
예제 #2
0
파일: xmlview.go 프로젝트: Ebiroll/openvg
// interact controls the display of the deck
func interact(filename, searchterm string, w, h, slidenum int, gp float64) {
	openvg.SaveTerm()
	defer openvg.RestoreTerm()
	var d deck.Deck
	var err error
	d, err = deck.Read(filename, w, h)
	if err != nil {
		fmt.Fprintf(os.Stderr, "%v\n", err)
		return
	}
	openvg.RawTerm()
	r := bufio.NewReader(os.Stdin)
	lastslide := len(d.Slide) - 1
	if slidenum > lastslide {
		slidenum = lastslide
	}
	if slidenum < 0 {
		slidenum = 0
	}
	if len(searchterm) > 0 {
		sr := deck.Search(d, searchterm)
		if sr >= 0 {
			slidenum = sr
		}
	}
	n := slidenum
	xray := 1
	initial := 0
	imap := make(map[string]image.Image)
	// respond to keyboard commands, 'q' to exit
	for cmd := byte('0'); cmd != 'q'; cmd = readcmd(r) {
		switch cmd {
		// read/reload
		case 'r', 18: // r, Ctrl-R
			d, err = deck.Read(filename, w, h)
			if err != nil {
				fmt.Fprintf(os.Stderr, "%v\n", err)
				return
			}
			loadimage(d, imap)
			openvg.Background(0, 0, 0)
			xray = 1
			showslide(d, imap, n)

		// save slide
		case 's', 19: // s, Ctrl-S
			openvg.SaveEnd(fmt.Sprintf("%s-slide-%04d", filename, n))

		// first slide
		case '0', '1', 1, '^': // 0,1,Ctrl-A,^
			initial++
			if initial == 1 {
				loadimage(d, imap)
				n = slidenum
			} else {
				n = 0
			}
			showslide(d, imap, n)

		// last slide
		case '*', 5, '$': // *, Crtl-E, $
			n = lastslide
			showslide(d, imap, n)

		// next slide
		case '+', 'n', '\n', ' ', '\t', '=', 14: // +,n,newline,space,tab,equal,Crtl-N
			n++
			if n > lastslide {
				n = 0
			}
			showslide(d, imap, n)

		// previous slide
		case '-', 'p', 8, 16, 127: // -,p,Backspace,Ctrl-P,Del
			n--
			if n < 0 {
				n = lastslide
			}
			showslide(d, imap, n)

		// x-ray
		case 'x', 24: // x, Ctrl-X
			xray++
			showslide(d, imap, n)
			if xray%2 == 0 {
				showgrid(d, n, gp)
			}
		// Escape sequence from remotes
		case 27:
			remote, rerr := r.ReadString('~')
			if len(remote) > 2 && rerr == nil {
				switch remote[1] {
				case '3': // blank screen
					openvg.Start(d.Canvas.Width, d.Canvas.Height)
					openvg.FillColor("black")
					openvg.Rect(0, 0, openvg.VGfloat(d.Canvas.Width), openvg.VGfloat(d.Canvas.Height))
					openvg.End()

				case '5': // back
					n--
					if n < 0 {
						n = lastslide
					}
					showslide(d, imap, n)
				case '6': // forward
					n++
					if n > lastslide {
						n = 0
					}
					showslide(d, imap, n)
				}
			}
		// search
		case '/', 6: // slash, Ctrl-F
			openvg.RestoreTerm()
			searchterm, serr := r.ReadString('\n')
			openvg.RawTerm()
			if serr != nil {
				continue
			}
			if len(searchterm) > 2 {
				ns := deck.Search(d, searchterm[0:len(searchterm)-1])
				if ns >= 0 {
					showslide(d, imap, ns)
					n = ns
				}
			}
		}
	}
}