示例#1
0
文件: tui.go 项目: Foxboron/gopics
func (win Interface) createTempWindow(text string, writeable bool, h int, w int) *gc.Panel {
	// gc.Raw(false)
	// gc.Echo(true)
	// gc.Cursor(1)
	_, cols := win.files.Window().MaxYX()

	input, _ := gc.NewWindow(11, cols, 19, 0)
	input.Box(0, 0)
	panel := gc.NewPanel(input)
	panel.Top()
	if len(text) > 0 {
		input.MovePrint(1, 1, text)
	}
	if writeable {
		gc.Raw(false)
		gc.Echo(true)
		gc.Cursor(1)
		_, err := input.GetString(10)
		if err != nil {
			println("Input error")
		}
		setDefaultOptions()
		input.Refresh()
		input.Erase()
		panel.Hide()
		input.Refresh()
		win.Refresh()
	} else {
		input.Refresh()
		panel.Window().ScrollOk(true)
		win.tmp = panel
	}

	return win.tmp
}
示例#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()
		}
	}
}
示例#3
0
文件: tui.go 项目: Foxboron/gopics
func createPictureView(stdscr *gc.Window) *gc.Window {

	rows, cols := stdscr.MaxYX()
	pic_view, _ := gc.NewWindow(rows, cols/2, 0, cols/2)
	pic_view.Box(0, 0)
	// pic_view.MovePrintf(y+1, x+1, "TEST")
	gc.NewPanel(pic_view)

	y, _ := stdscr.MaxYX()
	stdscr.MovePrint(y-2, 1, "'q' to exit")
	stdscr.Refresh()
	pic_view.Refresh()
	return pic_view

}
示例#4
0
func main() {
	stdscr, _ := gc.Init()
	defer gc.End()

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

	for i := 0; i < 3; i++ {
		window, _ := gc.NewWindow(10, 40, y+i, x+(i*5))
		window.Box(0, 0)
		panels[i] = gc.NewPanel(window)
	}

	gc.UpdatePanels()
	gc.Update()

	stdscr.GetChar()
}
示例#5
0
文件: tui.go 项目: Foxboron/gopics
func createFileList(stdscr *gc.Window) *gc.Menu {

	// build the menu items
	menu_items := getFiles()
	items := make([]*gc.MenuItem, len(menu_items))
	i := 0
	for key, val := range menu_items {
		items[i], _ = gc.NewItem(key, val)
		// defer items[i].Free()
		i++
	}
	menu, _ := gc.NewMenu(items)
	defer menu.Free()
	rows, cols := stdscr.MaxYX()

	// menuwin, _ := gc.NewWindow(rows, cols/2, 3, 1)
	menuwin, _ := gc.NewWindow(rows, cols/2, 0, 0)
	menuwin.Keypad(true)

	menu.SetWindow(menuwin)
	dwin := menuwin.Derived(29, 50, 3, 1)
	menu.SubWindow(dwin)
	menu.Option(gc.O_SHOWDESC, true)
	menu.Mark(" * ")
	menu.Option(gc.O_ONEVALUE, false)

	// Print centered menu title
	_, x := menuwin.MaxYX()
	title := "My Menu"
	menuwin.Box(0, 0)
	menuwin.ColorOn(1)
	menuwin.MovePrint(1, (x/2)-(len(title)/2), title)
	menuwin.ColorOff(1)
	menuwin.MoveAddChar(2, 0, gc.ACS_LTEE)
	menuwin.HLine(2, 1, gc.ACS_HLINE, x-3)
	menuwin.MoveAddChar(2, x-2, gc.ACS_RTEE)

	gc.NewPanel(menuwin)

	menu.Post()
	//defer menu.UnPost()
	menu.Window().Refresh()
	return menu
}
示例#6
0
文件: tui.go 项目: Foxboron/gopics
func (w Interface) getInput(msg string) string {
	input, _ := gc.NewWindow(3, 30, 20, 10)
	input.Box(0, 0)
	input.MovePrint(1, 1, msg)
	panel := gc.NewPanel(input)
	panel.Top()

	gc.Raw(false)
	gc.Echo(true)
	gc.Cursor(1)
	str, err := input.GetString(10)
	if err != nil {
		println("Input error")
	}

	panel.Delete()
	setDefaultOptions()
	return str
}