本文整理匯總了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
}
}
}
示例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(),
}
}
示例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
}
示例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
}
示例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
}
示例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:
}
}
}
示例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)]
}
示例8: NewPrinter
func NewPrinter(lineWidth int) *Printer {
ret := &Printer{
lineWidth: lineWidth,
}
ret.w, ret.h = box.Size()
return ret
}
示例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)
}
}
}
}
示例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)
}
}
}
示例11: ScrollUp
func (w *Window) ScrollUp() {
if _, height := termbox.Size(); len(w.Widgets) <= height {
return
}
if w.scrollPos > 0 {
w.scrollPos -= 1
}
}
示例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]
}
示例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)
}
示例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
}
}
示例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)
}
}
}
}