2021-01-25 07:18:06 +08:00
|
|
|
// Copyright 2021 The TCell Authors
|
2015-10-06 13:53:22 +08:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the license at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package tcell
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
"unicode/utf8"
|
|
|
|
|
|
|
|
"golang.org/x/text/transform"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NewSimulationScreen returns a SimulationScreen. Note that
|
|
|
|
// SimulationScreen is also a Screen.
|
|
|
|
func NewSimulationScreen(charset string) SimulationScreen {
|
|
|
|
if charset == "" {
|
|
|
|
charset = "UTF-8"
|
|
|
|
}
|
|
|
|
s := &simscreen{charset: charset}
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
// SimulationScreen represents a screen simulation. This is intended to
|
|
|
|
// be a superset of normal Screens, but also adds some important interfaces
|
|
|
|
// for testing.
|
|
|
|
type SimulationScreen interface {
|
|
|
|
// InjectKeyBytes injects a stream of bytes corresponding to
|
|
|
|
// the native encoding (see charset). It turns true if the entire
|
|
|
|
// set of bytes were processed and delivered as KeyEvents, false
|
|
|
|
// if any bytes were not fully understood. Any bytes that are not
|
|
|
|
// fully converted are discarded.
|
|
|
|
InjectKeyBytes(buf []byte) bool
|
|
|
|
|
|
|
|
// InjectKey injects a key event. The rune is a UTF-8 rune, post
|
|
|
|
// any translation.
|
|
|
|
InjectKey(key Key, r rune, mod ModMask)
|
|
|
|
|
|
|
|
// InjectMouse injects a mouse event.
|
|
|
|
InjectMouse(x, y int, buttons ButtonMask, mod ModMask)
|
|
|
|
|
2015-10-31 00:33:45 +08:00
|
|
|
// SetSize resizes the underlying physical screen. It also causes
|
2015-10-06 13:53:22 +08:00
|
|
|
// a resize event to be injected during the next Show() or Sync().
|
|
|
|
// A new physical contents array will be allocated (with data from
|
|
|
|
// the old copied), so any prior value obtained with GetContents
|
|
|
|
// won't be used anymore
|
2015-10-31 00:33:45 +08:00
|
|
|
SetSize(width, height int)
|
2015-10-06 13:53:22 +08:00
|
|
|
|
|
|
|
// GetContents returns screen contents as an array of
|
|
|
|
// cells, along with the physical width & height. Note that the
|
2015-10-31 00:33:45 +08:00
|
|
|
// physical contents will be used until the next time SetSize()
|
2015-10-06 13:53:22 +08:00
|
|
|
// is called.
|
|
|
|
GetContents() (cells []SimCell, width int, height int)
|
|
|
|
|
|
|
|
// GetCursor returns the cursor details.
|
|
|
|
GetCursor() (x int, y int, visible bool)
|
|
|
|
|
|
|
|
Screen
|
|
|
|
}
|
|
|
|
|
|
|
|
// SimCell represents a simulated screen cell. The purpose of this
|
|
|
|
// is to track on screen content.
|
|
|
|
type SimCell struct {
|
|
|
|
// Bytes is the actual character bytes. Normally this is
|
|
|
|
// rune data, but it could be be data in another encoding system.
|
|
|
|
Bytes []byte
|
|
|
|
|
|
|
|
// Style is the style used to display the data.
|
|
|
|
Style Style
|
|
|
|
|
|
|
|
// Runes is the list of runes, unadulterated, in UTF-8.
|
|
|
|
Runes []rune
|
|
|
|
}
|
|
|
|
|
|
|
|
type simscreen struct {
|
|
|
|
physw int
|
|
|
|
physh int
|
2015-10-07 15:56:18 +08:00
|
|
|
fini bool
|
2015-10-06 13:53:22 +08:00
|
|
|
style Style
|
|
|
|
evch chan Event
|
|
|
|
quit chan struct{}
|
|
|
|
|
|
|
|
front []SimCell
|
2015-10-07 15:56:18 +08:00
|
|
|
back CellBuffer
|
2015-10-06 13:53:22 +08:00
|
|
|
clear bool
|
|
|
|
cursorx int
|
|
|
|
cursory int
|
|
|
|
cursorvis bool
|
|
|
|
mouse bool
|
2020-10-16 13:13:08 +08:00
|
|
|
paste bool
|
2015-10-06 13:53:22 +08:00
|
|
|
charset string
|
|
|
|
encoder transform.Transformer
|
|
|
|
decoder transform.Transformer
|
|
|
|
fillchar rune
|
|
|
|
fillstyle Style
|
2015-10-15 10:09:00 +08:00
|
|
|
fallback map[rune]string
|
2015-10-06 13:53:22 +08:00
|
|
|
|
|
|
|
sync.Mutex
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *simscreen) Init() error {
|
|
|
|
s.evch = make(chan Event, 10)
|
2018-04-02 23:17:51 +08:00
|
|
|
s.quit = make(chan struct{})
|
2015-10-06 13:53:22 +08:00
|
|
|
s.fillchar = 'X'
|
|
|
|
s.fillstyle = StyleDefault
|
|
|
|
s.mouse = false
|
|
|
|
s.physw = 80
|
|
|
|
s.physh = 25
|
|
|
|
s.cursorx = -1
|
|
|
|
s.cursory = -1
|
|
|
|
s.style = StyleDefault
|
|
|
|
|
2015-10-15 10:09:00 +08:00
|
|
|
if enc := GetEncoding(s.charset); enc != nil {
|
|
|
|
s.encoder = enc.NewEncoder()
|
|
|
|
s.decoder = enc.NewDecoder()
|
|
|
|
} else {
|
|
|
|
return ErrNoCharset
|
2015-10-06 13:53:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
s.front = make([]SimCell, s.physw*s.physh)
|
2015-10-07 15:56:18 +08:00
|
|
|
s.back.Resize(80, 25)
|
2015-10-06 13:53:22 +08:00
|
|
|
|
2015-10-15 10:09:00 +08:00
|
|
|
// default fallbacks
|
|
|
|
s.fallback = make(map[rune]string)
|
|
|
|
for k, v := range RuneFallbacks {
|
|
|
|
s.fallback[k] = v
|
|
|
|
}
|
2015-10-06 13:53:22 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *simscreen) Fini() {
|
2015-10-07 15:56:18 +08:00
|
|
|
s.Lock()
|
|
|
|
s.fini = true
|
|
|
|
s.back.Resize(0, 0)
|
|
|
|
s.Unlock()
|
2015-10-06 13:53:22 +08:00
|
|
|
if s.quit != nil {
|
|
|
|
close(s.quit)
|
|
|
|
}
|
|
|
|
s.physw = 0
|
|
|
|
s.physh = 0
|
|
|
|
s.front = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *simscreen) SetStyle(style Style) {
|
|
|
|
s.Lock()
|
|
|
|
s.style = style
|
|
|
|
s.Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *simscreen) Clear() {
|
2016-05-24 05:55:11 +08:00
|
|
|
s.Fill(' ', s.style)
|
|
|
|
}
|
2015-10-06 13:53:22 +08:00
|
|
|
|
2016-05-24 05:55:11 +08:00
|
|
|
func (s *simscreen) Fill(r rune, style Style) {
|
2015-10-06 13:53:22 +08:00
|
|
|
s.Lock()
|
2016-05-24 05:55:11 +08:00
|
|
|
s.back.Fill(r, style)
|
2015-10-06 13:53:22 +08:00
|
|
|
s.Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *simscreen) SetCell(x, y int, style Style, ch ...rune) {
|
|
|
|
|
2015-10-07 15:56:18 +08:00
|
|
|
if len(ch) > 0 {
|
|
|
|
s.SetContent(x, y, ch[0], ch[1:], style)
|
|
|
|
} else {
|
|
|
|
s.SetContent(x, y, ' ', nil, style)
|
2015-10-06 13:53:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-07 15:56:18 +08:00
|
|
|
func (s *simscreen) SetContent(x, y int, mainc rune, combc []rune, st Style) {
|
|
|
|
|
2015-10-06 13:53:22 +08:00
|
|
|
s.Lock()
|
2015-10-07 15:56:18 +08:00
|
|
|
s.back.SetContent(x, y, mainc, combc, st)
|
2015-10-06 13:53:22 +08:00
|
|
|
s.Unlock()
|
|
|
|
}
|
|
|
|
|
2015-10-07 15:56:18 +08:00
|
|
|
func (s *simscreen) GetContent(x, y int) (rune, []rune, Style, int) {
|
|
|
|
var mainc rune
|
|
|
|
var combc []rune
|
|
|
|
var style Style
|
|
|
|
var width int
|
2015-10-06 13:53:22 +08:00
|
|
|
s.Lock()
|
2015-10-07 15:56:18 +08:00
|
|
|
mainc, combc, style, width = s.back.GetContent(x, y)
|
2015-10-06 13:53:22 +08:00
|
|
|
s.Unlock()
|
2015-10-07 15:56:18 +08:00
|
|
|
return mainc, combc, style, width
|
2015-10-06 13:53:22 +08:00
|
|
|
}
|
|
|
|
|
2015-10-07 15:56:18 +08:00
|
|
|
func (s *simscreen) drawCell(x, y int) int {
|
|
|
|
|
|
|
|
mainc, combc, style, width := s.back.GetContent(x, y)
|
|
|
|
if !s.back.Dirty(x, y) {
|
|
|
|
return width
|
|
|
|
}
|
2015-10-06 13:53:22 +08:00
|
|
|
if x >= s.physw || y >= s.physh || x < 0 || y < 0 {
|
2015-10-07 15:56:18 +08:00
|
|
|
return width
|
2015-10-06 13:53:22 +08:00
|
|
|
}
|
|
|
|
simc := &s.front[(y*s.physw)+x]
|
2015-10-07 15:56:18 +08:00
|
|
|
|
|
|
|
if style == StyleDefault {
|
|
|
|
style = s.style
|
2015-10-06 13:53:22 +08:00
|
|
|
}
|
2015-10-07 15:56:18 +08:00
|
|
|
simc.Style = style
|
|
|
|
simc.Runes = append([]rune{mainc}, combc...)
|
2015-10-06 13:53:22 +08:00
|
|
|
|
|
|
|
// now emit runes - taking care to not overrun width with a
|
|
|
|
// wide character, and to ensure that we emit exactly one regular
|
|
|
|
// character followed up by any residual combing characters
|
|
|
|
|
|
|
|
simc.Bytes = nil
|
|
|
|
|
2015-10-07 15:56:18 +08:00
|
|
|
if x > s.physw-width {
|
2015-10-06 13:53:22 +08:00
|
|
|
simc.Runes = []rune{' '}
|
|
|
|
simc.Bytes = []byte{' '}
|
2015-10-07 15:56:18 +08:00
|
|
|
return width
|
2015-10-06 13:53:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
lbuf := make([]byte, 12)
|
2015-10-15 10:09:00 +08:00
|
|
|
ubuf := make([]byte, 12)
|
|
|
|
nout := 0
|
2015-10-06 13:53:22 +08:00
|
|
|
|
|
|
|
for _, r := range simc.Runes {
|
2015-10-15 10:09:00 +08:00
|
|
|
|
2015-10-06 13:53:22 +08:00
|
|
|
l := utf8.EncodeRune(ubuf, r)
|
2015-10-15 10:09:00 +08:00
|
|
|
|
2015-11-05 09:05:24 +08:00
|
|
|
nout, _, _ = s.encoder.Transform(lbuf, ubuf[:l], true)
|
2015-10-15 10:09:00 +08:00
|
|
|
|
|
|
|
if nout == 0 || lbuf[0] == '\x1a' {
|
|
|
|
|
|
|
|
// skip combining
|
|
|
|
|
|
|
|
if subst, ok := s.fallback[r]; ok {
|
|
|
|
simc.Bytes = append(simc.Bytes,
|
|
|
|
[]byte(subst)...)
|
|
|
|
|
|
|
|
} else if r >= ' ' && r <= '~' {
|
|
|
|
simc.Bytes = append(simc.Bytes, byte(r))
|
|
|
|
|
|
|
|
} else if simc.Bytes == nil {
|
2015-10-06 13:53:22 +08:00
|
|
|
simc.Bytes = append(simc.Bytes, '?')
|
|
|
|
}
|
2015-10-15 10:09:00 +08:00
|
|
|
} else {
|
2015-10-06 13:53:22 +08:00
|
|
|
simc.Bytes = append(simc.Bytes, lbuf[:nout]...)
|
|
|
|
}
|
|
|
|
}
|
2015-10-07 15:56:18 +08:00
|
|
|
s.back.SetDirty(x, y, false)
|
|
|
|
return width
|
2015-10-06 13:53:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *simscreen) ShowCursor(x, y int) {
|
|
|
|
s.Lock()
|
|
|
|
s.cursorx, s.cursory = x, y
|
|
|
|
s.showCursor()
|
|
|
|
s.Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *simscreen) HideCursor() {
|
|
|
|
s.ShowCursor(-1, -1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *simscreen) showCursor() {
|
|
|
|
|
|
|
|
x, y := s.cursorx, s.cursory
|
|
|
|
if x < 0 || y < 0 || x >= s.physw || y >= s.physh {
|
|
|
|
s.cursorvis = false
|
|
|
|
} else {
|
|
|
|
s.cursorvis = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *simscreen) hideCursor() {
|
|
|
|
// does not update cursor position
|
|
|
|
s.cursorvis = false
|
|
|
|
}
|
|
|
|
|
2021-09-27 07:31:20 +08:00
|
|
|
func (s *simscreen) SetCursorStyle(CursorStyle) {}
|
|
|
|
|
2015-10-06 13:53:22 +08:00
|
|
|
func (s *simscreen) Show() {
|
|
|
|
s.Lock()
|
|
|
|
s.resize()
|
|
|
|
s.draw()
|
|
|
|
s.Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *simscreen) clearScreen() {
|
|
|
|
// We emulate a hardware clear by filling with a specific pattern
|
|
|
|
for i := range s.front {
|
|
|
|
s.front[i].Style = s.fillstyle
|
|
|
|
s.front[i].Runes = []rune{s.fillchar}
|
|
|
|
s.front[i].Bytes = []byte{byte(s.fillchar)}
|
|
|
|
}
|
|
|
|
s.clear = false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *simscreen) draw() {
|
|
|
|
s.hideCursor()
|
|
|
|
if s.clear {
|
|
|
|
s.clearScreen()
|
|
|
|
}
|
|
|
|
|
2015-10-07 15:56:18 +08:00
|
|
|
w, h := s.back.Size()
|
|
|
|
for y := 0; y < h; y++ {
|
|
|
|
for x := 0; x < w; x++ {
|
|
|
|
width := s.drawCell(x, y)
|
|
|
|
x += width - 1
|
2015-10-06 13:53:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
s.showCursor()
|
|
|
|
}
|
|
|
|
|
2021-01-25 07:18:06 +08:00
|
|
|
func (s *simscreen) EnableMouse(...MouseFlags) {
|
2015-10-06 13:53:22 +08:00
|
|
|
s.mouse = true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *simscreen) DisableMouse() {
|
|
|
|
s.mouse = false
|
|
|
|
}
|
|
|
|
|
2020-10-16 13:13:08 +08:00
|
|
|
func (s *simscreen) EnablePaste() {
|
|
|
|
s.paste = true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *simscreen) DisablePaste() {
|
|
|
|
s.paste = false
|
|
|
|
}
|
|
|
|
|
2015-10-06 13:53:22 +08:00
|
|
|
func (s *simscreen) Size() (int, int) {
|
|
|
|
s.Lock()
|
2015-10-07 15:56:18 +08:00
|
|
|
w, h := s.back.Size()
|
2015-10-06 13:53:22 +08:00
|
|
|
s.Unlock()
|
|
|
|
return w, h
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *simscreen) resize() {
|
|
|
|
w, h := s.physw, s.physh
|
2015-10-07 15:56:18 +08:00
|
|
|
ow, oh := s.back.Size()
|
|
|
|
if w != ow || h != oh {
|
|
|
|
s.back.Resize(w, h)
|
|
|
|
ev := NewEventResize(w, h)
|
2015-10-06 13:53:22 +08:00
|
|
|
s.PostEvent(ev)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *simscreen) Colors() int {
|
|
|
|
return 256
|
|
|
|
}
|
|
|
|
|
2021-06-12 10:43:12 +08:00
|
|
|
func (s *simscreen) ChannelEvents(ch chan<- Event, quit <-chan struct{}) {
|
|
|
|
defer close(ch)
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-quit:
|
|
|
|
return
|
|
|
|
case <-s.quit:
|
|
|
|
return
|
|
|
|
case ev := <-s.evch:
|
|
|
|
select {
|
|
|
|
case <-quit:
|
|
|
|
return
|
|
|
|
case <-s.quit:
|
|
|
|
return
|
|
|
|
case ch <- ev:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-06 13:53:22 +08:00
|
|
|
func (s *simscreen) PollEvent() Event {
|
|
|
|
select {
|
|
|
|
case <-s.quit:
|
|
|
|
return nil
|
|
|
|
case ev := <-s.evch:
|
|
|
|
return ev
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-17 00:21:17 +08:00
|
|
|
func (s *simscreen) HasPendingEvent() bool {
|
|
|
|
return len(s.evch) > 0
|
|
|
|
}
|
|
|
|
|
2015-10-31 00:33:45 +08:00
|
|
|
func (s *simscreen) PostEventWait(ev Event) {
|
|
|
|
s.evch <- ev
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *simscreen) PostEvent(ev Event) error {
|
2015-10-06 13:53:22 +08:00
|
|
|
select {
|
|
|
|
case s.evch <- ev:
|
2015-10-31 00:33:45 +08:00
|
|
|
return nil
|
2015-10-06 13:53:22 +08:00
|
|
|
default:
|
2015-10-31 00:33:45 +08:00
|
|
|
return ErrEventQFull
|
2015-10-06 13:53:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *simscreen) InjectMouse(x, y int, buttons ButtonMask, mod ModMask) {
|
|
|
|
ev := NewEventMouse(x, y, buttons, mod)
|
|
|
|
s.PostEvent(ev)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *simscreen) InjectKey(key Key, r rune, mod ModMask) {
|
2018-04-02 23:26:45 +08:00
|
|
|
ev := NewEventKey(key, r, mod)
|
2015-10-06 13:53:22 +08:00
|
|
|
s.PostEvent(ev)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *simscreen) InjectKeyBytes(b []byte) bool {
|
|
|
|
failed := false
|
|
|
|
|
|
|
|
outer:
|
|
|
|
for len(b) > 0 {
|
|
|
|
if b[0] >= ' ' && b[0] <= 0x7F {
|
|
|
|
// printable ASCII easy to deal with -- no encodings
|
|
|
|
ev := NewEventKey(KeyRune, rune(b[0]), ModNone)
|
|
|
|
s.PostEvent(ev)
|
|
|
|
b = b[1:]
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if b[0] < 0x80 {
|
|
|
|
mod := ModNone
|
|
|
|
// No encodings start with low numbered values
|
|
|
|
if Key(b[0]) >= KeyCtrlA && Key(b[0]) <= KeyCtrlZ {
|
|
|
|
mod = ModCtrl
|
|
|
|
}
|
|
|
|
ev := NewEventKey(Key(b[0]), 0, mod)
|
|
|
|
s.PostEvent(ev)
|
2020-12-14 16:33:56 +08:00
|
|
|
b = b[1:]
|
2015-10-06 13:53:22 +08:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2015-11-05 09:05:24 +08:00
|
|
|
utfb := make([]byte, len(b)*4) // worst case
|
|
|
|
for l := 1; l < len(b); l++ {
|
|
|
|
s.decoder.Reset()
|
|
|
|
nout, nin, _ := s.decoder.Transform(utfb, b[:l], true)
|
2015-10-06 13:53:22 +08:00
|
|
|
|
2015-11-05 09:05:24 +08:00
|
|
|
if nout != 0 {
|
|
|
|
r, _ := utf8.DecodeRune(utfb[:nout])
|
|
|
|
if r != utf8.RuneError {
|
2015-10-06 13:53:22 +08:00
|
|
|
ev := NewEventKey(KeyRune, r, ModNone)
|
|
|
|
s.PostEvent(ev)
|
|
|
|
}
|
2015-11-05 09:05:24 +08:00
|
|
|
b = b[nin:]
|
|
|
|
continue outer
|
2015-10-06 13:53:22 +08:00
|
|
|
}
|
|
|
|
}
|
2015-11-05 09:05:24 +08:00
|
|
|
failed = true
|
|
|
|
b = b[1:]
|
|
|
|
continue
|
2015-10-06 13:53:22 +08:00
|
|
|
}
|
|
|
|
|
2016-12-06 07:37:37 +08:00
|
|
|
return !failed
|
2015-10-06 13:53:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *simscreen) Sync() {
|
|
|
|
s.Lock()
|
|
|
|
s.clear = true
|
|
|
|
s.resize()
|
2015-10-07 15:56:18 +08:00
|
|
|
s.back.Invalidate()
|
2015-10-06 13:53:22 +08:00
|
|
|
s.draw()
|
|
|
|
s.Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *simscreen) CharacterSet() string {
|
|
|
|
return s.charset
|
|
|
|
}
|
|
|
|
|
2015-10-31 00:33:45 +08:00
|
|
|
func (s *simscreen) SetSize(w, h int) {
|
2015-10-06 13:53:22 +08:00
|
|
|
s.Lock()
|
|
|
|
newc := make([]SimCell, w*h)
|
|
|
|
for row := 0; row < h && row < s.physh; row++ {
|
|
|
|
for col := 0; col < w && col < s.physw; col++ {
|
|
|
|
newc[(row*w)+col] = s.front[(row*s.physw)+col]
|
|
|
|
}
|
|
|
|
}
|
2017-12-24 12:20:35 +08:00
|
|
|
s.cursorx, s.cursory = -1, -1
|
|
|
|
s.physw, s.physh = w, h
|
|
|
|
s.front = newc
|
|
|
|
s.back.Resize(w, h)
|
2015-10-06 13:53:22 +08:00
|
|
|
s.Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *simscreen) GetContents() ([]SimCell, int, int) {
|
|
|
|
s.Lock()
|
|
|
|
cells, w, h := s.front, s.physw, s.physh
|
|
|
|
s.Unlock()
|
|
|
|
return cells, w, h
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *simscreen) GetCursor() (int, int, bool) {
|
|
|
|
s.Lock()
|
|
|
|
x, y, vis := s.cursorx, s.cursory, s.cursorvis
|
|
|
|
s.Unlock()
|
|
|
|
return x, y, vis
|
|
|
|
}
|
2015-10-15 10:09:00 +08:00
|
|
|
|
|
|
|
func (s *simscreen) RegisterRuneFallback(r rune, subst string) {
|
|
|
|
s.Lock()
|
|
|
|
s.fallback[r] = subst
|
|
|
|
s.Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *simscreen) UnregisterRuneFallback(r rune) {
|
|
|
|
s.Lock()
|
|
|
|
delete(s.fallback, r)
|
|
|
|
s.Unlock()
|
|
|
|
}
|
2015-10-15 10:46:35 +08:00
|
|
|
|
|
|
|
func (s *simscreen) CanDisplay(r rune, checkFallbacks bool) bool {
|
|
|
|
|
|
|
|
if enc := s.encoder; enc != nil {
|
|
|
|
nb := make([]byte, 6)
|
|
|
|
ob := make([]byte, 6)
|
|
|
|
num := utf8.EncodeRune(ob, r)
|
|
|
|
|
|
|
|
enc.Reset()
|
|
|
|
dst, _, err := enc.Transform(nb, ob[:num], true)
|
|
|
|
if dst != 0 && err == nil && nb[0] != '\x1A' {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !checkFallbacks {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if _, ok := s.fallback[r]; ok {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2015-10-31 00:33:45 +08:00
|
|
|
|
2016-01-20 07:51:33 +08:00
|
|
|
func (s *simscreen) HasMouse() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2015-10-31 00:33:45 +08:00
|
|
|
func (s *simscreen) Resize(int, int, int, int) {}
|
2016-01-20 07:51:33 +08:00
|
|
|
|
|
|
|
func (s *simscreen) HasKey(Key) bool {
|
|
|
|
return true
|
|
|
|
}
|
2019-07-23 09:49:28 +08:00
|
|
|
|
|
|
|
func (s *simscreen) Beep() error {
|
|
|
|
return nil
|
|
|
|
}
|
2021-02-21 04:36:49 +08:00
|
|
|
|
|
|
|
func (s *simscreen) Suspend() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *simscreen) Resume() error {
|
|
|
|
return nil
|
2021-06-12 10:43:12 +08:00
|
|
|
}
|