Debian Codegraph @

demos/styles/styles.go

raw symbols SCIP
1 // Copyright 2025 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 // styles just displays some sample output styles.
16 // Press CTRL-Q 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 )
26
27 var row = 0
28 var style = tcell.StyleDefault
29
30 func main() {
31
32 s, e := tcell.NewScreen()
33 if e != nil {
34 fmt.Fprintf(os.Stderr, "%v\n", e)
35 os.Exit(1)
36 }
37
38 if e = s.Init(); e != nil {
39 fmt.Fprintf(os.Stderr, "%v\n", e)
40 os.Exit(1)
41 }
42 defer s.Fini()
43
44 plain := tcell.StyleDefault
45 bold := style.Bold(true)
46
47 s.SetStyle(tcell.StyleDefault.
48 Foreground(color.Black).
49 Background(color.White))
50 s.Clear()
51
52 quit := make(chan struct{})
53
54 style = bold.Foreground(color.Blue).Background(color.Silver)
55
56 row = 2
57 s.PutStrStyled(2, row, "Press ESC to Exit", style)
58 row = 4
59 s.PutStrStyled(2, row, "Note: Style support is dependent on your terminal.", plain)
60 row = 6
61
62 plain = tcell.StyleDefault.Foreground(color.Black).Background(color.White)
63
64 style = plain
65 s.PutStrStyled(2, row, "Plain", style)
66 row++
67
68 style = plain.Blink(true)
69 s.PutStrStyled(2, row, "Blink", style)
70 row++
71
72 style = plain.Reverse(true)
73 s.PutStrStyled(2, row, "Reverse", style)
74 row++
75
76 style = plain.Dim(true)
77 s.PutStrStyled(2, row, "Dim", style)
78 row++
79
80 style = plain.Underline(true)
81 s.PutStrStyled(2, row, "Underline", style)
82 row++
83
84 style = plain.Italic(true)
85 s.PutStrStyled(2, row, "Italic", style)
86 row++
87
88 style = plain.Bold(true)
89 s.PutStrStyled(2, row, "Bold", style)
90 row++
91
92 style = plain.Bold(true).Italic(true)
93 s.PutStrStyled(2, row, "Bold Italic", style)
94 row++
95
96 style = plain.Bold(true).Italic(true).Underline(true)
97 s.PutStrStyled(2, row, "Bold Italic Underline", style)
98 row++
99
100 style = plain.StrikeThrough(true)
101 s.PutStrStyled(2, row, "StrikeThrough", style)
102 row++
103
104 style = plain.Underline(tcell.UnderlineStyleDouble)
105 s.PutStrStyled(2, row, "Double Underline", style)
106 row++
107
108 style = plain.Underline(tcell.UnderlineStyleCurly)
109 s.PutStrStyled(2, row, "Curly Underline", style)
110 row++
111
112 style = plain.Underline(tcell.UnderlineStyleDotted)
113 s.PutStrStyled(2, row, "Dotted Underline", style)
114 row++
115
116 style = plain.Underline(tcell.UnderlineStyleDashed)
117 s.PutStrStyled(2, row, "Dashed Underline", style)
118 row++
119
120 style = plain.Underline(true, color.Blue)
121 s.PutStrStyled(2, row, "Blue Underline", style)
122 row++
123
124 style = plain.Underline(tcell.UnderlineStyleSolid, color.FireBrick)
125 s.PutStrStyled(2, row, "Firebrick Underline", style)
126 row++
127
128 style = plain.Underline(tcell.UnderlineStyleCurly, color.NewRGBColor(0xc5, 0x8a, 0xf9))
129 s.PutStrStyled(2, row, "Pink Curly Underline", style)
130 row++
131
132 style = plain.Url("http://github.com/gdamore/tcell")
133 s.PutStrStyled(2, row, "HyperLink", style)
134 row++
135
136 style = plain.Foreground(color.Red)
137 s.PutStrStyled(2, row, "Red Foreground", style)
138 row++
139
140 style = plain.Background(color.Red)
141 s.PutStrStyled(2, row, "Red Background", style)
142 row++
143
144 s.Show()
145 go func() {
146 for {
147 ev := <-s.EventQ()
148 switch ev := ev.(type) {
149 case *tcell.EventKey:
150 switch ev.Key() {
151 case tcell.KeyEscape, tcell.KeyEnter, tcell.KeyCtrlQ:
152 close(quit)
153 return
154 case tcell.KeyCtrlL:
155 s.Sync()
156 }
157 case *tcell.EventResize:
158 s.Sync()
159 }
160 }
161 }()
162
163 <-quit
164 }