Exemple #1
0
func main() {
	stdscr, _ := gc.Init()
	defer gc.End()

	gc.Echo(false)
	gc.CBreak(true)
	gc.StartColor()
	stdscr.Keypad(true)

	gc.InitPair(1, gc.C_WHITE, gc.C_BLUE)
	gc.InitPair(2, gc.C_YELLOW, gc.C_BLUE)

	fields := make([]*gc.Field, 2)
	fields[0], _ = gc.NewField(1, 10, 4, 18, 0, 0)
	defer fields[0].Free()
	fields[0].SetForeground(gc.ColorPair(1))
	fields[0].SetBackground(gc.ColorPair(2) | gc.A_UNDERLINE | gc.A_BOLD)
	fields[0].SetOptionsOff(gc.FO_AUTOSKIP)

	fields[1], _ = gc.NewField(1, 10, 6, 18, 0, 0)
	defer fields[1].Free()
	fields[1].SetForeground(gc.ColorPair(1))
	fields[1].SetBackground(gc.A_UNDERLINE)
	fields[1].SetOptionsOff(gc.FO_AUTOSKIP)
	fields[1].SetPad('*')

	form, _ := gc.NewForm(fields)
	form.Post()
	defer form.UnPost()
	defer form.Free()
	stdscr.Refresh()

	stdscr.AttrOn(gc.ColorPair(2) | gc.A_BOLD)
	stdscr.MovePrint(4, 10, "Value 1:")
	stdscr.AttrOff(gc.ColorPair(2) | gc.A_BOLD)
	stdscr.MovePrint(6, 10, "Value 2:")
	stdscr.Refresh()

	ch := stdscr.GetChar()
	for ch != 'q' {
		switch ch {
		case gc.KEY_DOWN:
			form.Driver(gc.REQ_NEXT_FIELD)
			form.Driver(gc.REQ_END_LINE)
		case gc.KEY_UP:
			form.Driver(gc.REQ_PREV_FIELD)
			form.Driver(gc.REQ_END_LINE)
		default:
			form.Driver(ch)
		}
		ch = stdscr.GetChar()
	}
}
Exemple #2
0
func main() {
	stdscr, _ := gc.Init()
	defer gc.End()

	gc.StartColor()
	gc.CBreak(true)
	gc.Echo(true)
	stdscr.Keypad(true)
	stdscr.Print("Hit 'tab' to cycle through windows, 'q' to quit")

	gc.InitPair(1, gc.C_RED, gc.C_BLACK)
	gc.InitPair(2, gc.C_GREEN, gc.C_BLACK)
	gc.InitPair(3, gc.C_BLUE, gc.C_BLACK)
	gc.InitPair(4, gc.C_CYAN, gc.C_BLACK)

	var panels [3]*gc.Panel
	y, x := 4, 10

	for i := 0; i < 3; i++ {
		h, w := 10, 40
		title := "Window Number %d"

		window, _ := gc.NewWindow(h, w, y+(i*4), x+(i*10))
		window.Box(0, 0)
		window.MoveAddChar(2, 0, gc.ACS_LTEE)
		window.HLine(2, 1, gc.ACS_HLINE, w-2)
		window.MoveAddChar(2, w-1, gc.ACS_RTEE)
		window.ColorOn(int16(i + 1))
		window.MovePrintf(1, (w/2)-(len(title)/2), title, i+1)
		window.ColorOff(int16(i + 1))
		panels[i] = gc.NewPanel(window)

	}

	active := 2

	for {
		gc.UpdatePanels()
		gc.Update()

		switch stdscr.GetChar() {
		case 'q':
			return
		case gc.KEY_TAB:
			active += 1
			if active > 2 {
				active = 0
			}
			panels[active].Top()
		}
	}
}
Exemple #3
0
func main() {
	filename := os.Args[len(os.Args)-1]
	filepath := findFile(filename)
	bs, _ := ioutil.ReadFile(filepath)
	s := string(bs[:])

	scr, err := goncurses.Init()
	if err != nil {

	}
	defer terminateWindow()
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, syscall.SIGTERM)
	go func() {
		<-c
		terminateWindow()
		os.Exit(1)
	}()

	goncurses.CBreak(true)
	scr.ScrollOk(true)
	scr.Keypad(true)
	goncurses.Echo(false)
	goncurses.NewLines(true)

	y, x := scr.MaxYX()
	scr.Resize(y-1, x)

	status_win, err := goncurses.NewWindow(1, x, y-1, 0)
	if err != nil {
	}
	status_win.ClearOk(true)
	status_win.Printf("\"%s\" [New File]", filename)
	status_win.Refresh()
	renderInitialWindow(scr)

	scr.GetChar()
	status_win.Erase()
	status_win.Move(0, 0)
	status_win.AttrOn(goncurses.A_BOLD)
	status_win.Print("--INSERT--")
	status_win.Refresh()
	scr.Move(0, 0)
	scr.Refresh()

	chars := strings.Split(s, "")
	i := 0
	for true {
		ch := scr.GetChar()
		rune, _ := utf8.DecodeRuneInString(chars[i])
		if rune == '\n' {
			if ch == '\n' {
				scr.Print("\n")
				scr.DelChar()
				for true {
					i++
					if i >= len(chars) {
						break
					}
					r, _ := utf8.DecodeRuneInString(chars[i])
					if r == '\t' || r == ' ' {
						scr.Printf("%c", r)
					} else {
						break
					}
				}
			}
		} else {
			scr.Printf("%c", rune)
			i++
		}

		if i >= len(chars) {
			break
		}
	}
	scr.GetChar()
	status_win.Erase()
	status_win.Refresh()
	scr.Refresh()
	scr.GetChar()
	scr.GetChar()

	ioutil.WriteFile(filename, []byte(s), 0644)
}
Exemple #4
0
func main() {
	stdscr, err := gc.Init()
	if err != nil {
		log.Fatal(err)
	}
	defer gc.End()

	// Turn off character echo, hide the cursor and disable input buffering
	gc.Echo(false)
	gc.CBreak(true)
	gc.Cursor(0)

	stdscr.Print("Use arrow keys to move the window. Press 'q' to exit")
	stdscr.NoutRefresh()

	// Determine the center of the screen and offset those coordinates by
	// half of the window size we are about to create. These coordinates will
	// be used to move our window around the screen
	rows, cols := stdscr.MaxYX()
	height, width := 5, 10
	y, x := (rows-height)/2, (cols-width)/2

	// Create a new window centered on the screen and enable the use of the
	// keypad on it so the arrow keys are available
	var win *gc.Window
	win, err = gc.NewWindow(height, width, y, x)
	if err != nil {
		log.Fatal(err)
	}
	win.Keypad(true)

main:
	for {
		// Clear the section of screen where the box is currently located so
		// that it is blanked by calling Erase on the window and refreshing it
		// so that the chances are sent to the virtual screen but not actually
		// output to the terminal
		win.Erase()
		win.NoutRefresh()
		// Move the window to it's new location (if any) and redraw it
		win.MoveWindow(y, x)
		win.Box(0, 0)
		win.NoutRefresh()
		// Update will flush only the characters which have changed between the
		// physical screen and the virtual screen, minimizing the number of
		// characters which must be sent
		gc.Update()

		// In order for the window to display correctly, we must call GetChar()
		// on it rather than stdscr
		switch win.GetChar() {
		case 'q':
			break main
		case gc.KEY_LEFT:
			if x > 0 {
				x--
			}
		case gc.KEY_RIGHT:
			if x < cols-width {
				x++
			}
		case gc.KEY_UP:
			if y > 1 {
				y--
			}
		case gc.KEY_DOWN:
			if y < rows-height {
				y++
			}
		}
	}
	win.Delete()
}
Exemple #5
0
func terminateWindow() {
	log.Println("TERMINATE")
	goncurses.CBreak(false)
	goncurses.NewLines(false)
	goncurses.End()
}