paste.go (1991B)
1 // Copyright 2024 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 // EventPaste is used to mark the start and end of a bracketed paste. 22 // 23 // An event with .Start() true will be sent to mark the start of a bracketed paste, 24 // followed by a number of keys (string data) for the content, ending with the 25 // an event with .End() true. 26 type EventPaste struct { 27 start bool 28 t time.Time 29 data []byte 30 } 31 32 // When returns the time when this EventPaste was created. 33 func (ev *EventPaste) When() time.Time { 34 return ev.t 35 } 36 37 // Start returns true if this is the start of a paste. 38 func (ev *EventPaste) Start() bool { 39 return ev.start 40 } 41 42 // End returns true if this is the end of a paste. 43 func (ev *EventPaste) End() bool { 44 return !ev.start 45 } 46 47 // NewEventPaste returns a new EventPaste. 48 func NewEventPaste(start bool) *EventPaste { 49 return &EventPaste{t: time.Now(), start: start} 50 } 51 52 // NewEventClipboard returns a new NewEventClipboard with a data payload 53 func NewEventClipboard(data []byte) *EventClipboard { 54 return &EventClipboard{t: time.Now(), data: data} 55 } 56 57 // EventClipboard represents data from the clipboard, 58 // in response to a GetClipboard request. 59 type EventClipboard struct { 60 t time.Time 61 data []byte 62 } 63 64 // Data returns the attached binary data. 65 func (ev *EventClipboard) Data() []byte { 66 return ev.data 67 } 68 69 // When returns the time when this event was created. 70 func (ev *EventClipboard) When() time.Time { 71 return ev.t 72 }