1// Copyright 2015 The TCell Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use file except in compliance with the License.
5// You may obtain a copy of the license at
6//
7//    http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package tcell
16
17import (
18	"time"
19)
20
21// Event is a generic interface used for passing around Events.
22// Concrete types follow.
23type Event interface {
24	// When reports the time when the event was generated.
25	When() time.Time
26}
27
28// EventTime is a simple base event class, suitable for easy reuse.
29// It can be used to deliver actual timer events as well.
30type EventTime struct {
31	when time.Time
32}
33
34// When returns the time stamp when the event occurred.
35func (e *EventTime) When() time.Time {
36	return e.when
37}
38
39// SetEventTime sets the time of occurrence for the event.
40func (e *EventTime) SetEventTime(t time.Time) {
41	e.when = t
42}
43
44// SetEventNow sets the time of occurrence for the event to the current time.
45func (e *EventTime) SetEventNow() {
46	e.SetEventTime(time.Now())
47}
48
49// EventHandler is anything that handles events.  If the handler has
50// consumed the event, it should return true.  False otherwise.
51type EventHandler interface {
52	HandleEvent(Event) bool
53}
54