| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 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 |
|
| 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 |
} |