예제 #1
0
func main() {
	fmt.Println("starting")
	gocurses.Initscr()
	defer gocurses.End()
	gocurses.Cbreak()
	gocurses.Noecho()
	gocurses.Stdscr.Keypad(true)

	y, x := gocurses.Getmaxyx()
	gocurses.Addstr("Press any key to exit")
	gocurses.Refresh()

	window := gocurses.NewWindow(windowHeight, windowWidth, (y-windowHeight)/2, (x-windowWidth)/2)
	window.Box(0, 0)
	window.Mvaddstr(0, 1, "Sample")
	window.Refresh()

	gocurses.Getch()
}
예제 #2
0
파일: main.go 프로젝트: mpdroog/ntop
func main() {
	go Update()
	gocurses.Initscr()
	defer gocurses.End()
	gocurses.Cbreak()
	gocurses.Noecho()
	gocurses.Stdscr.Keypad(true)
	gocurses.StartColor()
	//gocurses.UseDefaultColors()
	gocurses.InitPair(1, gocurses.COLOR_WHITE, gocurses.COLOR_RED)

	go (func() {
		for range time.Tick(1 * time.Second) {
			s := stat
			//gocurses.Addstr("Press any key to exit")
			gocurses.Refresh()

			_, x := gocurses.Getmaxyx()
			// Load
			{
				window := gocurses.NewWindow(3, 24, 0, 0)
				window.Box(0, 0)
				window.Mvaddstr(1, 1, "Load "+s.Load)
				window.Refresh()
			}
			// Hostname
			{
				window := gocurses.NewWindow(3, 34, 0, 24)
				window.Box(0, 0)
				window.Mvaddstr(1, 1, "Hostname "+s.Hostname)
				window.Refresh()
			}

			// Proc stats
			{
				window := gocurses.NewWindow(11, 17, 2, 0)
				window.Box(0, 0)
				b := 0

				var keys []string
				for key, _ := range s.Procs {
					keys = append(keys, key)
				}
				sort.Strings(keys)

				for id, name := range keys {
					proc := s.Procs[name]
					window.Mvaddstr(b+id, 1, name)
					if proc.Ok {
						window.Mvaddstr(b+id, 12, "OK")
					} else {
						window.Attron(gocurses.ColorPair(1))
						window.Mvaddstr(b+id, 12, "ERR")
						window.Attroff(gocurses.ColorPair(1))
					}
				}
				window.Refresh()
			}

			// NNTPd load
			{
				window := gocurses.NewWindow(10, 20, 3, 17)
				window.Box(0, 0)
				window.Mvaddstr(1, 1, "NNTP Activity")
				window.Mvaddstr(2, 1, fmt.Sprintf("Clients: %d", s.NNTP.Clients))
				window.Mvaddstr(3, 1, fmt.Sprintf("ArtFound: %d", s.NNTP.ArticlesFound))
				window.Mvaddstr(4, 1, fmt.Sprintf("ArtMiss: %d", s.NNTP.ArticlesNotFound))

				var keys []string
				for key, _ := range s.NNTP.Queues {
					keys = append(keys, key)
				}
				sort.Strings(keys)

				for id, queue := range keys {
					avail := s.NNTP.Queues[queue]
					window.Mvaddstr(5+id, 1, fmt.Sprintf("%s: %d", queue, avail))
					id++
				}
				window.Refresh()
			}

			// Beanstalkd
			{
				window := gocurses.NewWindow(10, 20, 3, 37)
				window.Box(0, 0)
				window.Mvaddstr(1, 1, "Beanstalkd")
				window.Mvaddstr(2, 1, fmt.Sprintf("Available: %s", s.Bean.Available))
				window.Mvaddstr(3, 1, fmt.Sprintf("Buried: %s", s.Bean.Buried))
				window.Refresh()
			}

			// Galera
			{
				window := gocurses.NewWindow(10, 25, 3, 57)
				window.Box(0, 0)
				window.Mvaddstr(1, 1, "Galera")
				window.Mvaddstr(2, 1, fmt.Sprintf("Cluster size: %s", s.Galera.ClusterSize))
				window.Mvaddstr(3, 1, fmt.Sprintf("Cluster status: %s", s.Galera.ClusterStatus))
				window.Mvaddstr(4, 1, fmt.Sprintf("Node ready: %s", s.Galera.Ready))
				window.Mvaddstr(5, 1, fmt.Sprintf("Node connected: %s", s.Galera.Connected))
				window.Mvaddstr(6, 1, fmt.Sprintf("Node comment: %s", s.Galera.StateComment))
				window.Refresh()
			}

			// External
			{
				window := gocurses.NewWindow(10, 30, 3, 57)
				window.Box(0, 0)
				window.Mvaddstr(1, 1, "External APIs")
				window.Mvaddstr(2, 1, fmt.Sprintf("WeFact: %s", s.External.Wefact))
				window.Mvaddstr(3, 1, fmt.Sprintf("IcePay: %s", s.External.Icepay))
				window.Mvaddstr(4, 1, fmt.Sprintf("Bitonic: %s", s.External.Bitonic))
				window.Refresh()
			}

			// NNTP Status
			{
				window := gocurses.NewWindow(10, 35, 3, 57)
				window.Box(0, 0)
				window.Mvaddstr(1, 1, "NNTP Status")
				window.Mvaddstr(2, 1, fmt.Sprintf("Connect: %s", s.Client.TimeConn))
				window.Mvaddstr(3, 1, fmt.Sprintf("Done: %s", s.Client.TimeDone))
				window.Refresh()
			}

			// Tail
			if len(s.Errors) > 0 {
				window := gocurses.NewWindow(11, x-18, 13, 0)
				window.Box(0, 0)
				window.Mvaddstr(1, 1, fmt.Sprintf("Read errors (%d)", len(s.Errors)))
				for id, error := range s.Errors {
					window.Mvaddstr(2+id, 1, error)
					if id > 6 {
						break
					}
				}
				window.Refresh()
			} else {
				window := gocurses.NewWindow(11, x-18, 13, 0)
				window.Box(0, 0)
				window.Mvaddstr(1, 1, fmt.Sprintf("Log msgs (%d)", len(s.Logs)))
				sort.Strings(s.Logs)
				for id, log := range s.Logs {
					window.Mvaddstr(2+id, 1, log)
					if id > 6 {
						break
					}
				}
				window.Refresh()
			}
		}
	})()

	for {
		switch gocurses.Stdscr.Getch() {
		case ' ':
			// Toggle log
		case 'q':
			return
		}
	}
}