示例#1
0
func (d *EditController) Handle(ev terminal.Event) error {
	switch ev.Key {
	case terminal.KeyEnter:
		log.Println("enter pressed")
		d.cursor.Newline()
		d.fullView.Render(d.atts, d.grid)
		d.onRender <- grid.CopyGrid(d.grid)
	case terminal.KeyEsc:
		d.exitEditor <- true
	case terminal.KeyDelete:
		log.Println("terminal.KeyDelete")
		x, y, c := d.handleKey(ev, ev.Key)
		d.grid.Set(x, y, c)
		d.fullView.Render(d.atts, d.grid)
		d.onRender <- grid.CopyGrid(d.grid)
	default:
		x, y, c := d.handleKey(ev, ev.Key)
		d.grid.Set(x, y, c)
		d.fullView.Render(d.atts, d.grid)
		d.onRender <- grid.CopyGrid(d.grid)
	}

	return nil
}
示例#2
0
func NewEditController(
	atts *view.ViewAtts,
	writer chan io.WriterTo,
	exitEditor chan bool) *EditController {

	cursor := NewCursor(0, 0)
	ec := &EditController{
		atts:       atts,
		onRender:   writer,
		exitEditor: exitEditor,
		escapes:    terminal.NewEscapes(),
		grid:       grid.NewGrid(atts.Dims()),
		fullView:   view.NewFullView("*scratch*", cursor),
		cursor:     cursor,
	}

	ec.fullView.Render(atts, ec.grid)
	writer <- grid.CopyGrid(ec.grid)

	return ec
}