Debian Codegraph @

debian/vendor/github.com/micro-editor/tcell/v2/screen.go

raw
1 // Copyright 2019 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 // Screen represents the physical (or emulated) screen.
18 // This can be a terminal window or a physical console. Platforms implement
19 // this differerently.
20 type Screen interface {
21 // Init initializes the screen for use.
22 Init() error
23
24 // Fini finalizes the screen also releasing resources.
25 Fini()
26
27 // Clear erases the screen. The contents of any screen buffers
28 // will also be cleared. This has the logical effect of
29 // filling the screen with spaces, using the global default style.
30 Clear()
31
32 // Fill fills the screen with the given character and style.
33 Fill(rune, Style)
34
35 // SetCell is an older API, and will be removed. Please use
36 // SetContent instead; SetCell is implemented in terms of SetContent.
37 SetCell(x int, y int, style Style, ch ...rune)
38
39 // GetContent returns the contents at the given location. If the
40 // coordinates are out of range, then the values will be 0, nil,
41 // StyleDefault. Note that the contents returned are logical contents
42 // and may not actually be what is displayed, but rather are what will
43 // be displayed if Show() or Sync() is called. The width is the width
44 // in screen cells; most often this will be 1, but some East Asian
45 // characters require two cells.
46 GetContent(x, y int) (mainc rune, combc []rune, style Style, width int)
47
48 // SetContent sets the contents of the given cell location. If
49 // the coordinates are out of range, then the operation is ignored.
50 //
51 // The first rune is the primary non-zero width rune. The array
52 // that follows is a possible list of combining characters to append,
53 // and will usually be nil (no combining characters.)
54 //
55 // The results are not displayd until Show() or Sync() is called.
56 //
57 // Note that wide (East Asian full width) runes occupy two cells,
58 // and attempts to place character at next cell to the right will have
59 // undefined effects. Wide runes that are printed in the
60 // last column will be replaced with a single width space on output.
61 SetContent(x int, y int, mainc rune, combc []rune, style Style)
62
63 // SetStyle sets the default style to use when clearing the screen
64 // or when StyleDefault is specified. If it is also StyleDefault,
65 // then whatever system/terminal default is relevant will be used.
66 SetStyle(style Style)
67
68 // ShowCursor is used to display the cursor at a given location.
69 // If the coordinates -1, -1 are given or are otherwise outside the
70 // dimensions of the screen, the cursor will be hidden.
71 ShowCursor(x int, y int)
72
73 // HideCursor is used to hide the cursor. Its an alias for
74 // ShowCursor(-1, -1).
75 HideCursor()
76
77 // Size returns the screen size as width, height. This changes in
78 // response to a call to Clear or Flush.
79 Size() (int, int)
80
81 // PollEvent waits for events to arrive. Main application loops
82 // must spin on this to prevent the application from stalling.
83 // Furthermore, this will return nil if the Screen is finalized.
84 PollEvent() Event
85
86 // PostEvent tries to post an event into the event stream. This
87 // can fail if the event queue is full. In that case, the event
88 // is dropped, and ErrEventQFull is returned.
89 PostEvent(ev Event) error
90
91 // PostEventWait is like PostEvent, but if the queue is full, it
92 // blocks until there is space in the queue, making delivery
93 // reliable. However, it is VERY important that this function
94 // never be called from within whatever event loop is polling
95 // with PollEvent(), otherwise a deadlock may arise.
96 //
97 // For this reason, when using this function, the use of a
98 // Goroutine is recommended to ensure no deadlock can occur.
99 PostEventWait(ev Event)
100
101 // EnableMouse enables the mouse. (If your terminal supports it.)
102 EnableMouse()
103
104 // DisableMouse disables the mouse.
105 DisableMouse()
106
107 // HasMouse returns true if the terminal (apparently) supports a
108 // mouse. Note that the a return value of true doesn't guarantee that
109 // a mouse/pointing device is present; a false return definitely
110 // indicates no mouse support is available.
111 HasMouse() bool
112
113 // Colors returns the number of colors. All colors are assumed to
114 // use the ANSI color map. If a terminal is monochrome, it will
115 // return 0.
116 Colors() int
117
118 // Show makes all the content changes made using SetContent() visible
119 // on the display.
120 //
121 // It does so in the most efficient and least visually disruptive
122 // manner possible.
123 Show()
124
125 // Sync works like Show(), but it updates every visible cell on the
126 // physical display, assuming that it is not synchronized with any
127 // internal model. This may be both expensive and visually jarring,
128 // so it should only be used when believed to actually be necessary.
129 //
130 // Typically this is called as a result of a user-requested redraw
131 // (e.g. to clear up on screen corruption caused by some other program),
132 // or during a resize event.
133 Sync()
134
135 // CharacterSet returns information about the character set.
136 // This isn't the full locale, but it does give us the input/output
137 // character set. Note that this is just for diagnostic purposes,
138 // we normally translate input/output to/from UTF-8, regardless of
139 // what the user's environment is.
140 CharacterSet() string
141
142 // RegisterRuneFallback adds a fallback for runes that are not
143 // part of the character set -- for example one coudld register
144 // o as a fallback for ΓΈ. This should be done cautiously for
145 // characters that might be displayed ordinarily in language
146 // specific text -- characters that could change the meaning of
147 // of written text would be dangerous. The intention here is to
148 // facilitate fallback characters in pseudo-graphical applications.
149 //
150 // If the terminal has fallbacks already in place via an alternate
151 // character set, those are used in preference. Also, standard
152 // fallbacks for graphical characters in the ACSC terminfo string
153 // are registered implicitly.
154
155 // The display string should be the same width as original rune.
156 // This makes it possible to register two character replacements
157 // for full width East Asian characters, for example.
158 //
159 // It is recommended that replacement strings consist only of
160 // 7-bit ASCII, since other characters may not display everywhere.
161 RegisterRuneFallback(r rune, subst string)
162
163 // UnregisterRuneFallback unmaps a replacement. It will unmap
164 // the implicit ASCII replacements for alternate characters as well.
165 // When an unmapped char needs to be displayed, but no suitable
166 // glyph is available, '?' is emitted instead. It is not possible
167 // to "disable" the use of alternate characters that are supported
168 // by your terminal except by changing the terminal database.
169 UnregisterRuneFallback(r rune)
170
171 // CanDisplay returns true if the given rune can be displayed on
172 // this screen. Note that this is a best guess effort -- whether
173 // your fonts support the character or not may be questionable.
174 // Mostly this is for folks who work outside of Unicode.
175 //
176 // If checkFallbacks is true, then if any (possibly imperfect)
177 // fallbacks are registered, this will return true. This will
178 // also return true if the terminal can replace the glyph with
179 // one that is visually indistinguishable from the one requested.
180 CanDisplay(r rune, checkFallbacks bool) bool
181
182 // Resize does nothing, since its generally not possible to
183 // ask a screen to resize, but it allows the Screen to implement
184 // the View interface.
185 Resize(int, int, int, int)
186
187 // HasKey returns true if the keyboard is believed to have the
188 // key. In some cases a keyboard may have keys with this name
189 // but no support for them, while in others a key may be reported
190 // as supported but not actually be usable (such as some emulators
191 // that hijack certain keys). Its best not to depend to strictly
192 // on this function, but it can be used for hinting when building
193 // menus, displayed hot-keys, etc. Note that KeyRune (literal
194 // runes) is always true.
195 HasKey(Key) bool
196
197 // RegisterRawSeq registers a user-defined escape code that should
198 // be parsed by the screen
199 // Not defined for non-posix systems
200 RegisterRawSeq(string)
201
202 // UnregisterRawSeq unregisters a user-defined escape code that should
203 // be parsed by the screen
204 // Not defined for non-posix systems
205 UnregisterRawSeq(string)
206
207 // SetPaste sets whether or not this screen should be expecting paste
208 // events. When paste is true, all key events with multiple bytes
209 // will be treated as pastes rather than as the user typing really
210 // fast. This is to enable a feature similar to Vim's "paste" option.
211 SetPaste(bool)
212
213 // GetClipboard sends an OSC 52 escape sequence to the tty requesting
214 // that the clipboard contents be sent in base64 encoding.
215 GetClipboard(string) error
216
217 // SetClipboard sends an OSC 52 escape sequence to the tty with a base64
218 // encoded string requesting that the string be decoded and placed into
219 // the system clipboard.
220 SetClipboard(string, string) error
221
222 // Beep attempts to sound an OS-dependent audible alert and returns an error
223 // when unsuccessful.
224 Beep() error
225 }
226
227 // NewScreen returns a default Screen suitable for the user's terminal
228 // environment.
229 func NewScreen() (Screen, error) {
230 // Windows is happier if we try for a console screen first.
231 if s, _ := NewConsoleScreen(); s != nil {
232 return s, nil
233 } else if s, e := NewTerminfoScreen(); s != nil {
234 return s, nil
235 } else {
236 return nil, e
237 }
238 }