예제 #1
35
파일: view.go 프로젝트: GiantToast/ngrok
func New(ctl *ui.Controller, state ui.State) *TermView {
	// initialize terminal display
	termbox.Init()

	// make sure ngrok doesn't quit until we've cleaned up
	ctl.Wait.Add(1)

	w, _ := termbox.Size()

	v := &TermView{
		ctl:      ctl,
		updates:  ctl.Updates.Reg(),
		flush:    make(chan int),
		subviews: make([]ui.View, 0),
		state:    state,
		Logger:   log.NewPrefixLogger(),
		area:     NewArea(0, 0, w, 10),
	}

	v.Logger.AddLogPrefix("view")
	v.Logger.AddLogPrefix("term")

	switch p := state.GetProtocol().(type) {
	case *proto.Http:
		v.subviews = append(v.subviews, NewHttp(p, v.flush, ctl.Shutdown, 0, 10))
	default:
	}

	v.Render()

	go v.run()
	go v.input()

	return v
}
예제 #2
0
파일: panel.go 프로젝트: errnoh/termbox
// Returns buffered struct of the main screen.
// NOTE: Resize creates new buffer?
func MainScreen() *Buffered {
	width, height := termbox.Size()
	return &Buffered{
		Unbuffered: Unbuffered{r: image.Rect(0, 0, width, height)},
		buffer:     termbox.CellBuffer(),
	}
}
예제 #3
0
파일: session.go 프로젝트: rwcarlsen/editor
func (s *Session) Run() error {
	s.mode = &ModeEdit{}
	data, err := ioutil.ReadFile(s.File)
	if err != nil {
		return err
	}
	s.Buf = util.NewBuffer(data)
	s.W, s.H = termbox.Size()
	s.H--
	s.View.SetBuf(s.Buf)
	s.View.SetSize(s.W, s.H)
	s.View.SetTabwidth(s.Tabwidth)

	for {
		s.Draw()
		termbox.Flush()
		termbox.Clear(0, 0)

		ev := termbox.PollEvent()
		switch ev.Type {
		case termbox.EventKey:
			s.mode, err = s.mode.HandleKey(s, ev)
			if err != nil {
				return err
			}
		case termbox.EventResize:
			s.W, s.H = ev.Width, ev.Height-1
			s.View.SetSize(s.W, s.H)
		case termbox.EventMouse:
		case termbox.EventError:
			return ev.Err
		}
	}
}
예제 #4
0
func (c *Composer) moveTopWindow(ev Event) bool {
	if len(c.windows) > 0 {
		view := c.topWindow()
		if view != nil {
			x, y := view.Pos()
			w, h := view.Size()
			x1, y1 := x, y
			cx, cy := term.Size()
			if ev.Key == term.KeyArrowUp && y > 0 {
				y--
			} else if ev.Key == term.KeyArrowDown && y+h < cy {
				y++
			} else if ev.Key == term.KeyArrowLeft && x > 0 {
				x--
			} else if ev.Key == term.KeyArrowRight && x+w < cx {
				x++
			}

			if x1 != x || y1 != y {
				view.SetPos(x, y)
				event := Event{Type: EventMove, X: x, Y: y}
				c.sendEventToActiveWindow(event)
				RefreshScreen()
			}
		}
		return true
	}

	return false
}
예제 #5
0
func (w *Window) Repaint() error {

	w.Lock()
	err := termbox.Clear(w.Fg, w.Bg)
	width, height := termbox.Size()

	if err != nil {
		return err
	}

	for _, row := range w.Widgets[w.scrollPos:] {
		j := 0
		for _, c := range row.Text {

			termbox.SetCell(w.x, w.y, rune(c), row.Fg[j], row.Bg[j])
			j++

			if w.x += 1; w.x > width {
				break
			}
		}
		w.x = 0

		if w.y += 1; w.y > height {
			break
		}
	}
	w.y = 0
	w.x = 0

	w.Unlock()
	return nil
}
예제 #6
0
파일: main.go 프로젝트: henesy/NetRogue
/* A multiplayer rogue-like in the spirit of TOAG, but implemented in termbox-go */
func main() {

	//flag.Parse()
	/* start network handling and channels */
	max_dimensions := 80 * 24
	screen := make([]nr.Sprite, max_dimensions)
	world := loadWorld()

	/* initialize termbox interface */
	err := tb.Init()
	check(err)

	tb.SetInputMode(tb.InputAlt)
	w, h := tb.Size()

	tb.Clear(tb.ColorBlack, tb.ColorBlack)
	tb.Flush()
	go draw(w, h)

	for run := true; run == true; {
		switch ev := tb.PollEvent(); ev.Type {
		case tb.EventKey:
			//key := ev.Ch
			if ev.Key == tb.KeyCtrlQ {
				tb.Flush()
				run = false
			}
		default:
		}
	}
}
예제 #7
0
파일: panel.go 프로젝트: errnoh/termbox
func (panel *Unbuffered) At(x, y int) termbox.Cell {
	if !panel.contains(x, y) {
		return termbox.Cell{}
	}
	width, _ := termbox.Size()
	return termbox.CellBuffer()[(panel.r.Min.Y+y)*width+(panel.r.Min.X+x)]
}
예제 #8
0
파일: common.go 프로젝트: eurry/gotunnel2
func NewPrinter(lineWidth int) *Printer {
	ret := &Printer{
		lineWidth: lineWidth,
	}
	ret.w, ret.h = box.Size()
	return ret
}
예제 #9
0
파일: grin.go 프로젝트: nickaubert/grin
func draw_piece(well *Well, operation string, this_piece *Tetronimo) {

	well_depth := len(well.debris_map)

	term_col, term_row := tb.Size()
	vert_headroom := int((term_row-well_depth)/2) - 1

	well_bottom := len(well.debris_map) + vert_headroom
	well_left := ((term_col / 2) - len(well.debris_map[0]))

	for t_vert := range this_piece.shape {
		for t_horz := range this_piece.shape[t_vert] {
			if this_piece.shape[t_vert][t_horz] > 0 {
				color := tb.ColorDefault
				if operation == "draw" {
					color = set_color(this_piece.shape[t_vert][t_horz])
				}
				height := (well_bottom - this_piece.height + t_vert)
				longitude := (well_left + (this_piece.longitude * 2) + (t_horz * 2))
				tb.SetCell(longitude, height, 0, 0, color)
				tb.SetCell(longitude+1, height, 0, 0, color)
			}
		}
	}

}
예제 #10
0
파일: termbox.go 프로젝트: telyn/form
func (t *TermBox) Fill(cell *termbox.Cell) {
	w, h := termbox.Size()
	for y := 0; y < h; y++ {
		for x := 0; x < w; x++ {
			termbox.SetCell(x, y, cell.Ch, cell.Fg, cell.Bg)
		}
	}
}
예제 #11
0
func (w *Window) ScrollUp() {
	if _, height := termbox.Size(); len(w.Widgets) <= height {
		return
	}
	if w.scrollPos > 0 {
		w.scrollPos -= 1
	}
}
예제 #12
0
파일: termbox.go 프로젝트: telyn/form
func (t *TermBox) GetCell(x, y int) *termbox.Cell {
	w, h := termbox.Size()
	idx := y*w + x
	if idx > w*h {
		return nil
	}
	return &termbox.CellBuffer()[idx]
}
예제 #13
0
// Reset reinitializes canvas: set clipping rectangle to the whole
// terminal window, clears clip and color saved data, sets colors
// to default ones
func Reset() {
	canvas.width, canvas.height = term.Size()
	canvas.clipX, canvas.clipY = 0, 0
	canvas.clipW, canvas.clipH = canvas.width, canvas.height
	canvas.textColor = ColorWhite
	canvas.backColor = ColorBlack

	canvas.attrStack = make([]attr, 0)
	canvas.clipStack = make([]rect, 0)
}
예제 #14
0
func (w *Window) ScrollDown() {
	_, height := termbox.Size()
	if len(w.Widgets) <= height {
		return
	}
	rowLength := len(w.Widgets)
	if w.scrollPos < (rowLength - height) {
		w.scrollPos += 1
	}
}
예제 #15
0
파일: main.go 프로젝트: rdterner/tview
func main() {
	fname := os.Args[1]

	f, err := os.Open(fname)
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	img, _, err := image.Decode(f)
	if err != nil {
		log.Fatal(err)
	}

	err = termbox.Init()
	if err != nil {
		panic(err)
	}
	defer termbox.Close()

	if termbox.SetOutputMode(termbox.Output256) == termbox.Output256 {
		palette = upgrade(palette)
	}

	lw, lh := termbox.Size()
	draw(img)
loop:
	for {
		ev := termbox.PollEvent()
		switch ev.Type {
		case termbox.EventKey:
			if ev.Key == termbox.KeyEsc {
				break loop
			}
		case termbox.EventResize:
			termbox.Flush()
			if w, h := termbox.Size(); lw != w || lh != h {
				lw, lh = w, h
				draw(img)
			}
		}
	}
}
예제 #16
0
파일: termbox.go 프로젝트: discoloda/gorl
func (tb termbox) Read(x, y int) (ch rune, fg, bg Color) {
	cells := T.CellBuffer()
	w, h := T.Size()
	index := x + (y * w)
	if index < 0 || index >= w*h {
		return ' ', ColorBlack, ColorBlack
	}
	cell := cells[index]
	return cell.Ch, termbox_to_color(cell.Fg), termbox_to_color(cell.Bg)
}
예제 #17
0
파일: render.go 프로젝트: 4honor/termui
// Init initializes termui library. This function should be called before any others.
// After initialization, the library must be finalized by 'Close' function.
func Init() error {
	Body = NewGrid()
	Body.X = 0
	Body.Y = 0
	Body.BgColor = theme.BodyBg
	defer (func() {
		w, _ := tm.Size()
		Body.Width = w
	})()
	return tm.Init()
}
// TODO make new widget traffic light
// Waiting for canvas from termui
func initWidgets() (*ui.List, *ui.Par, *ui.Par, *ui.Par, *ui.Par) {
	ui.UseTheme("Jenkins Term UI")

	title := "q to quit - " + *jenkinsUrl
	if *filter != "" {
		title += " filter on " + *filter
	}
	p := ui.NewPar(title)
	_, h := tm.Size()
	p.Height = 3
	p.TextFgColor = ui.ColorWhite
	p.Border.Label = "Go Jenkins Dashboard"
	p.Border.FgColor = ui.ColorCyan

	info := ui.NewPar("")
	info.Height = 3
	info.Y = h - 3
	info.TextFgColor = ui.ColorWhite
	info.Border.FgColor = ui.ColorWhite

	ls := ui.NewList()
	ls.ItemFgColor = ui.ColorYellow
	ls.Border.Label = "Jobs"
	ls.Y = 3
	ls.Height = h - 6

	width, height := 4, 5
	redbox, yellowbox, greenbox := ui.NewPar(""), ui.NewPar(""), ui.NewPar("")
	redbox.HasBorder, yellowbox.HasBorder, greenbox.HasBorder = false, false, false
	redbox.Height, yellowbox.Height, greenbox.Height = height, height, height
	redbox.Width, yellowbox.Width, greenbox.Width = width, width, width
	redbox.BgColor = ui.ColorRed
	yellowbox.BgColor = ui.ColorYellow
	greenbox.BgColor = ui.ColorGreen

	ui.Body.AddRows(
		ui.NewRow(
			ui.NewCol(12, 0, p),
		),
		ui.NewRow(
			ui.NewCol(10, 0, ls),
			ui.NewCol(2, 0, redbox, yellowbox, greenbox),
		),
		ui.NewRow(
			ui.NewCol(12, 0, info),
		),
	)
	ui.Body.Align()
	ui.Render(ui.Body)
	return ls, info, redbox, yellowbox, greenbox
}
예제 #19
0
func (scr *Screen) Blit(x, y int) {
	termWidth, _ := tb.Size()
	startOffset := (y * termWidth) + x
	cells := tb.CellBuffer()

	for i := 0; i < scr.height; i++ {
		tbRangeStart := startOffset + (i * termWidth)
		tbRangeEnd := tbRangeStart + scr.width
		scrRangeStart := i * scr.width
		scrRangeEnd := scrRangeStart + scr.width

		copy(cells[tbRangeStart:tbRangeEnd], scr.buffer[scrRangeStart:scrRangeEnd])
	}
}
예제 #20
0
파일: draw.go 프로젝트: kybin/tor
func printStatus(status string) {
	termw, termh := term.Size()
	statusLine := termh - 1
	// clear
	for i := 0; i < termw; i++ {
		SetCell(statusLine, i, ' ', term.ColorBlack, term.ColorWhite)
	}
	// draw
	o := 0
	for _, r := range status {
		SetCell(statusLine, o, r, term.ColorBlack, term.ColorWhite)
		o += runewidth.RuneWidth(r)
	}
}
예제 #21
0
파일: draw.go 프로젝트: kybin/tor
func printErrorStatus(err string) {
	termw, termh := term.Size()
	statusLine := termh - 1
	// clear
	for i := 0; i < termw; i++ {
		SetCell(statusLine, i, ' ', term.ColorBlack, term.ColorRed)
	}
	// draw
	o := 0
	for _, r := range err {
		SetCell(statusLine, o, r, term.ColorBlack, term.ColorRed)
		o += runewidth.RuneWidth(r)
	}
}
예제 #22
0
func calibratePoint(et gaze.EyeTracker, x, y float64) {
	termbox.Clear(0, 0)
	sizeX, sizeY := termbox.Size()
	dx, dy := int(float64(sizeX)*x), int(float64(sizeY)*y)
	termbox.CellBuffer()[sizeX*dy+dx] = termbox.Cell{'#', marker, termbox.ColorDefault}
	termbox.Flush()
	//log.Printf("Termbox Size: (%d, %d)", sizeX, sizeY)
	log.Printf("Calibrating (%.3f, %.3f)", x, y)
	done := make(chan struct{})
	time.Sleep(1 * time.Second) //Minimum time. Gives user time to react.
	et.AddPointToCalibration(gaze.NewPoint2D(x, y), func(err error) {
		close(done) //Synchronizing async call.
	})
	<-done
}
예제 #23
0
// selects the next row
func (w *Window) NextRow() {

	_, maxy := termbox.Size()
	if w.scrollable == true {
		if w.selected+w.scrollPos == len(w.Rows)-1 {
			return // bottom of the visible output
		} else if w.selected == maxy-1 {
			w.ScrollDown()
		} else {
			w.selected += 1
		}
	} else {
		w.selected += 1
	}
}
예제 #24
0
func drawMessage(s string) {

	ns := addNewlines(s, 80)
	w, h := tb.Size()
	wc := w / 2
	hc := h / 2

	rectW := 82
	rectH := strings.Count(ns, "\n") + 3

	rectX := wc - rectW/2
	rectY := hc - rectH/2

	drawRectangle(rectX, rectY, rectW, rectH)
	drawString(rectX+2, rectY+1, ns)
}
예제 #25
0
파일: ui.go 프로젝트: CasualSuperman/dfc
func main() {
	if err := tb.Init(); err != nil {
		panic(err)
	} else {
		defer tb.Close()
		tb.HideCursor()
	}

	x, y := tb.Size()
	drawBoundingBox(0, x-1, 0, y-1)
	drawTypedBoundingBox(tb.ColorBlack, tb.ColorWhite)(x/3, 2*x/3, y/3, 2*y/3)
	fillInBox(x/3+1, 2*x/3-1, y/3+1, 2*y/3-1, tb.ColorBlack, tb.ColorWhite)

	tb.Flush()
	time.Sleep(3 * time.Second)
}
예제 #26
0
파일: traceGaze.go 프로젝트: BreamIO/gobii
func drawPoint(point gaze.Point2D, attributes termbox.Attribute) {
	sizeX, sizeY := termbox.Size()
	x, y := int(float64(sizeX)*point.X()), int(float64(sizeY)*point.Y())
	switch {
	case x < 0:
		x = 0
	case x >= sizeX:
		x = sizeX - 1
	}

	switch {
	case y < 0:
		y = 0
	case y >= sizeY:
		y = sizeY - 1
	}
	termbox.CellBuffer()[sizeX*y+x] = termbox.Cell{'O', attributes, termbox.ColorWhite}
}
예제 #27
0
파일: grin.go 프로젝트: nickaubert/grin
func draw_debris(well *Well) {

	term_col, term_row := tb.Size()
	well_depth := len(well.debris_map)
	vert_headroom := int((term_row-well_depth)/2) - 1

	for row := range well.debris_map {
		for col := range well.debris_map[row] {
			row_loc := vert_headroom + len(well.debris_map) - row
			col_loc := ((term_col / 2) - len(well.debris_map[0])) + (col * 2)

			color := set_color(well.debris_map[row][col])
			tb.SetCell(col_loc, row_loc, 0, 0, color)
			tb.SetCell(col_loc+1, row_loc, 0, 0, color)
		}
	}

}
예제 #28
0
func render(s state) {

	tb.Clear(tb.ColorDefault, tb.ColorDefault)

	w, h := tb.Size()

	drawString(1, 1, fmt.Sprint("dust: ", s.dust))

	if s.howManyBuilt(searcher.name) > 0 {
		drawString(1, 2, fmt.Sprint("data disks: ", s.disks))
	}

	if s.highestDust >= collector.baseCost {

		drawString(1, 3,
			fmt.Sprint(
				"[c]ollectors(", collector.currentCost(s), "): ",
				s.howManyBuilt(collector.name)))
	}

	if s.highestDust >= searcher.baseCost {

		drawString(1, 4, fmt.Sprint(
			"[s]earcher(", searcher.currentCost(s), "):  ",
			s.howManyBuilt(searcher.name)))
	}

	helpMessage := "hit [space] to take a turn, [h] for help, [q] or [Esc] to quit"
	nextTurnMessage := fmt.Sprint(
		"next turn:", getDescription(s.nextTurnEvent))

	drawString((w/2)-(len(helpMessage)/2), h-1, helpMessage)
	drawString((w/2)-(len(nextTurnMessage)/2), h-2, nextTurnMessage)

	if len(s.message) > 0 {
		drawMessage(s.message)
	}

	err := tb.Flush()

	if err != nil {
		panic(err)
	}
}
예제 #29
0
파일: view.go 프로젝트: 0x19/ngrok
func NewTermView(ctl mvc.Controller) *TermView {
	// initialize terminal display
	termbox.Init()

	w, _ := termbox.Size()

	v := &TermView{
		ctl:      ctl,
		updates:  ctl.Updates().Reg(),
		redraw:   util.NewBroadcast(),
		flush:    make(chan int),
		shutdown: make(chan int),
		Logger:   log.NewPrefixLogger("view", "term"),
		area:     NewArea(0, 0, w, 10),
	}

	ctl.Go(v.run)
	ctl.Go(v.input)

	return v
}
예제 #30
0
파일: game.go 프로젝트: igungor/bingo
func (g *game) draw() {
	// update board and racks
	g.board.qb = g.pos().Board()
	g.rack1.player = g.playerById(0)
	g.rack2.player = g.playerById(1)
	g.w, g.h = termbox.Size()

	termbox.Clear(fgcolor, bgcolor)
	defer termbox.Flush()

	// board
	g.board.x = (g.w - g.board.w*2 + 2 + 1) / 2
	g.board.y = (g.h - g.board.h - g.rack1.h - g.editbox.h - 2) / 2
	g.board.draw()

	// racks
	g.rack1.x = g.board.x
	g.rack1.y = g.board.y + g.board.h + 2
	g.rack1.draw()
	g.rack2.x = g.board.x + g.rack1.w + 2
	g.rack2.y = g.board.y + g.board.h + 2
	g.rack2.draw()
	if g.player().Id() == 0 {
		g.rack1.setActive()
	} else {
		g.rack2.setActive()
	}

	// editbox
	g.editbox.x = g.board.x + g.editbox.w/2 + 1
	g.editbox.y = g.rack1.y - g.rack1.h + 4
	g.editbox.draw()

	// legend
	if g.showLegend {
		g.legend.x = g.board.x + g.board.w*2 - 8
		g.legend.y = g.board.y + g.board.h
		g.legend.draw()
	}
}