Exemplo n.º 1
0
func (s *Session) Draw() {
	s.View.SetRef(s.CursorL, 0, 0, s.Ypivot)
	surf := s.View.Render()

	// draw cursor
	x, y := view.RenderPos(surf, s.CursorL, s.CursorC)
	termbox.SetCursor(x, y)

	// draw content
	view.Draw(surf, 0, 0)
}
Exemplo n.º 2
0
func (m *ModeSearch) HandleKey(s *Session, ev termbox.Event) (Mode, error) {
	if m.s == nil {
		m.s = s
		m.b = util.NewBuffer([]byte{})
		m.view = &view.Wrap{}
		m.view.SetBuf(m.b)
		m.view.SetSize(s.W-1, 1)
		m.view.SetTabwidth(1)
	}

	var err error
	if ev.Ch != 0 {
		m.b.Insert(m.pos, ev.Ch)
		m.pos++
	}
	switch ev.Key {
	case termbox.KeyEnter:
		s.Search, err = regexp.Compile(string(m.b.Bytes()))
		if err != nil {
			msg := err.Error()
			for i, ch := range msg {
				termbox.SetCell(i, s.H, ch, 0, 0)
			}
			return &ModeEdit{}, nil
		}
		s.UpdSearch()
		s.NextMatch()
		return &ModeEdit{}, nil
	case termbox.KeySpace:
		m.b.Insert(m.pos, ' ')
		m.pos++
	case termbox.KeyBackspace, termbox.KeyBackspace2:
		m.b.Delete(m.pos, -1)
		m.pos--
	case termbox.KeyEsc:
		return &ModeEdit{}, nil
	}

	surf := m.view.Render()
	termbox.SetCell(0, s.H, '/', 0, 0)
	view.Draw(surf, 1, s.H)
	return m, nil
}