Debian Codegraph @

debian/vendor/github.com/micro-editor/tcell/v2/event.go

raw
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
15 package tcell
16
17 import (
18 "time"
19 )
20
21 // Event is a generic interface used for passing around Events.
22 // Concrete types follow.
23 type Event interface {
24 // When reports the time when the event was generated.
25 When() time.Time
26 // EscSeq returns the escape sequence that was parsed for this event
27 EscSeq() string
28 }
29
30 // EventTime is a simple base event class, suitable for easy reuse.
31 // It can be used to deliver actual timer events as well.
32 type EventTime struct {
33 when time.Time
34 }
35
36 // When returns the time stamp when the event occurred.
37 func (e *EventTime) When() time.Time {
38 return e.when
39 }
40
41 // SetEventTime sets the time of occurrence for the event.
42 func (e *EventTime) SetEventTime(t time.Time) {
43 e.when = t
44 }
45
46 // SetEventNow sets the time of occurrence for the event to the current time.
47 func (e *EventTime) SetEventNow() {
48 e.SetEventTime(time.Now())
49 }
50
51 // EventHandler is anything that handles events. If the handler has
52 // consumed the event, it should return true. False otherwise.
53 type EventHandler interface {
54 HandleEvent(Event) bool
55 }