errors.go 2.5 KB

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