2017-01-14 06:07:43 +00:00
|
|
|
// Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
|
2015-03-20 20:21:50 +00:00
|
|
|
// Use of this source code is governed by a MIT license that can
|
|
|
|
// be found in the LICENSE file.
|
|
|
|
|
|
|
|
// +build ignore
|
|
|
|
|
2015-03-13 17:20:17 +00:00
|
|
|
package main
|
|
|
|
|
2019-01-24 04:12:10 +00:00
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
2019-03-07 10:50:20 +00:00
|
|
|
ui "github.com/gizak/termui/v3"
|
|
|
|
"github.com/gizak/termui/v3/widgets"
|
2019-01-24 04:12:10 +00:00
|
|
|
)
|
2015-03-13 17:20:17 +00:00
|
|
|
|
|
|
|
func main() {
|
2019-01-24 04:12:10 +00:00
|
|
|
if err := ui.Init(); err != nil {
|
|
|
|
log.Fatalf("failed to initialize termui: %v", err)
|
2018-09-07 01:22:04 +00:00
|
|
|
}
|
2018-09-06 21:48:09 +00:00
|
|
|
defer ui.Close()
|
2015-03-13 17:20:17 +00:00
|
|
|
|
2019-01-24 04:12:10 +00:00
|
|
|
l := widgets.NewList()
|
|
|
|
l.Title = "List"
|
|
|
|
l.Rows = []string{
|
2019-03-07 10:50:20 +00:00
|
|
|
"[0] github.com/gizak/termui/v3",
|
2019-01-24 04:12:10 +00:00
|
|
|
"[1] [你好,世界](fg:blue)",
|
|
|
|
"[2] [こんにちは世界](fg:red)",
|
2019-01-24 05:44:00 +00:00
|
|
|
"[3] [color](fg:white,bg:green) output",
|
2015-03-13 17:20:17 +00:00
|
|
|
"[4] output.go",
|
|
|
|
"[5] random_out.go",
|
|
|
|
"[6] dashboard.go",
|
2019-02-02 05:05:03 +00:00
|
|
|
"[7] foo",
|
|
|
|
"[8] bar",
|
|
|
|
"[9] baz",
|
2019-01-24 04:12:10 +00:00
|
|
|
}
|
|
|
|
l.TextStyle = ui.NewStyle(ui.ColorYellow)
|
2019-01-27 06:32:08 +00:00
|
|
|
l.WrapText = false
|
2019-02-02 05:05:03 +00:00
|
|
|
l.SetRect(0, 0, 25, 8)
|
2015-03-13 17:20:17 +00:00
|
|
|
|
2019-01-24 04:12:10 +00:00
|
|
|
ui.Render(l)
|
2018-09-06 21:48:09 +00:00
|
|
|
|
2019-02-02 05:05:03 +00:00
|
|
|
previousKey := ""
|
2018-11-29 23:32:42 +00:00
|
|
|
uiEvents := ui.PollEvents()
|
2018-11-29 02:19:34 +00:00
|
|
|
for {
|
2018-11-29 23:32:42 +00:00
|
|
|
e := <-uiEvents
|
2018-11-29 02:19:34 +00:00
|
|
|
switch e.ID {
|
|
|
|
case "q", "<C-c>":
|
|
|
|
return
|
2019-01-27 06:32:08 +00:00
|
|
|
case "j", "<Down>":
|
|
|
|
l.ScrollDown()
|
|
|
|
case "k", "<Up>":
|
|
|
|
l.ScrollUp()
|
2019-02-02 05:05:03 +00:00
|
|
|
case "<C-d>":
|
2019-03-01 22:00:31 +00:00
|
|
|
l.ScrollHalfPageDown()
|
2019-02-02 05:05:03 +00:00
|
|
|
case "<C-u>":
|
2019-03-01 22:00:31 +00:00
|
|
|
l.ScrollHalfPageUp()
|
2019-02-01 03:14:37 +00:00
|
|
|
case "<C-f>":
|
2019-03-01 22:00:31 +00:00
|
|
|
l.ScrollPageDown()
|
2019-02-01 03:14:37 +00:00
|
|
|
case "<C-b>":
|
2019-03-01 22:00:31 +00:00
|
|
|
l.ScrollPageUp()
|
2019-02-02 05:05:03 +00:00
|
|
|
case "g":
|
|
|
|
if previousKey == "g" {
|
|
|
|
l.ScrollTop()
|
|
|
|
}
|
|
|
|
case "<Home>":
|
|
|
|
l.ScrollTop()
|
|
|
|
case "G", "<End>":
|
|
|
|
l.ScrollBottom()
|
2018-11-29 02:19:34 +00:00
|
|
|
}
|
2019-02-02 05:05:03 +00:00
|
|
|
|
|
|
|
if previousKey == "g" {
|
|
|
|
previousKey = ""
|
|
|
|
} else {
|
|
|
|
previousKey = e.ID
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.Render(l)
|
2018-11-29 02:19:34 +00:00
|
|
|
}
|
2015-03-13 17:20:17 +00:00
|
|
|
}
|