Exemplo n.º 1
0
// Run initializes the browser environment and hooks up the provided application.
func Run(app env.Application) {
	canvas := jquery.NewJQuery("canvas#output")
	window, _ := NewWebGlWindow(canvas.Get(0))

	app.Init(window)

	root := newViewModelFiller()
	app.ViewModel().Specialize(root)
	vm := ko.ViewModelFromJS(root.object)

	ko.ApplyBindings(vm)
}
Exemplo n.º 2
0
// Run initializes the environment to run the given application within.
func Run(app env.Application, deferrer <-chan func()) {
	runtime.LockOSThread()

	gui := gocui.NewGui()
	if err := gui.Init(); err != nil {
		log.Panicln(err)
	}
	defer gui.Close()

	runner := &appRunner{gui: gui, app: app}

	gui.Cursor = true
	gui.SelBgColor = gocui.ColorGreen
	gui.SelFgColor = gocui.ColorBlack
	gui.SetLayout(runner.layout)

	if err := gui.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
		log.Panicln(err)
	}
	if err := gui.SetKeybinding("mainControls", gocui.KeyArrowDown, gocui.ModNone, runner.cursorDown); err != nil {
		log.Panicln(err)
	}
	if err := gui.SetKeybinding("mainControls", gocui.KeyArrowUp, gocui.ModNone, runner.cursorUp); err != nil {
		log.Panicln(err)
	}
	if err := gui.SetKeybinding("mainControls", gocui.KeyEnter, gocui.ModNone, runner.actMainControl); err != nil {
		log.Panicln(err)
	}
	if err := gui.SetKeybinding("listDetail", gocui.KeyEnter, gocui.ModNone, runner.confirmListDetail); err != nil {
		log.Panicln(err)
	}
	if err := gui.SetKeybinding("listDetail", gocui.KeyBackspace, gocui.ModNone, runner.cancelListDetail); err != nil {
		log.Panicln(err)
	}
	if err := gui.SetKeybinding("listDetail", gocui.KeyBackspace2, gocui.ModNone, runner.cancelListDetail); err != nil {
		log.Panicln(err)
	}
	if err := gui.SetKeybinding("listDetail", gocui.KeyEsc, gocui.ModNone, runner.cancelListDetail); err != nil {
		log.Panicln(err)
	}
	if err := gui.SetKeybinding("listDetail", gocui.KeyArrowDown, gocui.ModNone, runner.cursorDown); err != nil {
		log.Panicln(err)
	}
	if err := gui.SetKeybinding("listDetail", gocui.KeyArrowUp, gocui.ModNone, runner.cursorUp); err != nil {
		log.Panicln(err)
	}
	if err := gui.SetKeybinding("stringDetail", gocui.KeyEnter, gocui.ModNone, runner.confirmStringDetail); err != nil {
		log.Panicln(err)
	}
	if err := gui.SetKeybinding("stringDetail", gocui.KeyEsc, gocui.ModNone, runner.cancelStringDetail); err != nil {
		log.Panicln(err)
	}

	var window *native.OpenGlWindow
	{
		var err error
		window, err = native.NewOpenGlWindow()
		if err != nil {
			log.Panicln(err)
		}
	}

	app.Init(window)

	{
		visitor := NewViewModelTexterVisitor(runner)
		app.ViewModel().Specialize(visitor)
		runner.rootTexter = visitor.instance
	}

	startDeferrerRoutine(gui, deferrer)

	gui.Execute(getWindowUpdater(window))
	if err := gui.MainLoop(); err != nil && err != gocui.ErrQuit {
		log.Panicln(err)
	}

	window.Close()
}