提交 ba2356a8 编写于 作者: N nsf

Simply check for a new size every 'Clear' and 'Present' call.

Instead of relying on sigwinch. Two syscalls per one screen update won't hurt.
上级 4478c773
......@@ -38,8 +38,7 @@ func Init() error {
// we set two signal handlers, because input/output are not really
// connected, but they both need to be aware of window size changes
signal.Notify(sigwinch_input, syscall.SIGWINCH)
signal.Notify(sigwinch_draw, syscall.SIGWINCH)
signal.Notify(sigwinch, syscall.SIGWINCH)
err = tcgetattr(out.Fd(), &orig_tios)
if err != nil {
......@@ -106,11 +105,7 @@ func Present() {
lastx = coord_invalid
lasty = coord_invalid
select {
case <-sigwinch_draw:
update_size()
default:
}
update_size_maybe()
for y := 0; y < front_buffer.height; y++ {
line_offset := y * front_buffer.width
......@@ -200,7 +195,7 @@ func PollEvent() Event {
if extract_event(&event) {
return event
}
case <-sigwinch_input:
case <-sigwinch:
event.Type = EventResize
event.Width, event.Height = get_term_size(out.Fd())
return event
......@@ -217,11 +212,7 @@ func Size() (int, int) {
// Clears the internal back buffer.
func Clear() {
select {
case <-sigwinch_draw:
update_size()
default:
}
update_size_maybe()
back_buffer.clear()
}
......
......@@ -57,8 +57,7 @@ var (
background = ColorDefault
inbuf = make([]byte, 0, 64)
outbuf bytes.Buffer
sigwinch_input = make(chan os.Signal, 1)
sigwinch_draw = make(chan os.Signal, 1)
sigwinch = make(chan os.Signal, 1)
input_comm = make(chan []byte)
intbuf = make([]byte, 0, 16)
)
......@@ -166,12 +165,15 @@ func send_clear() {
lasty = coord_invalid
}
func update_size() {
termw, termh = get_term_size(out.Fd())
back_buffer.resize(termw, termh)
front_buffer.resize(termw, termh)
front_buffer.clear()
send_clear()
func update_size_maybe() {
w, h := get_term_size(out.Fd())
if w != termw || h != termh {
termw, termh = w, h
back_buffer.resize(termw, termh)
front_buffer.resize(termw, termh)
front_buffer.clear()
send_clear()
}
}
func tcsetattr(fd uintptr, termios *syscall_Termios) error {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册