Esempio n. 1
0
func (ch *commandHandler) RunTextCommand(view *View, name string, args Args) error {
	lvl := log.FINE
	p := Prof.Enter("tc")
	defer p.Exit()
	t := time.Now()
	if ch.log {
		lvl = log.DEBUG
	}
	log.Logf(lvl, "Running text command: %s %v", name, args)
	if c, ok := ch.TextCommands[name].(TextCommand); c != nil && ok {
		if err := ch.init(c, args); err != nil && ch.verbose {
			log.Debug("Command initialization failed: %s", err)
			return err
		} else if err := view.runCommand(c, name); err != nil {
			log.Logf(lvl, "Command execution failed: %s", err)
			return err
		}
	} else if w := view.Window(); w != nil {
		if c, ok := ch.WindowCommands[name].(WindowCommand); c != nil && ok {
			if err := w.runCommand(c, name); err != nil {
				log.Logf(lvl, "Command execution failed: %s", err)
				return err
			}
		}
	}
	log.Logf(lvl, "Ran text command: %s %s", name, time.Since(t))
	return nil
}
Esempio n. 2
0
func (ch *commandHandler) RunWindowCommand(wnd *Window, name string, args Args) error {
	lvl := log.FINE
	p := Prof.Enter("wc")
	defer p.Exit()
	if ch.log {
		lvl = log.DEBUG
	}
	log.Logf(lvl, "Running window command: %s %v", name, args)
	t := time.Now()
	if c, ok := ch.WindowCommands[name].(WindowCommand); c != nil && ok {
		if err := ch.init(c, args); err != nil && ch.verbose {
			log.Debug("Command initialization failed: %s", err)
			return err
		} else if err := wnd.runCommand(c, name); err != nil {
			log.Logf(lvl+1, "Command execution failed: %s", err)
			return err
		} else {
			log.Logf(lvl, "Ran Window command: %s %s", name, time.Since(t))
		}
	} else {
		log.Logf(lvl, "No such window command: %s", name)
	}
	return nil
}
Esempio n. 3
0
func (e *Editor) inputthread() {
	pc := 0
	var lastBindings keys.KeyBindings
	doinput := func(kp keys.KeyPress) {
		defer func() {
			if r := recover(); r != nil {
				log.Error("Panic in inputthread: %v\n%s", r, string(debug.Stack()))
				if pc > 0 {
					panic(r)
				}
				pc++
			}
		}()
		p := Prof.Enter("hi")
		defer p.Exit()

		lvl := log.FINE
		if e.logInput {
			lvl++
		}
		log.Logf(lvl, "Key: %v", kp)
		if lastBindings.SeqIndex() == 0 {
			lastBindings = *e.KeyBindings()
		}
	try_again:
		possible_actions := lastBindings.Filter(kp)
		lastBindings = possible_actions

		// TODO?
		var (
			wnd *Window
			v   *View
		)
		if wnd = e.ActiveWindow(); wnd != nil {
			v = wnd.ActiveView()
		}

		qc := func(key string, operator Op, operand interface{}, match_all bool) bool {
			return OnQueryContext.Call(v, key, operator, operand, match_all) == True
		}

		if action := possible_actions.Action(qc); action != nil {
			p2 := Prof.Enter("hi.perform")
			e.RunCommand(action.Command, action.Args)
			p2.Exit()
		} else if possible_actions.SeqIndex() > 1 {
			// TODO: this disables having keyBindings with more than 2 key sequence
			lastBindings = *e.KeyBindings()
			goto try_again
		} else if kp.IsCharacter() {
			p2 := Prof.Enter("hi.character")
			log.Finest("[editor.inputthread] kp: |%s|, pos: %v", kp.Text, possible_actions)
			if err := e.CommandHandler().RunTextCommand(v, "insert", Args{"characters": kp.Text}); err != nil {
				log.Debug("Couldn't run textcommand: %s", err)
			}
			p2.Exit()
		}
	}
	for kp := range e.keyInput {
		doinput(kp)
	}
}