paste.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2020 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. // EventPaste is used to mark the start and end of a bracketed paste.
  19. // An event with .Start() true will be sent to mark the start.
  20. // Then a number of keys will be sent to indicate that the content
  21. // is pasted in. At the end, an event with .Start() false will be sent.
  22. type EventPaste struct {
  23. start bool
  24. t time.Time
  25. }
  26. // When returns the time when this EventPaste was created.
  27. func (ev *EventPaste) When() time.Time {
  28. return ev.t
  29. }
  30. // Start returns true if this is the start of a paste.
  31. func (ev *EventPaste) Start() bool {
  32. return ev.start
  33. }
  34. // End returns true if this is the end of a paste.
  35. func (ev *EventPaste) End() bool {
  36. return !ev.start
  37. }
  38. // NewEventPaste returns a new EventPaste.
  39. func NewEventPaste(start bool) *EventPaste {
  40. return &EventPaste{t: time.Now(), start: start}
  41. }