当前位置: 首页>>代码示例>>Golang>>正文


Golang KeyPress.Key方法代码示例

本文整理汇总了Golang中lime/backend.KeyPress.Key方法的典型用法代码示例。如果您正苦于以下问题:Golang KeyPress.Key方法的具体用法?Golang KeyPress.Key怎么用?Golang KeyPress.Key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lime/backend.KeyPress的用法示例。


在下文中一共展示了KeyPress.Key方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: key

func (t *tbfe) key(w http.ResponseWriter, req *http.Request) {
	log4go.Debug("key: %s", req)
	kc := req.FormValue("keyCode")
	var kp backend.KeyPress
	v, _ := strconv.ParseInt(kc, 10, 32)

	if req.FormValue("altKey") == "true" {
		kp.Alt = true
	}
	if req.FormValue("ctrlKey") == "true" {
		kp.Ctrl = true
	}
	if req.FormValue("metaKey") == "true" {
		kp.Super = true
	}
	if req.FormValue("shiftKey") == "true" {
		kp.Shift = true
	}
	if !kp.Shift {
		v = int64(unicode.ToLower(rune(v)))
	}
	kp.Key = backend.Key(v)
	backend.GetEditor().HandleInput(kp)
}
开发者ID:nadavvin,项目名称:lime,代码行数:24,代码来源:main.go

示例2: loop


//.........这里部分代码省略.........
			return termbox.Attribute(l)
		}
	}
	for i, s := range scheme.Settings {
		var (
			fi = defaultFg
			bi = defaultBg
		)
		if fg, ok := s.Settings["foreground"]; ok {
			fi = palLut(fg)
			if i == 0 {
				defaultFg = fi
			}
		}
		if bg, ok := s.Settings["background"]; ok {
			bi = palLut(bg)
			if i == 0 {
				defaultBg = bi
			}
		}
		schemelut[s.Scope] = [2]termbox.Attribute{fi, bi}
	}
	if mode256 {
		termbox.SetColorPalette(pal)
	}
	defer func() {
		termbox.Close()
		fmt.Println(c.Buffer().Data())
	}()

	w := ed.NewWindow()
	t.active_window = w
	v := w.OpenFile("main.go", 0)
	v.Settings().Set("trace", true)
	c.Buffer().AddCallback(t.scroll)

	if err := v.SetSyntaxFile("../../3rdparty/bundles/GoSublime/GoSublime.tmLanguage"); err != nil {
		log4go.Error("Unable to set syntax file: %s", err)
	}
	sel := v.Sel()
	sel.Clear()
	//	end := v.Buffer().Size() - 2
	sel.Add(primitives.Region{0, 0})
	// sel.Add(primitives.Region{end - 22, end - 22})
	// sel.Add(primitives.Region{end - 16, end - 20})
	// sel.Add(primitives.Region{end - 13, end - 10})

	evchan := make(chan termbox.Event)

	go func() {
		for {
			evchan <- termbox.PollEvent()
		}
	}()

	sublime.Init()
	for {
		blink = !blink
		termbox.Clear(defaultFg, defaultBg)
		w, h := termbox.Size()

		t.renderView(0, 0, w, h-console_height, v)
		t.renderView(0, h-(console_height), w, (console_height - 1), c)
		runes := []rune(t.status_message)
		for i := 0; i < w && i < len(runes); i++ {
			termbox.SetCell(i, h-1, runes[i], defaultFg, defaultBg)
		}
		termbox.Flush()

		blink_phase := time.Second
		if p, ok := ed.Settings().Get("caret_blink_phase", 1.0).(float64); ok {
			blink_phase = time.Duration(float64(time.Second) * p)
		}

		select {
		case ev := <-evchan:
			switch ev.Type {
			case termbox.EventKey:
				var kp backend.KeyPress

				if ev.Ch != 0 {
					kp.Key = backend.Key(ev.Ch)
				} else if v2, ok := lut[ev.Key]; ok {
					kp = v2
				} else {
					break
				}

				if ev.Key == termbox.KeyCtrlQ {
					return
				}
				ed.HandleInput(kp)
				blink = false
			}
		case <-time.After(blink_phase / 2):
			// Divided by two since we're only doing a simple toggle blink
			// TODO(q): Shouldn't redraw if blink is disabled...
		}
	}
}
开发者ID:BinaryPaean,项目名称:lime,代码行数:101,代码来源:main.go

示例3: loop


