Example #1
0
// Blur removes focus from the input box.
func (i *Input) Blur() {
	i.focus = false
	i.text = i.text[:0]
	i.cursorPos = 0

	dst := tulib.TermboxBuffer()
	dst.Fill(i.rect, i.proto)
	dst.DrawLabel(i.rect, &i.promptParams, i.prompt)
	term.Flush()
}
Example #2
0
File: cli.go Project: jteeuwen/dcpu
// draw redraws the screen contents.
func (c *CLI) draw() {
	dst := tulib.TermboxBuffer()
	if len(dst.Cells) == 0 {
		return
	}

	c.traceLog.Draw(&dst)
	c.watchers.Draw(&dst)
	c.sourceLog.Draw(&dst)
	c.breakpoints.Draw(&dst)
	c.status.Draw(&dst)
	c.input.Draw(&dst)

	term.Flush()
}
Example #3
0
// blink periodically toggles the cursor blink state.
func (i *Input) blink() {
	tick := time.NewTicker((time.Second / 4) * 3)

	for {
		select {
		case <-tick.C:
			if !i.focus {
				break
			}

			i.cursorParams.Fg, i.cursorParams.Bg =
				i.cursorParams.Bg, i.cursorParams.Fg

			dst := tulib.TermboxBuffer()
			i.drawCursor(&dst)
			term.Flush()
		}
	}
}
Example #4
0
// Call it manually only when views layout has changed.
func (g *godit) resize() {
	g.uibuf = tulib.TermboxBuffer()
	views_area := g.uibuf.Rect
	views_area.Height -= 1 // reserve space for command line
	g.views.resize(views_area)
}
Example #5
0
func updateRootBuffer() {
	mutex.Lock()
	rootBuffer = tulib.TermboxBuffer()
	mutex.Unlock()
}
Example #6
0
File: cli.go Project: jteeuwen/dcpu
// Init initializes the CLI.
func (c *CLI) Init() error {
	err := term.Init()
	if err != nil {
		return err
	}

	r := tulib.TermboxBuffer().Rect
	c.resize(r.Width, r.Height)

	c.kb.Bind(func() {
		go func() {
			err := c.cpu.Run(c.cpu.Store.PC)
			if err != nil {
				c.traceLog.Append("[e] %v", err)
			}
		}()
	}, "q")

	c.kb.Bind(func() { c.cpu.Stop() }, "w")

	c.kb.Bind(func() {
		err := c.cpu.Step()
		if err != nil {
			c.sourceLog.Append("[e] %v", err)
		}
	}, "e")

	c.kb.Bind(func() {
		c.cpu.Stop()
		c.cycles = 0
		c.traceLog.Clear()
		c.sourceLog.Clear()
		c.source.Clear()

		err := Build("", c.cpu)
		if err != nil {
			c.sourceLog.Append(err.Error())
		}

		c.loadBreakpoints(arch)
	}, "r")

	c.kb.Bind(func() { c.input.Focus() }, "/")
	c.kb.Bind(func() { c.input.Blur() }, "escape")

	c.kb.Bind(func() {
		cs := c.cpu.ClockSpeed / 10
		if cs <= 0 {
			cs = 1
		}

		c.cpu.ClockSpeed = cs
	}, "=")

	c.kb.Bind(func() {
		cs := c.cpu.ClockSpeed * 10
		if cs > 1e9 {
			cs = 1e9
		}

		c.cpu.ClockSpeed = cs
	}, "-")

	c.loadBreakpoints(arch)

	go c.pollTermEvent()
	go c.pollRedraw()
	return nil
}
Example #7
0
// Call it manually only when views layout has changed.
func (e *Editor) Resize() {
	e.uiBuf = tulib.TermboxBuffer()
	viewsArea := e.uiBuf.Rect
	viewsArea.Height -= 1 // reserve space for command line
	e.views.Resize(viewsArea)
}