Debian Codegraph @

demos/presentation/textview.go

raw symbols SCIP
1 package mainscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview/demos/presentation`/
2
3 import (
4 "fmtscip-go gomod github.com/golang/go/src go1.18 fmt/"
5 "strconvscip-go gomod github.com/golang/go/src go1.18 strconv/"
6 "timescip-go gomod github.com/golang/go/src go1.18 time/"
7
8 "github.com/gdamore/tcell/v2scip-go gomod github.com/gdamore/tcell/v2 v2.7.4 `github.com/gdamore/tcell/v2`/"
9 "github.com/darkhz/tviewscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/"
10 )
11
12 const textView1scip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview/demos/presentation`/textView1. = `[green]func[white] [yellow]main[white]() {
13 app := tview.[yellow]NewApplication[white]()
14 textView := tview.[yellow]NewTextView[white]().
15 [yellow]SetTextColor[white](tcell.ColorYellow).
16 [yellow]SetScrollable[white](false).
17 [yellow]SetChangedFunc[white]([yellow]func[white]() {
18 app.[yellow]Draw[white]()
19 })
20 [green]go[white] [yellow]func[white]() {
21 [green]var[white] n [green]int
22 [white] [yellow]for[white] {
23 n++
24 fmt.[yellow]Fprintf[white](textView, [red]"%d "[white], n)
25 time.[yellow]Sleep[white]([red]200[white] * time.Millisecond)
26 }
27 }()
28 app.[yellow]SetRoot[white](textView, true).
29 [yellow]Run[white]()
30 }`
31
32 // TextView1 demonstrates the basic text view.
33 func TextView1scip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview/demos/presentation`/TextView1().(nextSlide func()) (title string, content tviewscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/.Primitivescip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Primitive#) {
34 textView := tviewscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/.NewTextViewscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/NewTextView().().
35 SetTextColorscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/TextView#SetTextColor().(tcellscip-go gomod github.com/gdamore/tcell/v2 v2.7.4 `github.com/gdamore/tcell/v2`/.ColorYellowscip-go gomod github.com/gdamore/tcell/v2 v2.7.4 `github.com/gdamore/tcell/v2`/ColorYellow.).
36 SetScrollablescip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/TextView#SetScrollable().(false).
37 SetDoneFuncscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/TextView#SetDoneFunc().(func(key tcellscip-go gomod github.com/gdamore/tcell/v2 v2.7.4 `github.com/gdamore/tcell/v2`/.Keyscip-go gomod github.com/gdamore/tcell/v2 v2.7.4 `github.com/gdamore/tcell/v2`/Key#) {
38 nextSlide()
39 })
40 textView.SetChangedFuncscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/TextView#SetChangedFunc().(func() {
41 if textView.HasFocusscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/TextView#HasFocus().() {
42 appscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview/demos/presentation`/app..Drawscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Application#Draw().()
43 }
44 })
45 go func() {
46 var n int
47 for {
48 if textView.HasFocusscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/TextView#HasFocus().() {
49 n++
50 if n > 512 {
51 n = 1
52 textView.SetTextscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/TextView#SetText().("")
53 }
54
55 fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.18 fmt/Fprintf().(textView, "%d ", n)
56 timescip-go gomod github.com/golang/go/src go1.18 time/.Sleepscip-go gomod github.com/golang/go/src go1.18 time/Sleep().(200 * timescip-go gomod github.com/golang/go/src go1.18 time/.Millisecondscip-go gomod github.com/golang/go/src go1.18 time/Millisecond.)
57 } else {
58 timescip-go gomod github.com/golang/go/src go1.18 time/.Sleepscip-go gomod github.com/golang/go/src go1.18 time/Sleep().(timescip-go gomod github.com/golang/go/src go1.18 time/.Secondscip-go gomod github.com/golang/go/src go1.18 time/Second.)
59 }
60 }
61 }()
62 textView.SetBorderscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Box#SetBorder().(true).SetTitlescip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Box#SetTitle().("TextView implements io.Writer")
63 return "Text 1", Codescip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview/demos/presentation`/Code().(textView, 36, 13, textView1scip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview/demos/presentation`/textView1.)
64 }
65
66 const textView2scip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview/demos/presentation`/textView2. = `[green]package[white] main
67
68 [green]import[white] (
69 [red]"strconv"[white]
70
71 [red]"github.com/gdamore/tcell/v2"[white]
72 [red]"github.com/darkhz/tview"[white]
73 )
74
75 [green]func[white] [yellow]main[white]() {
76 ["0"]textView[""] := tview.[yellow]NewTextView[white]()
77 ["1"]textView[""].[yellow]SetDynamicColors[white](true).
78 [yellow]SetWrap[white](false).
79 [yellow]SetRegions[white](true).
80 [yellow]SetDoneFunc[white]([yellow]func[white](key tcell.Key) {
81 highlights := ["2"]textView[""].[yellow]GetHighlights[white]()
82 hasHighlights := [yellow]len[white](highlights) > [red]0
83 [yellow]switch[white] key {
84 [yellow]case[white] tcell.KeyEnter:
85 [yellow]if[white] hasHighlights {
86 ["3"]textView[""].[yellow]Highlight[white]()
87 } [yellow]else[white] {
88 ["4"]textView[""].[yellow]Highlight[white]([red]"0"[white]).
89 [yellow]ScrollToHighlight[white]()
90 }
91 [yellow]case[white] tcell.KeyTab:
92 [yellow]if[white] hasHighlights {
93 current, _ := strconv.[yellow]Atoi[white](highlights[[red]0[white]])
94 next := (current + [red]1[white]) % [red]9
95 ["5"]textView[""].[yellow]Highlight[white](strconv.[yellow]Itoa[white](next)).
96 [yellow]ScrollToHighlight[white]()
97 }
98 [yellow]case[white] tcell.KeyBacktab:
99 [yellow]if[white] hasHighlights {
100 current, _ := strconv.[yellow]Atoi[white](highlights[[red]0[white]])
101 next := (current - [red]1[white] + [red]9[white]) % [red]9
102 ["6"]textView[""].[yellow]Highlight[white](strconv.[yellow]Itoa[white](next)).
103 [yellow]ScrollToHighlight[white]()
104 }
105 }
106 })
107 fmt.[yellow]Fprint[white](["7"]textView[""], content)
108 tview.[yellow]NewApplication[white]().
109 [yellow]SetRoot[white](["8"]textView[""], true).
110 [yellow]Run[white]()
111 }`
112
113 // TextView2 demonstrates the extended text view.
114 func TextView2scip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview/demos/presentation`/TextView2().(nextSlide func()) (title string, content tviewscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/.Primitivescip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Primitive#) {
115 codeView := tviewscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/.NewTextViewscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/NewTextView().().
116 SetWrapscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/TextView#SetWrap().(false)
117 fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Fprintscip-go gomod github.com/golang/go/src go1.18 fmt/Fprint().(codeView, textView2scip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview/demos/presentation`/textView2.)
118 codeView.SetBorderscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Box#SetBorder().(true).SetTitlescip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Box#SetTitle().("Raw text")
119
120 textView := tviewscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/.NewTextViewscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/NewTextView().()
121 textView.SetDynamicColorsscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/TextView#SetDynamicColors().(true).
122 SetWrapscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/TextView#SetWrap().(false).
123 SetRegionsscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/TextView#SetRegions().(true).
124 SetDoneFuncscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/TextView#SetDoneFunc().(func(key tcellscip-go gomod github.com/gdamore/tcell/v2 v2.7.4 `github.com/gdamore/tcell/v2`/.Keyscip-go gomod github.com/gdamore/tcell/v2 v2.7.4 `github.com/gdamore/tcell/v2`/Key#) {
125 if key == tcellscip-go gomod github.com/gdamore/tcell/v2 v2.7.4 `github.com/gdamore/tcell/v2`/.KeyEscapescip-go gomod github.com/gdamore/tcell/v2 v2.7.4 `github.com/gdamore/tcell/v2`/KeyEscape. {
126 nextSlide()
127 return
128 }
129 highlights := textView.GetHighlightsscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/TextView#GetHighlights().()
130 hasHighlights := len(highlights) > 0
131 switch key {
132 case tcellscip-go gomod github.com/gdamore/tcell/v2 v2.7.4 `github.com/gdamore/tcell/v2`/.KeyEnterscip-go gomod github.com/gdamore/tcell/v2 v2.7.4 `github.com/gdamore/tcell/v2`/KeyEnter.:
133 if hasHighlights {
134 textView.Highlightscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/TextView#Highlight().()
135 } else {
136 textView.Highlightscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/TextView#Highlight().("0").
137 ScrollToHighlightscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/TextView#ScrollToHighlight().()
138 }
139 case tcellscip-go gomod github.com/gdamore/tcell/v2 v2.7.4 `github.com/gdamore/tcell/v2`/.KeyTabscip-go gomod github.com/gdamore/tcell/v2 v2.7.4 `github.com/gdamore/tcell/v2`/KeyTab.:
140 if hasHighlights {
141 current, _ := strconvscip-go gomod github.com/golang/go/src go1.18 strconv/.Atoiscip-go gomod github.com/golang/go/src go1.18 strconv/Atoi().(highlights[0])
142 next := (current + 1) % 9
143 textView.Highlightscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/TextView#Highlight().(strconvscip-go gomod github.com/golang/go/src go1.18 strconv/.Itoascip-go gomod github.com/golang/go/src go1.18 strconv/Itoa().(next)).
144 ScrollToHighlightscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/TextView#ScrollToHighlight().()
145 }
146 case tcellscip-go gomod github.com/gdamore/tcell/v2 v2.7.4 `github.com/gdamore/tcell/v2`/.KeyBacktabscip-go gomod github.com/gdamore/tcell/v2 v2.7.4 `github.com/gdamore/tcell/v2`/KeyBacktab.:
147 if hasHighlights {
148 current, _ := strconvscip-go gomod github.com/golang/go/src go1.18 strconv/.Atoiscip-go gomod github.com/golang/go/src go1.18 strconv/Atoi().(highlights[0])
149 next := (current - 1 + 9) % 9
150 textView.Highlightscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/TextView#Highlight().(strconvscip-go gomod github.com/golang/go/src go1.18 strconv/.Itoascip-go gomod github.com/golang/go/src go1.18 strconv/Itoa().(next)).
151 ScrollToHighlightscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/TextView#ScrollToHighlight().()
152 }
153 }
154 })
155 fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Fprintscip-go gomod github.com/golang/go/src go1.18 fmt/Fprint().(textView, textView2scip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview/demos/presentation`/textView2.)
156 textView.SetBorderscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Box#SetBorder().(true).SetTitlescip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Box#SetTitle().("TextView output")
157 return "Text 2", tviewscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/.NewFlexscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/NewFlex().().
158 AddItemscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Flex#AddItem().(textView, 0, 1, true).
159 AddItemscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Flex#AddItem().(codeView, 0, 1, false)
160 }