Example #1
0
func (ch *commandHandler) RunTextCommand(view *View, name string, args Args) error {
	lvl := log4go.FINE
	p := Prof.Enter("tc")
	defer p.Exit()
	t := time.Now()
	if ch.log {
		lvl = log4go.DEBUG
	}
	log4go.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 {
			log4go.Debug("Command initialization failed: %s", err)
			return err
		} else if err := view.runCommand(c, name); err != nil {
			log4go.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 {
				log4go.Logf(lvl, "Command execution failed: %s", err)
				return err
			}
		}
	}
	log4go.Logf(lvl, "Ran text command: %s %s", name, time.Since(t))
	return nil
}
Example #2
0
func (e *Editor) inputthread() {
	pc := 0
	var lastBindings KeyBindings
	doinput := func(kp KeyPress) {
		defer func() {
			if r := recover(); r != nil {
				log4go.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 := log4go.FINE
		if e.loginput {
			lvl++
		}
		log4go.Logf(lvl, "Key: %v", kp)
		if lastBindings.keyOff == 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()
		}

		if action := possible_actions.Action(v); action != nil {
			p2 := Prof.Enter("hi.perform")
			e.RunCommand(action.Command, action.Args)
			p2.Exit()
		} else if possible_actions.keyOff > 1 {
			lastBindings = e.keyBindings
			goto try_again
		} else if kp.IsCharacter() {
			p2 := Prof.Enter("hi.character")
			log4go.Finest("kp: %v, pos: %v", kp, possible_actions)
			if err := e.CommandHandler().RunTextCommand(v, "insert", Args{"characters": string(rune(kp.Key))}); err != nil {
				log4go.Debug("Couldn't run textcommand: %s", err)
			}
			p2.Exit()
		}
	}
	for kp := range e.keyInput {
		doinput(kp)
	}
}
Example #3
0
func (ch *commandHandler) RunWindowCommand(wnd *Window, name string, args Args) error {
	lvl := log4go.FINE
	p := Prof.Enter("wc")
	defer p.Exit()
	if ch.log {
		lvl = log4go.DEBUG
	}
	log4go.Logf(lvl, "Running window command: %s %v", name, args)
	t := time.Now()
	if c := ch.WindowCommands[name]; c != nil {
		if err := wnd.runCommand(c, name, args); err != nil {
			log4go.Logf(lvl+1, "Command execution failed: %s", err)
		} else {
			log4go.Logf(lvl, "Ran Window command: %s %s", name, time.Since(t))
		}
	} else {
		log4go.Logf(lvl, "No such window command: %s", name)
	}
	return nil
}