<commit_before>/* This example show a basic menu similar to that found in the ncurses
 * examples from TLDP. Errors are intentionally discarded */

package main

import . "code.google.com/p/goncurses"

const (
    HEIGHT = 10
    WIDTH = 30
)

func main() {
    var active int
    menu := []string{"Choice 1", "Choice 2", "Choice 3", "Choice 4", "Exit"}
    
    stdscr, _ := Init();
    defer End()
    
    Raw(true)
    Echo(false)
    Cursor(0)
    stdscr.Clear()
    stdscr.Keypad(true)
    
    rows, cols := stdscr.Maxyx()
    y, x := (rows-HEIGHT)/2, (cols-WIDTH)/2
    
    win, _ := NewWindow(HEIGHT, WIDTH, y, x)
    win.Keypad(true)
    
    stdscr.Print(0, 0, "Use arrow keys to go up and down, Press enter to select")
    stdscr.Refresh()
    
    printmenu(&win, menu, active)
    
    for {
        ch:= stdscr.GetChar()
        switch(KeyString(ch)) {
        case "q":
            return
        case "up":
            if active == 0 {
                active = len(menu)-1
            } else {
                active -= 1
            }
        case "down":
            if active == len(menu)-1 {
                active = 0
            } else {
                active += 1
            }
        case "enter":
            stdscr.Print(23, 0, "Choice #%d: %s selected", active, 
                menu[active])
            stdscr.ClearToEOL()
            stdscr.Refresh()
        default:
            stdscr.Print(23, 0, "Character pressed = %3d/%c", ch, ch)
            stdscr.ClearToEOL()
            stdscr.Refresh()
        }

        printmenu(&win, menu, active)
    }
}

func printmenu (w *Window, menu []string, active int) {
    y, x := 2, 2
    w.Box(0, 0)
    for i, s := range menu {
        if i == active {
            w.AttrOn(A_REVERSE)
            w.Print(y+i, x, s)
            w.AttrOff(A_REVERSE)
        } else {
            w.Print(y+i, x, s)        
        }
    }
    w.Refresh()
}<commit_msg>Go fmt menu example<commit_after>/* This example show a basic menu similar to that found in the ncurses
 * examples from TLDP. Errors are intentionally discarded */

package main

import . "code.google.com/p/goncurses"

const (
	HEIGHT = 10
	WIDTH  = 30
)

func main() {
	var active int
	menu := []string{"Choice 1", "Choice 2", "Choice 3", "Choice 4", "Exit"}

	stdscr, _ := Init()
	defer End()

	Raw(true)
	Echo(false)
	Cursor(0)
	stdscr.Clear()
	stdscr.Keypad(true)

	rows, cols := stdscr.Maxyx()
	y, x := (rows-HEIGHT)/2, (cols-WIDTH)/2

	win, _ := NewWindow(HEIGHT, WIDTH, y, x)
	win.Keypad(true)

	stdscr.Print(0, 0, "Use arrow keys to go up and down, Press enter to select")
	stdscr.Refresh()

	printmenu(&win, menu, active)

	for {
		ch := stdscr.GetChar()
		switch KeyString(ch) {
		case "q":
			return
		case "up":
			if active == 0 {
				active = len(menu) - 1
			} else {
				active -= 1
			}
		case "down":
			if active == len(menu)-1 {
				active = 0
			} else {
				active += 1
			}
		case "enter":
			stdscr.Print(23, 0, "Choice #%d: %s selected", active,
				menu[active])
			stdscr.ClearToEOL()
			stdscr.Refresh()
		default:
			stdscr.Print(23, 0, "Character pressed = %3d/%c", ch, ch)
			stdscr.ClearToEOL()
			stdscr.Refresh()
		}

		printmenu(&win, menu, active)
	}
}

func printmenu(w *Window, menu []string, active int) {
	y, x := 2, 2
	w.Box(0, 0)
	for i, s := range menu {
		if i == active {
			w.AttrOn(A_REVERSE)
			w.Print(y+i, x, s)
			w.AttrOff(A_REVERSE)
		} else {
			w.Print(y+i, x, s)
		}
	}
	w.Refresh()
}
{'fraction_non_alphanumeric': 0.1448732718894009, 'fraction_numerical': 0.01728110599078341, 'mean_word_length': 1.9658411614005125, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5186035', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1244, 'n_words': 342}