2017-12-30 21:10:13 +00:00
|
|
|
/*
|
2019-12-30 23:12:17 +00:00
|
|
|
A presentation of the cview package, implemented with cview.
|
2018-01-03 20:13:32 +00:00
|
|
|
|
2017-12-30 21:10:13 +00:00
|
|
|
Navigation
|
|
|
|
|
2018-01-03 20:13:32 +00:00
|
|
|
The presentation will advance to the next slide when the primitive demonstrated
|
|
|
|
in the current slide is left (usually by hitting Enter or Escape). Additionally,
|
|
|
|
the following shortcuts can be used:
|
|
|
|
|
2017-12-30 21:10:13 +00:00
|
|
|
- Ctrl-N: Jump to next slide
|
|
|
|
- Ctrl-P: Jump to previous slide
|
|
|
|
*/
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-03-25 14:32:57 +00:00
|
|
|
"flag"
|
2017-12-30 21:10:13 +00:00
|
|
|
"fmt"
|
2020-03-25 14:32:57 +00:00
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
_ "net/http/pprof"
|
2017-12-30 21:10:13 +00:00
|
|
|
"strconv"
|
|
|
|
|
2021-04-03 15:11:20 +00:00
|
|
|
"code.rocketnine.space/tslocum/cview"
|
2020-08-30 15:36:03 +00:00
|
|
|
"github.com/gdamore/tcell/v2"
|
2017-12-30 21:10:13 +00:00
|
|
|
)
|
|
|
|
|
2021-06-05 03:35:34 +00:00
|
|
|
const (
|
|
|
|
appInfo = "Next slide: Ctrl-N Previous: Ctrl-P Exit: Ctrl-C (Navigate with your keyboard or mouse)"
|
|
|
|
listInfo = "Next item: J, Down Previous item: K, Up Open context menu: Alt+Enter"
|
|
|
|
textViewInfo = "Scroll down: J, Down, PageDown Scroll up: K, Up, PageUp"
|
|
|
|
sliderInfo = "Decrease: H, J, Left, Down Increase: K, L, Right, Up"
|
|
|
|
formInfo = "Next field: Tab Previous field: Shift+Tab Select: Enter"
|
|
|
|
windowInfo = "Windows may be dragged an resized using the mouse."
|
|
|
|
)
|
|
|
|
|
|
|
|
// Slide is a function which returns the slide's title, any applicable
|
|
|
|
// information and its main primitive, its. It receives a "nextSlide" function
|
|
|
|
// which can be called to advance the presentation to the next slide.
|
|
|
|
type Slide func(nextSlide func()) (title string, info string, content cview.Primitive)
|
2017-12-30 21:10:13 +00:00
|
|
|
|
|
|
|
// The application.
|
2019-12-30 23:12:17 +00:00
|
|
|
var app = cview.NewApplication()
|
2017-12-30 21:10:13 +00:00
|
|
|
|
|
|
|
// Starting point for the presentation.
|
|
|
|
func main() {
|
2020-03-25 14:32:57 +00:00
|
|
|
var debugPort int
|
|
|
|
flag.IntVar(&debugPort, "debug", 0, "port to serve debug info")
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if debugPort > 0 {
|
|
|
|
go func() {
|
2020-05-08 23:12:48 +00:00
|
|
|
log.Fatal(http.ListenAndServe(fmt.Sprintf("localhost:%d", debugPort), nil))
|
2020-03-25 14:32:57 +00:00
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2020-10-07 23:34:21 +00:00
|
|
|
app.EnableMouse(true)
|
|
|
|
|
2017-12-30 21:10:13 +00:00
|
|
|
// The presentation slides.
|
|
|
|
slides := []Slide{
|
|
|
|
Cover,
|
|
|
|
Introduction,
|
2020-04-03 15:01:21 +00:00
|
|
|
Colors,
|
2017-12-30 21:10:13 +00:00
|
|
|
TextView1,
|
|
|
|
TextView2,
|
2020-04-03 15:01:21 +00:00
|
|
|
InputField,
|
2020-10-11 20:39:04 +00:00
|
|
|
Slider,
|
2020-04-03 15:01:21 +00:00
|
|
|
Form,
|
2017-12-30 21:10:13 +00:00
|
|
|
Table,
|
2018-06-20 08:06:05 +00:00
|
|
|
TreeView,
|
2017-12-30 21:10:13 +00:00
|
|
|
Flex,
|
2018-02-20 10:30:57 +00:00
|
|
|
Grid,
|
2020-09-24 15:09:55 +00:00
|
|
|
Window,
|
2017-12-30 21:10:13 +00:00
|
|
|
End,
|
|
|
|
}
|
|
|
|
|
2020-10-16 01:50:10 +00:00
|
|
|
panels := cview.NewTabbedPanels()
|
2017-12-30 21:10:13 +00:00
|
|
|
|
|
|
|
// Create the pages for all slides.
|
|
|
|
previousSlide := func() {
|
2020-10-16 01:50:10 +00:00
|
|
|
slide, _ := strconv.Atoi(panels.GetCurrentTab())
|
2020-03-29 19:43:46 +00:00
|
|
|
slide = (slide - 1 + len(slides)) % len(slides)
|
2020-10-16 01:50:10 +00:00
|
|
|
panels.SetCurrentTab(strconv.Itoa(slide))
|
2017-12-30 21:10:13 +00:00
|
|
|
}
|
|
|
|
nextSlide := func() {
|
2020-10-16 01:50:10 +00:00
|
|
|
slide, _ := strconv.Atoi(panels.GetCurrentTab())
|
2020-03-29 19:43:46 +00:00
|
|
|
slide = (slide + 1) % len(slides)
|
2020-10-16 01:50:10 +00:00
|
|
|
panels.SetCurrentTab(strconv.Itoa(slide))
|
2017-12-30 21:10:13 +00:00
|
|
|
}
|
2020-01-04 02:46:23 +00:00
|
|
|
|
|
|
|
cursor := 0
|
|
|
|
var slideRegions []int
|
2017-12-30 21:10:13 +00:00
|
|
|
for index, slide := range slides {
|
2020-01-04 02:46:23 +00:00
|
|
|
slideRegions = append(slideRegions, cursor)
|
|
|
|
|
2021-06-05 03:35:34 +00:00
|
|
|
title, info, primitive := slide(nextSlide)
|
|
|
|
|
|
|
|
h := cview.NewTextView()
|
|
|
|
if info != "" {
|
|
|
|
h.SetDynamicColors(true)
|
|
|
|
h.SetText(" [" + cview.ColorHex(cview.Styles.SecondaryTextColor) + "]Info:[-] " + info)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a Flex layout that centers the logo and subtitle.
|
|
|
|
f := cview.NewFlex()
|
|
|
|
f.SetDirection(cview.FlexRow)
|
|
|
|
f.AddItem(h, 1, 1, false)
|
|
|
|
f.AddItem(primitive, 0, 1, true)
|
|
|
|
|
|
|
|
panels.AddTab(strconv.Itoa(index), title, f)
|
2020-01-04 02:46:23 +00:00
|
|
|
|
|
|
|
cursor += len(title) + 4
|
2017-12-30 21:10:13 +00:00
|
|
|
}
|
2020-10-16 01:50:10 +00:00
|
|
|
panels.SetCurrentTab("0")
|
2017-12-30 21:10:13 +00:00
|
|
|
|
|
|
|
// Shortcuts to navigate the slides.
|
2018-01-14 20:29:34 +00:00
|
|
|
app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
|
|
|
|
if event.Key() == tcell.KeyCtrlN {
|
|
|
|
nextSlide()
|
|
|
|
} else if event.Key() == tcell.KeyCtrlP {
|
|
|
|
previousSlide()
|
|
|
|
}
|
|
|
|
return event
|
2017-12-30 21:10:13 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
// Start the application.
|
2020-10-16 01:50:10 +00:00
|
|
|
app.SetRoot(panels, true)
|
2020-10-07 23:34:21 +00:00
|
|
|
if err := app.Run(); err != nil {
|
2017-12-30 21:10:13 +00:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|