Merge pull request #29 from Matt3o12/hotfix-unsecure-events
Fixes unsafe pointer madness.
This commit is contained in:
commit
0f56f3acdd
15
events.go
15
events.go
@ -9,7 +9,6 @@
|
||||
package termui
|
||||
|
||||
import "github.com/nsf/termbox-go"
|
||||
import "unsafe"
|
||||
|
||||
/***********************************termbox-go**************************************/
|
||||
|
||||
@ -133,7 +132,19 @@ const (
|
||||
|
||||
// convert termbox.Event to termui.Event
|
||||
func uiEvt(e termbox.Event) Event {
|
||||
return *(*Event)(unsafe.Pointer(&e))
|
||||
event := Event{}
|
||||
event.Type = EventType(e.Type)
|
||||
event.Mod = Modifier(e.Mod)
|
||||
event.Key = Key(e.Key)
|
||||
event.Ch = e.Ch
|
||||
event.Width = e.Width
|
||||
event.Height = e.Height
|
||||
event.Err = e.Err
|
||||
event.MouseX = e.MouseX
|
||||
event.MouseY = e.MouseY
|
||||
event.N = e.N
|
||||
|
||||
return event
|
||||
}
|
||||
|
||||
var evtChs = make([]chan Event, 0)
|
||||
|
28
events_test.go
Normal file
28
events_test.go
Normal file
@ -0,0 +1,28 @@
|
||||
// Copyright 2015 Zack Guo <gizak@icloud.com>. All rights reserved.
|
||||
// Use of this source code is governed by a MIT license that can
|
||||
// be found in the LICENSE file.
|
||||
//
|
||||
// Portions of this file uses [termbox-go](https://github.com/nsf/termbox-go/blob/54b74d087b7c397c402d0e3b66d2ccb6eaf5c2b4/api_common.go)
|
||||
// by [authors](https://github.com/nsf/termbox-go/blob/master/AUTHORS)
|
||||
// under [license](https://github.com/nsf/termbox-go/blob/master/LICENSE)
|
||||
|
||||
package termui
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
termbox "github.com/nsf/termbox-go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type boxEvent termbox.Event
|
||||
|
||||
func TestUiEvt(t *testing.T) {
|
||||
err := errors.New("This is a mock error")
|
||||
event := boxEvent{3, 5, 2, 'H', 200, 500, err, 50, 30, 2}
|
||||
expetced := Event{3, 5, 2, 'H', 200, 500, err, 50, 30, 2}
|
||||
|
||||
// We need to do that ugly casting so that vet does not complain
|
||||
assert.Equal(t, uiEvt(termbox.Event(event)), expetced)
|
||||
}
|
Loading…
Reference in New Issue
Block a user