Пример #1
0
func main() {

	var err error

	err = termutil.Init(time.Second)
	if err != nil {
		log.Fatal(err)
	}

	termutil.Screen.EventFunc = func(ev termbox.Event) {
		switch ev.Type {
		case termbox.EventKey:
			switch ev.Key {
			case termbox.KeyEsc:
				termutil.Quit()
			}
		}
	}

	win := termutil.NewWindow()

	win.UpdateFunc = func() []termutil.Row {
		return termutil.StringsToRows([]string{"hello"}, termbox.ColorCyan, termbox.ColorMagenta)
	}

	err = termutil.Run()
	termutil.End()

	if err != nil {
		log.Fatal(err)
		return
	}
}
Пример #2
0
func main() {

	var err error

	err = termutil.Init(time.Second)
	if err != nil {
		log.Fatal(err)
	}

	termutil.Screen.EventFunc = func(ev termbox.Event) {
		switch ev.Type {
		case termbox.EventKey:
			switch ev.Key {
			case termbox.KeyEsc:
				termutil.Quit()
			}
		}
	}

	head := termutil.NewWindow()
	head.SizeY = 1
	head.UpdateFunc = func() []termutil.Row {
		return termutil.StringsToRows([]string{
			fmt.Sprintf("WidgetTable: %v", time.Now().Format("02/01/2006 15:04:05"))}, 0, 0)
	}

	win := termutil.NewWindow()
	win.Y = 1

	wg := &termutil.WidgetTable{
		Header: &termutil.Header{
			Titles: []termutil.HeaderTitle{
				{"name", 20},
				{"id", 10},
				{"hobby", 0},
				{"height", 10},
			},
			Fg:       termbox.ColorBlack,
			Bg:       termbox.ColorGreen,
			FgActive: termbox.ColorBlack,
			BgActive: termbox.ColorBlue,
		},
		Body: &termutil.Body{
			Active:   0,
			FgActive: termbox.ColorDefault,
			BgActive: termbox.AttrReverse,
		},
	}
	win.UpdateFunc = func() []termutil.Row {
		wg.Body.Data = bodys[time.Now().Nanosecond()%3]
		return wg.Update(win)
	}
	win.EventFunc = wg.EventFunc

	err = termutil.Run()
	termutil.End()

	if err != nil {
		log.Fatal(err)
		return
	}
}