Debian Codegraph @

demos/unicode/unicode.go

raw symbols SCIP
1 // Copyright 2026 The TCell Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this 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 // unicode just displays a Unicode test on your screen.
16 // Press ESC to exit the program.
17 package main
18
19 import (
20 "fmt"
21 "os"
22
23 "github.com/gdamore/tcell/v3"
24 "github.com/gdamore/tcell/v3/color"
25 "github.com/gdamore/tcell/v3/encoding"
26 )
27
28 var row = 0
29 var style = tcell.StyleDefault
30
31 func putln(s tcell.Screen, str string) {
32
33 s.PutStrStyled(1, row, str, style)
34 row++
35 }
36
37 func main() {
38
39 s, e := tcell.NewScreen()
40 if e != nil {
41 fmt.Fprintf(os.Stderr, "%v\n", e)
42 os.Exit(1)
43 }
44
45 encoding.Register()
46
47 if e = s.Init(); e != nil {
48 fmt.Fprintf(os.Stderr, "%v\n", e)
49 os.Exit(1)
50 }
51
52 plain := tcell.StyleDefault
53 bold := style.Bold(true)
54
55 s.SetStyle(tcell.StyleDefault.
56 Foreground(color.Black).
57 Background(color.White))
58 s.Clear()
59
60 // we can even try to use unicode window titles!
61 s.SetTitle("Unicode Demonstration -- 🀯")
62
63 quit := make(chan struct{})
64
65 style = bold
66 putln(s, "Press Control-Q to Exit")
67 putln(s, "Character set: "+s.CharacterSet())
68 style = plain
69
70 putln(s, "English: October")
71 putln(s, "Icelandic: oktΓ³ber")
72 putln(s, "Arabic: Ψ£ΩƒΨͺوبر")
73 putln(s, "Russian: октября")
74 putln(s, "Greek: ΞŸΞΊΟ„Ο‰Ξ²ΟΞ―ΞΏΟ…")
75 putln(s, "Chinese: 十月 (note, two double wide characters)")
76 putln(s, "Combining: A\u030a (should look like Angstrom)")
77 putln(s, "Emoticon: \U0001f618 (blowing a kiss)")
78 putln(s, "Airplane: \u2708 (fly away)")
79 putln(s, "Command: \u2318 (mac clover key)")
80 putln(s, "Enclose: !\u20e3 (should be enclosed exclamation)")
81 putln(s, "ZWJ: \U0001f9db\u200d\u2640 (female vampire)")
82 putln(s, "ZWJ: \U0001f9db\u200d\u2642 (male vampire)")
83 putln(s, "Family: \U0001f469\u200d\U0001f467\u200d\U0001f467 (woman girl girl)\n")
84 putln(s, "Region: \U0001f1fa\U0001f1f8 (USA! USA!)\n")
85 putln(s, "")
86 putln(s, "Box:")
87 putln(s, "β”Œβ”€β”¬β”€β”¬β”€β”€β”")
88 putln(s, "β”‚Β·β”‚Β§β”‚ζœˆβ”‚ (bullet, lantern, CJK)")
89 putln(s, "β”œβ”€β”Όβ”€β”Όβ”€β”€β”€")
90 putln(s, "β”‚Aβ”‚1β”‚πŸ˜˜β”‚ (A, 1, Kiss)")
91 putln(s, "β”œβ”€β”Όβ”€β”Όβ”€β”€β”€")
92 putln(s, "β”‚Β·β”‚Ξ©β”‚πŸ‡¨πŸ‡­β”‚ (bullet, omega, Swiss)")
93 putln(s, "β”œβ”€β”Όβ”€β”Όβ”€β”€β”€")
94 putln(s, "│◆│↑│>=β”‚ (diamond, up arrow, greater-or-equal)")
95 putln(s, "β””β”€β”΄β”€β”΄β”€β”€β”˜")
96
97 s.Show()
98 go func() {
99 for {
100 ev := <-s.EventQ()
101 switch ev := ev.(type) {
102 case *tcell.EventKey:
103 switch ev.Key() {
104 case tcell.KeyEscape, tcell.KeyEnter, tcell.KeyCtrlQ:
105 close(quit)
106 return
107 case tcell.KeyCtrlL:
108 s.Sync()
109 }
110 case *tcell.EventResize:
111 s.Sync()
112 }
113 }
114 }()
115
116 <-quit
117
118 s.Fini()
119 }