event.go 1.5 KB

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