forked from rthornton128/goncurses
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pad.go
64 lines (56 loc) · 2.21 KB
/
pad.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// goncurses - ncurses library for Go.
// Copyright 2011 Rob Thornton. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package goncurses
// #include <curses.h>
// #include "goncurses.h"
import "C"
import "errors"
type Pad struct {
*Window
}
// NewPad creates a window which is not restricted by the terminal's
// dimensions (unlike a Window). Pads accept all functions which can be
// called on a window. It returns a pointer to a new Pad of h(eight) by
// w(idth).
func NewPad(h, w int) (*Pad, error) {
p := C.newpad(C.int(h), C.int(w))
if p == nil {
return nil, errors.New("Failed to create pad")
}
return &Pad{&Window{p}}, nil
}
// NoutRefresh indicates that a section of the screen should be redrawn but
// does not update the physical screen until Update() is called. See
// Pad.Refresh() for details on the arguments and Window.NoutRefresh for
// more details on the workings of this function
func (p *Pad) NoutRefresh(py, px, sy, sx, h, w int) error {
ok := C.pnoutrefresh(p.win, C.int(py), C.int(px), C.int(sy),
C.int(sx), C.int(h), C.int(w))
if ok != C.OK {
return errors.New("Failed to refresh pad")
}
return nil
}
// Refresh will calculate how to update the physical screen in the most
// efficient manor and update it. See Window.Refresh for more details.
// The coordinates py, px specify the location on the pad from which the
// characters we want to display are located. sy and sx specify the location
// on the screen where this data should be displayed. h and w are the height
// and width of the rectangle to be displayed. The coordinates and the size
// of the rectangle must be contained within both the Pad's and Window's
// respective areas
func (p *Pad) Refresh(py, px, sy, sx, h, w int) error {
if C.prefresh(p.win, C.int(py), C.int(px), C.int(sy), C.int(sx),
C.int(h), C.int(w)) != C.OK {
return errors.New("Failed to refresh pad")
}
return nil
}
// Sub creates a sub-pad h(eight) by w(idth) in size starting at the location
// y, x in the parent pad. Changes to a sub-pad will also change it's parent
func (p *Pad) Sub(y, x, h, w int) *Pad {
return &Pad{&Window{C.subpad(p.win, C.int(h), C.int(w), C.int(y),
C.int(x))}}
}