2023-08-15 09:27:44 +08:00
|
|
|
//go:build ignore
|
2020-08-26 07:20:58 +08:00
|
|
|
// +build ignore
|
|
|
|
|
2019-03-19 14:41:32 +08:00
|
|
|
// Copyright 2019 The TCell Authors
|
2015-10-05 10:53:38 +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.
|
|
|
|
|
|
|
|
// unicode just displays a Unicode test on your screen.
|
|
|
|
// Press ESC to exit the program.
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
2020-08-26 07:20:58 +08:00
|
|
|
"github.com/gdamore/tcell/v2"
|
|
|
|
"github.com/gdamore/tcell/v2/encoding"
|
2019-03-19 14:41:32 +08:00
|
|
|
runewidth "github.com/mattn/go-runewidth"
|
2015-10-05 10:53:38 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
var row = 0
|
|
|
|
var style = tcell.StyleDefault
|
|
|
|
|
2015-11-05 09:29:11 +08:00
|
|
|
func putln(s tcell.Screen, str string) {
|
2015-10-05 10:53:38 +08:00
|
|
|
|
2015-11-05 09:29:11 +08:00
|
|
|
puts(s, style, 1, row, str)
|
2015-10-05 10:53:38 +08:00
|
|
|
row++
|
|
|
|
}
|
|
|
|
|
2015-11-05 09:29:11 +08:00
|
|
|
func puts(s tcell.Screen, style tcell.Style, x, y int, str string) {
|
2015-10-05 10:53:38 +08:00
|
|
|
i := 0
|
|
|
|
var deferred []rune
|
|
|
|
dwidth := 0
|
2018-09-06 06:42:39 +08:00
|
|
|
zwj := false
|
2015-10-05 10:53:38 +08:00
|
|
|
for _, r := range str {
|
2018-09-06 06:42:39 +08:00
|
|
|
if r == '\u200d' {
|
|
|
|
if len(deferred) == 0 {
|
|
|
|
deferred = append(deferred, ' ')
|
|
|
|
dwidth = 1
|
|
|
|
}
|
|
|
|
deferred = append(deferred, r)
|
|
|
|
zwj = true
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if zwj {
|
|
|
|
deferred = append(deferred, r)
|
|
|
|
zwj = false
|
|
|
|
continue
|
|
|
|
}
|
2015-10-05 10:53:38 +08:00
|
|
|
switch runewidth.RuneWidth(r) {
|
|
|
|
case 0:
|
|
|
|
if len(deferred) == 0 {
|
|
|
|
deferred = append(deferred, ' ')
|
|
|
|
dwidth = 1
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
if len(deferred) != 0 {
|
2015-10-07 15:56:18 +08:00
|
|
|
s.SetContent(x+i, y, deferred[0], deferred[1:], style)
|
2015-10-05 10:53:38 +08:00
|
|
|
i += dwidth
|
|
|
|
}
|
2015-10-07 15:56:18 +08:00
|
|
|
deferred = nil
|
2015-10-05 10:53:38 +08:00
|
|
|
dwidth = 1
|
|
|
|
case 2:
|
|
|
|
if len(deferred) != 0 {
|
2015-10-07 15:56:18 +08:00
|
|
|
s.SetContent(x+i, y, deferred[0], deferred[1:], style)
|
2015-10-05 10:53:38 +08:00
|
|
|
i += dwidth
|
|
|
|
}
|
2015-10-07 15:56:18 +08:00
|
|
|
deferred = nil
|
2015-10-05 10:53:38 +08:00
|
|
|
dwidth = 2
|
|
|
|
}
|
|
|
|
deferred = append(deferred, r)
|
|
|
|
}
|
|
|
|
if len(deferred) != 0 {
|
2015-10-07 15:56:18 +08:00
|
|
|
s.SetContent(x+i, y, deferred[0], deferred[1:], style)
|
2015-10-05 10:53:38 +08:00
|
|
|
i += dwidth
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2015-10-05 14:22:57 +08:00
|
|
|
|
2015-10-05 10:53:38 +08:00
|
|
|
s, e := tcell.NewScreen()
|
|
|
|
if e != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "%v\n", e)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2015-10-05 14:22:57 +08:00
|
|
|
|
|
|
|
encoding.Register()
|
|
|
|
|
2015-10-05 10:53:38 +08:00
|
|
|
if e = s.Init(); e != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "%v\n", e)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
plain := tcell.StyleDefault
|
|
|
|
bold := style.Bold(true)
|
|
|
|
|
|
|
|
s.SetStyle(tcell.StyleDefault.
|
|
|
|
Foreground(tcell.ColorBlack).
|
|
|
|
Background(tcell.ColorWhite))
|
|
|
|
s.Clear()
|
|
|
|
|
|
|
|
quit := make(chan struct{})
|
|
|
|
|
|
|
|
style = bold
|
2015-11-05 09:29:11 +08:00
|
|
|
putln(s, "Press ESC to Exit")
|
|
|
|
putln(s, "Character set: "+s.CharacterSet())
|
2015-10-05 10:53:38 +08:00
|
|
|
style = plain
|
|
|
|
|
2015-11-05 09:29:11 +08:00
|
|
|
putln(s, "English: October")
|
|
|
|
putln(s, "Icelandic: október")
|
|
|
|
putln(s, "Arabic: أكتوبر")
|
|
|
|
putln(s, "Russian: октября")
|
|
|
|
putln(s, "Greek: Οκτωβρίου")
|
|
|
|
putln(s, "Chinese: 十月 (note, two double wide characters)")
|
|
|
|
putln(s, "Combining: A\u030a (should look like Angstrom)")
|
|
|
|
putln(s, "Emoticon: \U0001f618 (blowing a kiss)")
|
|
|
|
putln(s, "Airplane: \u2708 (fly away)")
|
|
|
|
putln(s, "Command: \u2318 (mac clover key)")
|
|
|
|
putln(s, "Enclose: !\u20e3 (should be enclosed exclamation)")
|
2018-09-06 06:42:39 +08:00
|
|
|
putln(s, "ZWJ: \U0001f9db\u200d\u2640 (female vampire)")
|
|
|
|
putln(s, "ZWJ: \U0001f9db\u200d\u2642 (male vampire)")
|
|
|
|
putln(s, "Family: \U0001f469\u200d\U0001f467\u200d\U0001f467 (woman girl girl)\n")
|
2019-03-19 14:41:32 +08:00
|
|
|
putln(s, "Region: \U0001f1fa\U0001f1f8 (USA! USA!)\n")
|
2015-11-05 09:29:11 +08:00
|
|
|
putln(s, "")
|
|
|
|
putln(s, "Box:")
|
|
|
|
putln(s, string([]rune{
|
2015-10-05 10:53:38 +08:00
|
|
|
tcell.RuneULCorner,
|
|
|
|
tcell.RuneHLine,
|
|
|
|
tcell.RuneTTee,
|
|
|
|
tcell.RuneHLine,
|
|
|
|
tcell.RuneURCorner,
|
|
|
|
}))
|
2015-11-05 09:29:11 +08:00
|
|
|
putln(s, string([]rune{
|
2015-10-05 10:53:38 +08:00
|
|
|
tcell.RuneVLine,
|
|
|
|
tcell.RuneBullet,
|
|
|
|
tcell.RuneVLine,
|
|
|
|
tcell.RuneLantern,
|
|
|
|
tcell.RuneVLine,
|
2015-10-05 16:27:55 +08:00
|
|
|
})+" (bullet, lantern/section)")
|
2015-11-05 09:29:11 +08:00
|
|
|
putln(s, string([]rune{
|
2015-10-05 10:53:38 +08:00
|
|
|
tcell.RuneLTee,
|
|
|
|
tcell.RuneHLine,
|
|
|
|
tcell.RunePlus,
|
|
|
|
tcell.RuneHLine,
|
|
|
|
tcell.RuneRTee,
|
|
|
|
}))
|
2015-11-05 09:29:11 +08:00
|
|
|
putln(s, string([]rune{
|
2015-10-05 10:53:38 +08:00
|
|
|
tcell.RuneVLine,
|
|
|
|
tcell.RuneDiamond,
|
|
|
|
tcell.RuneVLine,
|
|
|
|
tcell.RuneUArrow,
|
|
|
|
tcell.RuneVLine,
|
2015-10-05 16:27:55 +08:00
|
|
|
})+" (diamond, up arrow)")
|
2015-11-05 09:29:11 +08:00
|
|
|
putln(s, string([]rune{
|
2015-10-05 10:53:38 +08:00
|
|
|
tcell.RuneLLCorner,
|
|
|
|
tcell.RuneHLine,
|
|
|
|
tcell.RuneBTee,
|
|
|
|
tcell.RuneHLine,
|
|
|
|
tcell.RuneLRCorner,
|
|
|
|
}))
|
|
|
|
|
|
|
|
s.Show()
|
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
ev := s.PollEvent()
|
|
|
|
switch ev := ev.(type) {
|
|
|
|
case *tcell.EventKey:
|
|
|
|
switch ev.Key() {
|
|
|
|
case tcell.KeyEscape, tcell.KeyEnter:
|
|
|
|
close(quit)
|
|
|
|
return
|
|
|
|
case tcell.KeyCtrlL:
|
|
|
|
s.Sync()
|
|
|
|
}
|
|
|
|
case *tcell.EventResize:
|
|
|
|
s.Sync()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
<-quit
|
|
|
|
|
|
|
|
s.Fini()
|
|
|
|
}
|