Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
termui_list_do_not_render.go
// Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
// Use of this source code is governed by a MIT license that can
// be found in the LICENSE file.
// +build ignore
package main
import (
"log"
ui "github.com/gizak/termui"
"github.com/gizak/termui/widgets"
)
func main() {
if err := ui.Init(); err != nil {
log.Fatalf("failed to initialize termui: %v", err)
}
defer ui.Close()
l := widgets.NewList()
l.Title = "List"
l.Rows = []string{
"[0] github.com/gizak/termui",
"[1] [你好,世界](fg:blue)",
"[2] [こんにちは世界](fg:red)",
"[3] [color](fg:white,bg:green) output",
"[4] output.go",
"[4] output.go",
"[4] output.go",
"[4] output.go",
"[5] random_out.go",
"[6] dashboard.go",
"[7] foo",
"[8] bar",
"[9] baz",
"[5] random_out.go",
"[6] dashboard.go",
"[7] foo",
"[8] bar",
"[9] baz",
"[5] random_out.go",
"[6] dashboard.go",
"[7] foo",
"[8] bar",
"[9] baz",
"[5] random_out.go",
"[6] dashboard.go",
"[7] foo",
"[8] bar",
"[9] baz",
"[4] output.go",
"[5] random_out.go",
"[6] dashboard.go",
"[7] foo",
"[8] bar",
"[9] baz",
}
l.TextStyle = ui.NewStyle(ui.ColorYellow)
l.WrapText = false
l.SetRect(0, 0, 25, 8)
ui.Render(l)
k := widgets.NewList()
k.Title = "List"
k.Rows = []string{
"[0] github.com/gizak/termui",
"[1] [你好,世界](fg:blue)",
"[2] [こんにちは世界](fg:red)",
"[3] [color](fg:white,bg:green) output",
"[4] output.go",
"[5] random_out.go",
"[6] dashboard.go",
"[7] foo",
"[8] bar",
"[9] baz",
"[4] output.go",
"[4] output.go",
"[4] output.go",
"[4] output.go",
"[5] random_out.go",
"[6] dashboard.go",
"[7] foo",
"[8] bar",
"[9] baz",
"[5] random_out.go",
"[6] dashboard.go",
"[7] foo",
"[8] bar",
"[9] baz",
"[5] random_out.go",
"[6] dashboard.go",
"[7] foo",
"[8] bar",
"[9] baz",
"[5] random_out.go",
"[6] dashboard.go",
"[7] foo",
"[8] bar",
"[9] baz",
}
k.TextStyle = ui.NewStyle(ui.ColorYellow)
k.WrapText = false
k.SetRect(10, 0, 25, 8)
ui.Render(k)
grid := ui.NewGrid()
grid.Set(
ui.NewCol(0.2/2,
ui.NewRow(1.0/2, l),
ui.NewRow(1.0/2, k),
),
)
termWidth, termHeight := ui.TerminalDimensions()
grid.SetRect(0, 0, termWidth, termHeight)
ui.Render(grid)
previousKey := ""
uiEvents := ui.PollEvents()
for {
e := <-uiEvents
switch e.ID {
case "q", "<C-c>":
return
case "<Down>":
l.ScrollDown()
case "<Up>":
l.ScrollUp()
case "j":
k.ScrollDown()
case "k":
k.ScrollUp()
case "<C-d>":
l.HalfPageDown()
case "<C-u>":
l.HalfPageUp()
case "<C-f>":
l.PageDown()
case "<C-b>":
l.PageUp()
case "g":
if previousKey == "g" {
l.ScrollTop()
}
case "<Home>":
l.ScrollTop()
case "G", "<End>":
l.ScrollBottom()
}
if previousKey == "g" {
previousKey = ""
} else {
previousKey = e.ID
}
ui.Render(l, k)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment