| 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 |
"errors" |
| 19 |
"time" |
| 20 |
|
| 21 |
"github.com/micro-editor/tcell/v2/terminfo" |
| 22 |
) |
| 23 |
|
| 24 |
var ( |
| 25 |
// ErrTermNotFound indicates that a suitable terminal entry could |
| 26 |
// not be found. This can result from either not having TERM set, |
| 27 |
// or from the TERM failing to support certain minimal functionality, |
| 28 |
// in particular absolute cursor addressability (the cup capability) |
| 29 |
// is required. For example, legacy "adm3" lacks this capability, |
| 30 |
// whereas the slightly newer "adm3a" supports it. This failure |
| 31 |
// occurs most often with "dumb". |
| 32 |
ErrTermNotFound = terminfo.ErrTermNotFound |
| 33 |
|
| 34 |
// ErrNoScreen indicates that no suitable screen could be found. |
| 35 |
// This may result from attempting to run on a platform where there |
| 36 |
// is no support for either termios or console I/O (such as nacl), |
| 37 |
// or from running in an environment where there is no access to |
| 38 |
// a suitable console/terminal device. (For example, running on |
| 39 |
// without a controlling TTY or with no /dev/tty on POSIX platforms.) |
| 40 |
ErrNoScreen = errors.New("no suitable screen available") |
| 41 |
|
| 42 |
// ErrNoCharset indicates that the locale environment the |
| 43 |
// program is not supported by the program, because no suitable |
| 44 |
// encoding was found for it. This problem never occurs if |
| 45 |
// the environment is UTF-8 or UTF-16. |
| 46 |
ErrNoCharset = errors.New("character set not supported") |
| 47 |
|
| 48 |
// ErrEventQFull indicates that the event queue is full, and |
| 49 |
// cannot accept more events. |
| 50 |
ErrEventQFull = errors.New("event queue full") |
| 51 |
) |
| 52 |
|
| 53 |
// An EventError is an event representing some sort of error, and carries |
| 54 |
// an error payload. |
| 55 |
type EventError struct { |
| 56 |
t time.Time |
| 57 |
err error |
| 58 |
} |
| 59 |
|
| 60 |
// When returns the time when the event was created. |
| 61 |
func (ev *EventError) When() time.Time { |
| 62 |
return ev.t |
| 63 |
} |
| 64 |
|
| 65 |
// Error implements the error. |
| 66 |
func (ev *EventError) Error() string { |
| 67 |
return ev.err.Error() |
| 68 |
} |
| 69 |
|
| 70 |
func (ev *EventError) Err() error { |
| 71 |
return ev.err |
| 72 |
} |
| 73 |
|
| 74 |
func (ev *EventError) EscSeq() string { |
| 75 |
return ev.err.Error() |
| 76 |
} |
| 77 |
|
| 78 |
// NewEventError creates an ErrorEvent with the given error payload. |
| 79 |
func NewEventError(err error) *EventError { |
| 80 |
return &EventError{t: time.Now(), err: err} |
| 81 |
} |