You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: api.go
    path of file: ./repos/gotop/vendor/github.com/nsf/termbox-go
    
    the code of the file until where you have to start completion: // +build !windows

package termbox

import "github.com/mattn/go-runewidth"
import "fmt"
import "os"
import "os/signal"
import "syscall"
import "runtime"
import "time"

// public API

// Initializes termbox library. This function should be called before any other functions.
// After successful initialization, the library must be finalized using 'Close' function.
//
// Example usage:
//      err := termbox.Init()
//      if err != nil {
//              panic(err)
//      }
//      defer termbox.Close()
func Init() error {
	var err error

	if runtime.GOOS == "openbsd" {
		out, err = os.OpenFile("/dev/tty", os.O_RDWR, 0)
		if err != nil {
			return err
		}
		in = int(out.Fd())
	} else {
		out, err = os.OpenFile("/dev/tty", os.O_WRONLY, 0)
		if err != nil {
			return err
		}
		in, err = syscall.Open("/dev/tty", syscall.O_RDONLY, 0)
		if err != nil {
			return err
		}
	}

	err = setup_term()
	if err != nil {
		return fmt.Errorf("termbox: error while reading terminfo data: %v", err)
	}

	signal.Notify(sigwinch, syscall.SIGWINCH)
	signal.Notify(sigio, syscall.SIGIO)

	_, err = fcntl(in, syscall.F_SETFL, syscall.O_ASYNC|syscall.O_NONBLOCK)
	if err != nil {
		return err
	}
	_, err = fcntl(in, syscall.F_SETOWN, syscall.Getpid())
	if runtime.GOOS != "darwin" && err != nil {
		return err
	}
	
    
func PollEvent() Event {
	// Constant governing macOS specific behavior. See https://github.com/nsf/termbox-go/issues/132
	// This is an arbitrary delay which hopefully will be enough time for any lagging
	// partial escape sequences to come through.
	const esc_wait_delay = 100 * time.Millisecond

	var event Event
	var esc_wait_timer *time.Timer
	var esc_timeout <-chan time.Time

	// try to extract event from input buffer, return on success
	event.Type = EventKey
	status := extract_event(inbuf, &event, true)
	if event.N != 0 {
		copy(inbuf, inbuf[event.N:])
		inbuf = inbuf[:len(inbuf)-event.N]
	}
	if status == event_extracted {
		return event
	} else if status == esc_wait {
		esc_wait_timer = time.NewTimer(esc_wait_delay)
		esc_timeout = esc_wait_timer.C
	}

	for {
		select {
		case ev := <-input_comm:
			if esc_wait_timer != nil {
				if !esc_wait_timer.Stop() {
					<-esc_wait_timer.C
				}
				esc_wait_timer = nil
			}

			if ev.err != nil {
				return Event{Type: EventError, Err: ev.err}
			}

			inbuf = append(inbuf, ev.data...)
			input_comm <- ev
			status := extract_event(inbuf, &event, true)
			if event.N != 0 {
				copy(inbuf, inbuf[event.N:])
				inbuf = inbuf[:len(inbuf)-event.N]
			}
			if status == event_extracted {
				return event
			} else if status == esc_wait {
				esc_wait_timer = time.NewTimer(esc_wait_delay)
				esc_timeout = esc_wait_timer.C
			}
		case <-esc_timeout:
			esc_wait_timer = nil

			status := extract_event(inbuf, &event, false)
			if event.N != 0 {
				copy(inbuf, inbuf[event.N:])
				inbuf = inbuf[:len(inbuf)-event.N]
			}
			if status == event_extracted {
				return event
			}
		case <-interrupt_comm:
			event.Type = EventInterrupt
			return event

		case <-sigwinch:
			event.Type = EventResize
			event.Width, event.Height = get_term_size(out.Fd())
			return event
		}
	}
}