//.........这里部分代码省略.........
	}
	if mode256 {
		termbox.SetColorPalette(pal)
	}
	evchan := make(chan termbox.Event, 32)
	defer func() {
		close(evchan)
		termbox.Close()
		fmt.Println(util.Prof)
	}()

	w := ed.NewWindow()
	v := w.OpenFile("main.go", 0)
	v.Settings().Set("trace", true)
	v.Settings().Set("syntax", "../../3rdparty/bundles/go.tmbundle/Syntaxes/Go.tmLanguage")
	c.Buffer().AddCallback(t.scroll)

	sel := v.Sel()
	sel.Clear()
	//	end := v.Buffer().Size() - 2
	sel.Add(Region{0, 0})
	// sel.Add(Region{end - 22, end - 22})
	// sel.Add(Region{end - 16, end - 20})
	// sel.Add(Region{end - 13, end - 10})

	go func() {
		for {
			evchan <- termbox.PollEvent()
		}
	}()

	{
		w, h := termbox.Size()
		t.lock.Lock()
		t.layout[v] = layout{0, 0, w, h - console_height - 1, Region{}, 0}
		t.layout[c] = layout{0, h - console_height + 1, w, console_height - 5, Region{}, 0}
		t.lock.Unlock()
		t.Show(v, Region{1, 1})
	}
	t.Show(v, Region{100, 100})
	t.Show(v, Region{1, 1})

	go func() {
		ed.Init()
		sublime.Init()
	}()

	for {
		p := util.Prof.Enter("mainloop")

		blink_phase := time.Second
		if p, ok := ed.Settings().Get("caret_blink_phase", 1.0).(float64); ok {
			blink_phase = time.Duration(float64(time.Second) * p)
		}

		timer := time.NewTimer(blink_phase / 2)
		select {
		case ev := <-evchan:
			mp := util.Prof.Enter("evchan")
			limit := 3
		loop:
			switch ev.Type {
			case termbox.EventError:
				log4go.Debug("error occured")
				return
			case termbox.EventKey:
				var kp backend.KeyPress

				if ev.Ch != 0 {
					kp.Key = backend.Key(ev.Ch)
				} else if v2, ok := lut[ev.Key]; ok {
					kp = v2
				} else {
					break
				}

				if ev.Key == termbox.KeyCtrlQ {
					return
				}
				ed.HandleInput(kp)

				blink = true
			}
			if len(evchan) > 0 {
				limit--
				ev = <-evchan
				goto loop
			}
			mp.Exit()
		case <-timer.C:
			// 	// case <-time.After(blink_phase / 2):
			blink = !blink
			t.render()
			// 	// 	// Divided by two since we're only doing a simple toggle blink
			// 	// 	// TODO(q): Shouldn't redraw if blink is disabled...
		}
		timer.Stop()
		p.Exit()
	}
}
开发者ID:richardfontana,项目名称:lime,代码行数:101,代码来源:main.go

示例4: loop

func (t *tbfe) loop() {
	var (
		ed  = t.setupEditor()
		c   = ed.Console()
		w   = ed.NewWindow()
		v   = createNewView("main.go", w)
		sel = v.Sel()
	)

	t.settings = getSettings(v)
	c.Buffer().AddCallback(t.scroll)

	t.setupCallbacks()
	loadTextMateScheme()
	setColorMode()
	setSchemeSettings()
	sel.Clear()
	sel.Add(Region{0, 0})

	evchan := make(chan termbox.Event, 32)
	defer func() {
		close(evchan)
		termbox.Close()
		fmt.Println(util.Prof)
	}()

	go func() {
		for {
			evchan <- termbox.PollEvent()
		}
	}()

	{
		w, h := termbox.Size()
		t.lock.Lock()
		t.layout[v] = layout{0, 0, w, h - console_height - 1, Region{}, 0}
		t.layout[c] = layout{0, h - console_height + 1, w, console_height - 5, Region{}, 0}
		t.lock.Unlock()
		t.Show(v, Region{1, 1})
	}
	t.Show(v, Region{100, 100})
	t.Show(v, Region{1, 1})

	go func() {
		ed.Init()
		sublime.Init()
	}()

	for {
		p := util.Prof.Enter("mainloop")

		blink_phase := time.Second
		if p, ok := ed.Settings().Get("caret_blink_phase", 1.0).(float64); ok {
			blink_phase = time.Duration(float64(time.Second) * p)
		}

		// Divided by two since we're only doing a simple toggle blink
		timer := time.NewTimer(blink_phase / 2)
		select {
		case ev := <-evchan:
			mp := util.Prof.Enter("evchan")
			limit := 3
		loop:
			switch ev.Type {
			case termbox.EventError:
				log4go.Debug("error occured")
				return
			case termbox.EventKey:
				var kp backend.KeyPress

				if ev.Ch != 0 {
					kp.Key = backend.Key(ev.Ch)
				} else if v2, ok := lut[ev.Key]; ok {
					kp = v2
				} else {
					break
				}

				if ev.Key == termbox.KeyCtrlQ {
					return
				}
				ed.HandleInput(kp)

				blink = false
			}
			if len(evchan) > 0 {
				limit--
				ev = <-evchan
				goto loop
			}
			mp.Exit()
		case <-timer.C:
			// TODO(q): Shouldn't redraw if blink is disabled...

			blink = !blink
			t.render()
		}
		timer.Stop()
		p.Exit()
	}
//.........这里部分代码省略.........
开发者ID:vivekgalatage,项目名称:lime,代码行数:101,代码来源:main.go


注:本文中的lime/backend.KeyPress.Key方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。