Esempio n. 1
0
//DispatchKeys interface method
func (U *Ultra) DispatchKeys(t *sdl.KeyDownEvent) int {
	app := U.App
	T := app.Widget
	fmt.Printf("[%d ms] Keyboard\ttype:%d\tname:%s\tmodifiers:%d\tstate:%d\trepeat:%d\tsym: %c\n",
		t.Timestamp, t.Type, sdl.GetScancodeName(t.Keysym.Scancode), t.Keysym.Mod, t.State, t.Repeat, t.Keysym.Sym)
	key := sdl.GetScancodeName(t.Keysym.Scancode)
	if t.Keysym.Sym == sdl.K_ESCAPE || t.Keysym.Sym == sdl.K_CAPSLOCK {
		return 0
	}
	if (key == "A" && t.Keysym.Mod == 64) || key == "Home" {
		T.MoveCursor(T.Cursor.Row, 0)
		return 1
	}
	if (key == "U" && t.Keysym.Mod == 64) || key == "End" {
		T.MoveCursor(T.Cursor.Row, len(T.Content[T.Cursor.Row].Content))
		return 1
	}
	if (key == "H" && t.Keysym.Mod == 64) || key == "Backspace" {
		T.SetRules(0, []HighlightRule{HighlightRule{0, -1, "foreground", "default"}})
		T.removeString(1)
		U.update()
		return 1
	}
	if key == "Delete" {
		T.SetRules(0, []HighlightRule{HighlightRule{0, -1, "foreground", "default"}})
		T.removeStringForward(1)
		U.update()
		return 1
	}
	if key == "C" && t.Keysym.Mod == 64 {
		line := T.Content[0]
		T.MoveCursor(0, 0)
		line.Content = ""
		T.ChangeLine(0, line)
		T.SetRules(0, []HighlightRule{HighlightRule{0, -1, "foreground", "default"}})
		return 1
	}
	if key == "V" && t.Keysym.Mod == 64 {
		s, _ := sdl.GetClipboardText()
		T.SetRules(0, []HighlightRule{HighlightRule{0, -1, "foreground", "default"}})
		T.addString(s)
		U.update()
		return 1
	}
	if key == "W" && t.Keysym.Mod == 64 {
		T.SetRules(0, []HighlightRule{HighlightRule{0, -1, "foreground", "default"}})
		T.removeWord()
		U.update()
		return 1
	}
	if key == "Left" {
		T.MoveCursorLeft()
		// U.update()
		return 1
	}
	if key == "Right" {
		T.MoveCursorRight()
		// U.update()
		return 1
	}
	if key == "Down" || (key == "N" && t.Keysym.Mod == 64) {
		U.next()
		return 1
	}
	if key == "Up" || (key == "P" && t.Keysym.Mod == 64) {
		U.prev()
		return 1
	}
	if key == "Tab" {
		U.autocomplete()
		return 1
	}
	if (key == "J" && t.Keysym.Mod == 64) || t.Keysym.Sym == sdl.K_RETURN {
		ret := U.execInput(T.Content[0].Content)
		if ret != 0 {
			T.SetRules(0, []HighlightRule{HighlightRule{0, -1, "red", "default"}})
			T.drawCursor()
		}
		return ret
	}
	if isASCII(string(t.Keysym.Sym)) && t.Keysym.Mod <= 1 {
		T.SetRules(0, []HighlightRule{HighlightRule{0, -1, "foreground", "default"}})
		char := string(t.Keysym.Sym)
		if t.Keysym.Mod == 1 {
			char = strings.ToUpper(char)
			sub, ok := symbols[char]
			if ok {
				char = sub
			}
		}
		T.addString(char)
		U.update()
		return 1
	}
	return 1
}
Esempio n. 2
0
// GetClipboardText returns a string of the clipboard text. It may return an error
// if unable to get the contents.
func GetClipboardText() (string, error) {
	return sdl.GetClipboardText()
}