當前位置: 首頁>>代碼示例>>Golang>>正文


Golang termbox-go.Size函數代碼示例

本文整理匯總了Golang中github.com/nsf/termbox-go.Size函數的典型用法代碼示例。如果您正苦於以下問題:Golang Size函數的具體用法?Golang Size怎麽用?Golang Size使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Size函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Run

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
		}
	}
}
開發者ID:rwcarlsen,項目名稱:editor,代碼行數:34,代碼來源:session.go

示例2: MainScreen

// 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(),
	}
}
開發者ID:errnoh,項目名稱:termbox,代碼行數:9,代碼來源:panel.go

示例3: Repaint

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
}
開發者ID:anoopengineer,項目名稱:tldr,代碼行數:33,代碼來源:termboxwindow.go

示例4: moveTopWindow

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
}
開發者ID:VladimirMarkelov,項目名稱:clui,代碼行數:30,代碼來源:composer.go

示例5: New

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
}
開發者ID:GiantToast,項目名稱:ngrok,代碼行數:35,代碼來源:view.go

示例6: main

/* 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:
		}
	}
}
開發者ID:henesy,項目名稱:NetRogue,代碼行數:32,代碼來源:main.go

示例7: At

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)]
}
開發者ID:errnoh,項目名稱:termbox,代碼行數:7,代碼來源:panel.go

示例8: NewPrinter

func NewPrinter(lineWidth int) *Printer {
	ret := &Printer{
		lineWidth: lineWidth,
	}
	ret.w, ret.h = box.Size()
	return ret
}
開發者ID:eurry,項目名稱:gotunnel2,代碼行數:7,代碼來源:common.go

示例9: draw_piece

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)
			}
		}
	}

}
開發者ID:nickaubert,項目名稱:grin,代碼行數:26,代碼來源:grin.go

示例10: Fill

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)
		}
	}
}
開發者ID:telyn,項目名稱:form,代碼行數:8,代碼來源:termbox.go

示例11: ScrollUp

func (w *Window) ScrollUp() {
	if _, height := termbox.Size(); len(w.Widgets) <= height {
		return
	}
	if w.scrollPos > 0 {
		w.scrollPos -= 1
	}
}
開發者ID:anoopengineer,項目名稱:tldr,代碼行數:8,代碼來源:termboxwindow.go

示例12: GetCell

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]
}
開發者ID:telyn,項目名稱:form,代碼行數:8,代碼來源:termbox.go

示例13: Reset

// 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)
}
開發者ID:VladimirMarkelov,項目名稱:clui,代碼行數:13,代碼來源:canvas.go

示例14: ScrollDown

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
	}
}
開發者ID:anoopengineer,項目名稱:tldr,代碼行數:10,代碼來源:termboxwindow.go

示例15: main

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)
			}
		}
	}
}
開發者ID:rdterner,項目名稱:tview,代碼行數:43,代碼來源:main.go


注:本文中的github.com/nsf/termbox-go.Size函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。