Esempio n. 1
0
File: main.go Progetto: telyn/form
func draw() bool {
	termbox.Clear(termbox.ColorDefault, termbox.ColorDefault)

	dots := NewCellsBox([]termbox.Cell{dot, dot, dot, dot, dot,
		dot, dot, dot, dot, dot,
		dot, dot, dot, dot, dot,
		dot, dot, dot, dot, dot,
	}, 5)

	greenPlus := NewCellsBox([]termbox.Cell{greenPlus, greenPlus, greenPlus, greenPlus}, 2)

	if err := greenPlus.DrawInto(dots, 1, 2); err != nil {
		termbox.Close()
		fmt.Fprintf(os.Stderr, "%v1\r\n", err)
		return false
	}
	if err := dots.DrawInto(&TermBox{}, 0, 0); err != nil {
		termbox.Close()
		fmt.Fprintf(os.Stderr, "%v2\r\n", err)
		return false
	}

	termbox.SetCell(0, 0, '+', termbox.ColorRed, termbox.ColorDefault)
	termbox.SetCell(1, 0, '+', termbox.ColorRed, termbox.ColorDefault)
	termbox.SetCell(7, 0, '+', termbox.ColorRed, termbox.ColorDefault)

	termbox.Flush()
	return true
}
Esempio n. 2
0
func (b *board) highlightPos(x, y int) {
	if !b.in(x, y) {
		return
	}

	b.curPosVert = !b.curPosVert

	fg := fgcolor | termbox.AttrBold
	bg := bgcolor | termbox.AttrBold

	defch := '·'
	var xch, ych rune
	if b.curPosVert {
		xch = defch
		ych = '⇣'
	} else {
		xch = '⇢'
		ych = defch
	}

	// draw position indicators
	for i := b.x; i < x; i += 2 {
		termbox.SetCell(i, y, xch, fg, bg)
	}
	for i := b.y; i <= y; i++ {
		if (x-b.x)%2 == 1 {
			termbox.SetCell(x-1, i, ych, fg, bg)
		} else {
			termbox.SetCell(x, i, ych, fg, bg)
		}
	}
	termbox.Flush()
}
Esempio n. 3
0
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)
			}
		}
	}

}
Esempio n. 4
0
func drawSections() {
	if term.dm.Curr == nil || len(term.dm.Curr.Sections) == 0 {
		return
	}

	st := term.ofs.trk
	en := st + len(term.dm.Curr.Sections) + 3

	drawBottomCorners(en)
	drawHLines(en)
	drawVLines(vLine{0, st, en}, vLine{79, st, en}, vLine{28, st, en})

	// pattern tempo
	if term.mode == tempoMode {
		msg := fmt.Sprintf("tracks, bpm = %v", term.input.String())
		tbPrintDef(2, st, msg)
		tbPrint(16+len(msg), st, tb.ColorBlack, tb.ColorYellow, " ")
	} else {
		msg := fmt.Sprintf("tracks, bpm = %v", term.dm.Curr.Tempo)
		tbPrintDef(2, st, msg)
	}

	// beat numbers
	for i := 0; i < 16; i++ {
		if term.beat == i {
			tbPrintf(i*3+30, st, tb.ColorBlue, tb.ColorBlack, "%2d", i+1)
		} else {
			tbPrintf(i*3+30, st, tb.ColorWhite, tb.ColorBlack, "%2d", i+1)
		}
	}

	// sequence sections
	for i, sec := range term.dm.Curr.Sections {
		tbPrintf(2, st+2+i, tb.ColorWhite, tb.ColorBlack, "%4d", sec.ID)
		if sec.Enabled {
			tbPrintf(8, st+2+i, tb.ColorGreen, tb.ColorBlack, "%18s", sec.Name)
		} else {
			tbPrintf(8, st+2+i, tb.ColorWhite, tb.ColorBlack, "%18s", sec.Name)
		}
		if term.cur.sec == 1 && term.cur.row == i {
			tbPrint(27, st+2+i, tb.ColorWhite, tb.ColorBlack, "*")
		}
		for j, beat := range sec.Beats {
			conb := term.cur.sec == 1 && term.cur.row == i && term.cur.col == j
			if beat && conb {
				tb.SetCell(j*3+31, st+2+i, 'x', tb.ColorMagenta, tb.ColorYellow)
			} else if beat && j == term.beat {
				tb.SetCell(j*3+31, st+2+i, 'x', tb.ColorBlue, tb.ColorBlack)
			} else if beat {
				setCellDefaultColor(j*3+31, st+2+i, 'x')
			} else if conb {
				tb.SetCell(j*3+31, st+2+i, ' ', tb.ColorDefault, tb.ColorGreen)
			}
		}
	}
}
Esempio n. 5
0
File: main.go Progetto: telyn/form
func draw() bool {
	termbox.Clear(termbox.ColorDefault, termbox.ColorDefault)

	termbox.SetCell(0, 0, 'H', 0, 0)
	termbox.SetCell(1, 0, 'e', 0, 0)
	termbox.SetCell(2, 0, 'y', 0, 0)
	textField.DrawInto(&box.TermBox{}, 4, 0)

	termbox.Flush()
	return true
}
Esempio n. 6
0
// Draws borders _outside_ the
func DrawBorder(p BorderedPanel) {
	r := p.Bounds()
	b := p.Border()

	var border []rune
	switch b.Ch {
	case 's', 'S':
		border = singleBorder
	case 'd', 'D':
		border = doubleBorder
	default:
		border = []rune{b.Ch, b.Ch, b.Ch, b.Ch, b.Ch, b.Ch}
	}

	termbox.SetCell(r.Min.X-1, r.Min.Y-1, borderClash(r.Min.X-1, r.Min.Y-1, border[4], 3), b.Fg, b.Bg)
	termbox.SetCell(r.Max.X, r.Min.Y-1, borderClash(r.Max.X, r.Min.Y-1, border[5], 6), b.Fg, b.Bg)
	termbox.SetCell(r.Min.X-1, r.Max.Y, borderClash(r.Min.X-1, r.Max.Y, border[3], 9), b.Fg, b.Bg)
	termbox.SetCell(r.Max.X, r.Max.Y, borderClash(r.Max.X, r.Max.Y, border[2], 12), b.Fg, b.Bg)

	for x := r.Min.X; x < r.Min.X+r.Dx(); x++ {
		termbox.SetCell(x, r.Min.Y-1, borderClash(x, r.Min.Y-1, border[0], 2), b.Fg, b.Bg)
		termbox.SetCell(x, r.Min.Y+r.Dy(), borderClash(x, r.Min.Y+r.Dy(), border[0], 8), b.Fg, b.Bg)
	}

	for y := r.Min.Y; y < r.Min.Y+r.Dy(); y++ {
		termbox.SetCell(r.Min.X-1, y, borderClash(r.Min.X-1, y, border[1], 1), b.Fg, b.Bg)
		termbox.SetCell(r.Min.X+r.Dx(), y, borderClash(r.Min.X+r.Dx(), y, border[1], 4), b.Fg, b.Bg)
	}
}
Esempio n. 7
0
func (m *Mainboard) Init(xStart int, yStart int, width int, height int) {
	m.xStart = xStart
	m.yStart = yStart
	m.width = width
	m.height = height

	var x int = xStart + 1
	var y int = yStart + 1

	// Draw Top
	tm.SetCell(xStart, yStart, '+', tm.ColorDefault, tm.ColorDefault)
	for x < xStart+width {
		tm.SetCell(x, yStart, '-', tm.ColorDefault, tm.ColorDefault)
		x++
	}
	tm.SetCell(x, yStart, '+', tm.ColorDefault, tm.ColorDefault)

	// Draw Sides
	for y < yStart+height {
		tm.SetCell(xStart, y, '|', tm.ColorDefault, tm.ColorDefault)
		tm.SetCell(xStart+width, y, '|', tm.ColorDefault, tm.ColorDefault)
		y++
	}

	// Draw Bottom
	x = xStart + 1
	tm.SetCell(xStart, y, '+', tm.ColorDefault, tm.ColorDefault)
	for x < xStart+width {
		tm.SetCell(x, y, '-', tm.ColorDefault, tm.ColorDefault)
		x++
	}
	tm.SetCell(x, y, '+', tm.ColorDefault, tm.ColorDefault)
}
Esempio n. 8
0
// drawRectWithAttr draws a rectangle with unicode borders at position (x,y) with area of
// w*h with the given foreground and background attributes. Attributes can be
// colors and/or styling.
func drawRectWithAttr(x, y, w, h int, fgattr, bgattr termbox.Attribute) {
	// top border
	termbox.SetCell(x-1, y-1, '┌', fgattr, bgattr)
	fill(x, y-1, w, 1, '─')
	termbox.SetCell(x+w, y-1, '┐', fgattr, bgattr)

	// body border
	fill(x-1, y, 1, h, '│')
	fill(x+w, y, 1, h, '│')

	// bottom border
	termbox.SetCell(x-1, y+h, '└', fgcolor, bgcolor)
	fill(x, y+h, w, 1, '─')
	termbox.SetCell(x+w, y+h, '┘', fgcolor, bgcolor)
}
Esempio n. 9
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
}
Esempio n. 10
0
func print_tb(x, y int, fg, bg tb.Attribute, msg string) {
	for _, c := range msg {
		tb.SetCell(x, y, c, fg, bg)
		x++
	}
	tb.Flush()
}
Esempio n. 11
0
File: ui.go Progetto: twocool/srvdir
func (a *area) Clear() {
	for i := 0; i < a.w; i++ {
		for j := 0; j < a.h; j++ {
			termbox.SetCell(a.x+i, a.y+j, ' ', a.fgColor, a.bgColor)
		}
	}
}
Esempio n. 12
0
func fillInBox(xStart, xMax, yStart, yMax int, fg, bg tb.Attribute) {
	for i := xStart; i <= xMax; i++ {
		for j := yStart; j <= yMax; j++ {
			tb.SetCell(i, j, ' ', fg, bg)
		}
	}
}
Esempio n. 13
0
func main() {
	err := tb.Init()
	if err != nil {
		panic(err)
	}
	defer tb.Close()

	tb.SetInputMode(tb.InputEsc)
	tb.Clear(tb.ColorCyan, tb.ColorBlue)
	tb.Flush()

loop:
	for i := 0; ; i++ {
		ev := tb.PollEvent()
		switch ev.Type {
		case tb.EventKey:
			if ev.Key == tb.KeyCtrlC {
				break loop
			}
			tb.SetCell(i, i, ev.Ch, tb.ColorGreen, tb.ColorBlack)
			tb.Flush()
		case tb.EventError:
			panic(ev.Err)
		}
	}
}
Esempio n. 14
0
// fill draws a rectangle at position (x,y) with area of w*h and fills the
// inside with r.
func fill(x, y, w, h int, r rune) {
	for ly := 0; ly < h; ly++ {
		for lx := 0; lx < w; lx++ {
			termbox.SetCell(x+lx, y+ly, r, fgcolor, bgcolor)
		}
	}
}
Esempio n. 15
0
func tbprint(origin coord, msg string, fg, bg termbox.Attribute) coord {
	for _, r := range msg {
		termbox.SetCell(origin.x, origin.y, r, fg, bg)
		origin = origin.right(1)
	}
	return origin
}
Esempio n. 16
0
func buildInnerField(f field, origin coord) {
	var symbol rune
	fg := termbox.ColorWhite
	bg := termbox.ColorBlack

	for y := 0; y < f.dimensions.y; y++ {
		for x := 0; x < f.dimensions.x; x++ {
			theoretical := coord{x, y}
			statusHere := f.statusAt(theoretical)

			switch statusHere {
			case unknown:
				symbol = ' '
			case empty:
				symbol = '~'
				fg = termbox.ColorCyan
			case miss:
				symbol = '~'
				fg = termbox.ColorGreen
			case hit:
				symbol = '▓'
				fg = termbox.ColorRed
			case occupied:
				symbol = '█'
			}

			actual := theoretical.viewPos(origin)
			termbox.SetCell(actual.x, actual.y, symbol, fg, bg)
		}
	}
}
Esempio n. 17
0
func clearArea(r image.Rectangle, bg Attribute) {
	for i := r.Min.X; i < r.Max.X; i++ {
		for j := r.Min.Y; j < r.Max.Y; j++ {
			tm.SetCell(i, j, ' ', tm.ColorDefault, toTmAttr(bg))
		}
	}
}
Esempio n. 18
0
func print_tb(x, y int, msg string, fg, bg termbox.Attribute) {
	for _, c := range []rune(msg) {
		termbox.SetCell(x, y, c, fg, bg)
		x += runewidth.RuneWidth(c)
	}
	termbox.Flush()
}
Esempio n. 19
0
func termboxLogPrint(msg string) {
	x := 0
	y := 20
	for _, c := range msg {
		termbox.SetCell(x, y, c, termbox.ColorWhite, termbox.ColorBlack)
		x++
	}
}
Esempio n. 20
0
func Draw(s Surface, xorigin, yorigin int) {
	w, h := s.Size()
	for y := 0; y < h; y++ {
		for x := 0; x < w; x++ {
			termbox.SetCell(xorigin+x, yorigin+y, s.Rune(x, y), 0, 0)
		}
	}
}
Esempio n. 21
0
// PutChar sets value for the Canvas cell: rune and its colors. Returns result of
// operation: e.g, if the symbol position is outside Canvas the operation fails
// and the function returns false
func PutChar(x, y int, r rune) bool {
	if InClipRect(x, y) {
		term.SetCell(x, y, r, canvas.textColor, canvas.backColor)
		return true
	}

	return false
}
Esempio n. 22
0
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)
		}
	}
}
Esempio n. 23
0
func debug_tb(x, y int, fg, bg tb.Attribute, msg string) {
	for _, c := range msg {
		tb.SetCell(x, y, c, fg, bg)
		x++
	}
	tb.Flush()
	_ = tb.PollEvent().Ch
}
Esempio n. 24
0
func drawRectangle(x, y, w, h int) {

	for i := x; i < w+x; i++ {
		for j := y; j < h+y; j++ {

			tb.SetCell(i, j, ' ', tb.ColorBlack, tb.ColorWhite)
		}
	}
}
Esempio n. 25
0
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)
		}
	}

}
Esempio n. 26
0
func (m *ModeSearch) HandleKey(s *Session, ev termbox.Event) (Mode, error) {
	if m.s == nil {
		m.s = s
		m.b = util.NewBuffer([]byte{})
		m.view = &view.Wrap{}
		m.view.SetBuf(m.b)
		m.view.SetSize(s.W-1, 1)
		m.view.SetTabwidth(1)
	}

	var err error
	if ev.Ch != 0 {
		m.b.Insert(m.pos, ev.Ch)
		m.pos++
	}
	switch ev.Key {
	case termbox.KeyEnter:
		s.Search, err = regexp.Compile(string(m.b.Bytes()))
		if err != nil {
			msg := err.Error()
			for i, ch := range msg {
				termbox.SetCell(i, s.H, ch, 0, 0)
			}
			return &ModeEdit{}, nil
		}
		s.UpdSearch()
		s.NextMatch()
		return &ModeEdit{}, nil
	case termbox.KeySpace:
		m.b.Insert(m.pos, ' ')
		m.pos++
	case termbox.KeyBackspace, termbox.KeyBackspace2:
		m.b.Delete(m.pos, -1)
		m.pos--
	case termbox.KeyEsc:
		return &ModeEdit{}, nil
	}

	surf := m.view.Render()
	termbox.SetCell(0, s.H, '/', 0, 0)
	view.Draw(surf, 1, s.H)
	return m, nil
}
Esempio n. 27
0
// Render renders all Bufferer in the given order from left to right,
// right could overlap on left ones.
func Render(rs ...Bufferer) {
	tm.Clear(tm.ColorDefault, toTmAttr(theme.BodyBg))
	for _, r := range rs {
		buf := r.Buffer()
		for _, v := range buf {
			tm.SetCell(v.X, v.Y, v.Ch, toTmAttr(v.Fg), toTmAttr(v.Bg))
		}
	}
	tm.Flush()
}
Esempio n. 28
0
func buildLabels(f field, origin coord) {
	var labelOrigin coord

	// column headers
	labelOrigin.x = origin.x
	labelOrigin.y = origin.y - 1
	for i, symbol := range f.cols() {
		theoretical := coord{i, 0}
		actual := theoretical.viewPos(labelOrigin)
		termbox.SetCell(actual.x, actual.y, symbol, termbox.ColorMagenta, termbox.ColorBlack)
	}

	// row headers
	labelOrigin.x = origin.x - 2
	labelOrigin.y = origin.y
	for i, symbol := range f.rows() {
		theoretical := coord{0, i}
		actual := theoretical.viewPos(labelOrigin)
		termbox.SetCell(actual.x, actual.y, symbol, termbox.ColorMagenta, termbox.ColorBlack)
	}
}
Esempio n. 29
0
func printBoard(board TheirBoard, xStart, yStart int) {

	print_tb(xStart-1, 9, "/ - - - - - - - - - -\\", termbox.ColorBlack, termbox.ColorWhite)

	// X then Y
	// y := yStart
	for y := 0; y < 10; y++ {
		for x := 0; x < 10; x++ {
			termbox.SetCell(xStart-1, yStart+y, '|', termbox.ColorBlack, termbox.ColorWhite)

			switch board[x][y] {
			case 1:
				termbox.SetCell(xStart+(x*2), yStart+y, 'X', termbox.ColorRed, termbox.ColorBlack)
			case 2:
				termbox.SetCell(xStart+(x*2), yStart+y, ' ', 8, termbox.ColorBlack)

			default:
				termbox.SetCell(xStart+(x*2), yStart+y, '~', termbox.ColorGreen, termbox.ColorCyan)
				termbox.SetCell(xStart+(x*2)-1, yStart+y, ' ', termbox.ColorGreen, termbox.ColorCyan)
			}
		}
		termbox.SetCell(xStart+(10*2), yStart+y, '|', termbox.ColorBlack, termbox.ColorWhite)
	}
	termbox.Flush()

	print_tb(xStart-1, yStart+10, "\\ - - - - - - - - - -/", termbox.ColorBlack, termbox.ColorWhite)
}
Esempio n. 30
0
func draw(img image.Image) {
	w, h := termbox.Size()
	iw, ih := img.Bounds().Max.X, img.Bounds().Max.Y
	sw, sh := fit(w, h, iw*2, ih)
	termbox.Clear(termbox.ColorDefault, termbox.ColorDefault)
	for y := 0; y < h; y++ {
		for x := 0; x < w; x++ {
			if x >= sw || y >= sh {
				termbox.SetCell(x, y, ' ', termbox.ColorDefault, termbox.ColorDefault)
				continue
			}
			xi := x * img.Bounds().Max.X / sw
			yi := y * img.Bounds().Max.Y / sh
			a := palette.Convert(img.At(xi, yi))
			if at, ok := a.(attrColor); ok {
				termbox.SetCell(x, y, ' ', termbox.ColorDefault,
					termbox.Attribute(at))
			}
		}
	}
	termbox.Flush()
}