• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang curses.MaxY函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/junegunn/fzf/src/curses.MaxY函数的典型用法代码示例。如果您正苦于以下问题:Golang MaxY函数的具体用法?Golang MaxY怎么用?Golang MaxY使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: printHeader

func (t *Terminal) printHeader() {
	if len(t.header) == 0 {
		return
	}
	max := C.MaxY()
	var state *ansiState
	for idx, lineStr := range t.header {
		if !t.reverse {
			idx = len(t.header) - idx - 1
		}
		line := idx + 2
		if t.inlineInfo {
			line -= 1
		}
		if line >= max {
			continue
		}
		trimmed, colors, newState := extractColor(&lineStr, state)
		state = newState
		item := &Item{
			text:   trimmed,
			index:  0,
			colors: colors,
			rank:   Rank{0, 0, 0}}

		t.move(line, 2, true)
		t.printHighlighted(item, false, C.ColHeader, 0, false)
	}
}
开发者ID:jrib,项目名称:fzf,代码行数:29,代码来源:terminal.go


示例2: calculateMargins

func (t *Terminal) calculateMargins() {
	screenWidth := C.MaxX()
	screenHeight := C.MaxY()
	for idx, str := range t.margin {
		if str == "0" {
			t.marginInt[idx] = 0
		} else if strings.HasSuffix(str, "%") {
			num, _ := strconv.ParseFloat(str[:len(str)-1], 64)
			var val float64
			if idx%2 == 0 {
				val = float64(screenHeight)
			} else {
				val = float64(screenWidth)
			}
			t.marginInt[idx] = int(val * num * 0.01)
		} else {
			num, _ := strconv.Atoi(str)
			t.marginInt[idx] = num
		}
	}
	adjust := func(idx1 int, idx2 int, max int, min int) {
		if max >= min {
			margin := t.marginInt[idx1] + t.marginInt[idx2]
			if max-margin < min {
				desired := max - min
				t.marginInt[idx1] = desired * t.marginInt[idx1] / margin
				t.marginInt[idx2] = desired * t.marginInt[idx2] / margin
			}
		}
	}
	adjust(1, 3, screenWidth, minWidth)
	adjust(0, 2, screenHeight, minHeight)
}
开发者ID:eshenhu,项目名称:fzf,代码行数:33,代码来源:terminal.go


示例3: maxItems

func (t *Terminal) maxItems() int {
	max := C.MaxY() - 2 - len(t.header)
	if t.inlineInfo {
		max += 1
	}
	return util.Max(max, 0)
}
开发者ID:jrib,项目名称:fzf,代码行数:7,代码来源:terminal.go


示例4: move

func (t *Terminal) move(y int, x int, clear bool) {
	maxy := C.MaxY()
	if !t.reverse {
		y = maxy - y - 1
	}

	if clear {
		C.MoveAndClear(y, x)
	} else {
		C.Move(y, x)
	}
}
开发者ID:zennro,项目名称:fzf,代码行数:12,代码来源:terminal.go


示例5: move

func (t *Terminal) move(y int, x int, clear bool) {
	x += t.marginInt[3]
	maxy := C.MaxY()
	if !t.reverse {
		y = maxy - y - 1 - t.marginInt[2]
	} else {
		y += t.marginInt[0]
	}

	if clear {
		C.MoveAndClear(y, x)
	} else {
		C.Move(y, x)
	}
}
开发者ID:eshenhu,项目名称:fzf,代码行数:15,代码来源:terminal.go


示例6: constrain

func (t *Terminal) constrain() {
	count := t.merger.Length()
	height := C.MaxY() - 2
	diffpos := t.cy - t.offset

	t.cy = util.Constrain(t.cy, 0, count-1)

	if t.cy > t.offset+(height-1) {
		// Ceil
		t.offset = t.cy - (height - 1)
	} else if t.offset > t.cy {
		// Floor
		t.offset = t.cy
	}

	// Adjustment
	if count-t.offset < height {
		t.offset = util.Max(0, count-height)
		t.cy = util.Constrain(t.offset+diffpos, 0, count-1)
	}
}
开发者ID:zennro,项目名称:fzf,代码行数:21,代码来源:terminal.go


示例7: Loop


//.........这里部分代码省略.........
				t.cx = findLastMatch("[^[:alnum:]][[:alnum:]]", string(t.input[:t.cx])) + 1
			case actForwardWord:
				t.cx += findFirstMatch("[[:alnum:]][^[:alnum:]]|(.$)", string(t.input[t.cx:])) + 1
			case actKillWord:
				ncx := t.cx +
					findFirstMatch("[[:alnum:]][^[:alnum:]]|(.$)", string(t.input[t.cx:])) + 1
				if ncx > t.cx {
					t.yanked = copySlice(t.input[t.cx:ncx])
					t.input = append(t.input[:t.cx], t.input[ncx:]...)
				}
			case actKillLine:
				if t.cx < len(t.input) {
					t.yanked = copySlice(t.input[t.cx:])
					t.input = t.input[:t.cx]
				}
			case actRune:
				prefix := copySlice(t.input[:t.cx])
				t.input = append(append(prefix, event.Char), t.input[t.cx:]...)
				t.cx++
			case actPreviousHistory:
				if t.history != nil {
					t.history.override(string(t.input))
					t.input = []rune(t.history.previous())
					t.cx = len(t.input)
				}
			case actNextHistory:
				if t.history != nil {
					t.history.override(string(t.input))
					t.input = []rune(t.history.next())
					t.cx = len(t.input)
				}
			case actMouse:
				me := event.MouseEvent
				mx, my := me.X, me.Y
				if me.S != 0 {
					// Scroll
					if t.merger.Length() > 0 {
						if t.multi && me.Mod {
							toggle()
						}
						t.vmove(me.S)
						req(reqList)
					}
				} else if mx >= t.marginInt[3] && mx < C.MaxX()-t.marginInt[1] &&
					my >= t.marginInt[0] && my < C.MaxY()-t.marginInt[2] {
					mx -= t.marginInt[3]
					my -= t.marginInt[0]
					mx = util.Constrain(mx-len(t.prompt), 0, len(t.input))
					if !t.reverse {
						my = t.maxHeight() - my - 1
					}
					min := 2 + len(t.header)
					if t.inlineInfo {
						min--
					}
					if me.Double {
						// Double-click
						if my >= min {
							if t.vset(t.offset+my-min) && t.cy < t.merger.Length() {
								return doAction(t.keymap[C.DoubleClick], C.DoubleClick)
							}
						}
					} else if me.Down {
						if my == 0 && mx >= 0 {
							// Prompt
							t.cx = mx
						} else if my >= min {
							// List
							if t.vset(t.offset+my-min) && t.multi && me.Mod {
								toggle()
							}
							req(reqList)
						}
					}
				}
			}
			return true
		}
		action := t.keymap[event.Type]
		mapkey := event.Type
		if event.Type == C.Rune {
			mapkey = int(event.Char) + int(C.AltZ)
			if act, prs := t.keymap[mapkey]; prs {
				action = act
			}
		}
		if !doAction(action, mapkey) {
			continue
		}
		changed := string(previousInput) != string(t.input)
		t.mutex.Unlock() // Must be unlocked before touching reqBox

		if changed {
			t.eventBox.Set(EvtSearchNew, t.sort)
		}
		for _, event := range events {
			t.reqBox.Set(event, nil)
		}
	}
}
开发者ID:eshenhu,项目名称:fzf,代码行数:101,代码来源:terminal.go


示例8: maxHeight

func (t *Terminal) maxHeight() int {
	return C.MaxY() - t.marginInt[0] - t.marginInt[2]
}
开发者ID:eshenhu,项目名称:fzf,代码行数:3,代码来源:terminal.go


示例9: maxItems

func maxItems() int {
	return C.MaxY() - 2
}
开发者ID:zennro,项目名称:fzf,代码行数:3,代码来源:terminal.go


示例10: Loop


//.........这里部分代码省略.........
				t.vmove(1)
				req(reqList)
			}
		case C.CtrlJ, C.CtrlN:
			t.vmove(-1)
			req(reqList)
		case C.CtrlK, C.CtrlP:
			t.vmove(1)
			req(reqList)
		case C.CtrlM:
			req(reqClose)
		case C.CtrlL:
			req(reqRedraw)
		case C.CtrlU:
			if t.cx > 0 {
				t.yanked = copySlice(t.input[:t.cx])
				t.input = t.input[t.cx:]
				t.cx = 0
			}
		case C.CtrlW:
			if t.cx > 0 {
				t.rubout("\\s\\S")
			}
		case C.AltBS:
			if t.cx > 0 {
				t.rubout("[^[:alnum:]][[:alnum:]]")
			}
		case C.CtrlY:
			suffix := copySlice(t.input[t.cx:])
			t.input = append(append(t.input[:t.cx], t.yanked...), suffix...)
			t.cx += len(t.yanked)
		case C.Del:
			t.delChar()
		case C.PgUp:
			t.vmove(maxItems() - 1)
			req(reqList)
		case C.PgDn:
			t.vmove(-(maxItems() - 1))
			req(reqList)
		case C.AltB:
			t.cx = findLastMatch("[^[:alnum:]][[:alnum:]]", string(t.input[:t.cx])) + 1
		case C.AltF:
			t.cx += findFirstMatch("[[:alnum:]][^[:alnum:]]|(.$)", string(t.input[t.cx:])) + 1
		case C.AltD:
			ncx := t.cx +
				findFirstMatch("[[:alnum:]][^[:alnum:]]|(.$)", string(t.input[t.cx:])) + 1
			if ncx > t.cx {
				t.yanked = copySlice(t.input[t.cx:ncx])
				t.input = append(t.input[:t.cx], t.input[ncx:]...)
			}
		case C.Rune:
			prefix := copySlice(t.input[:t.cx])
			t.input = append(append(prefix, event.Char), t.input[t.cx:]...)
			t.cx++
		case C.Mouse:
			me := event.MouseEvent
			mx, my := util.Constrain(me.X-len(t.prompt), 0, len(t.input)), me.Y
			if !t.reverse {
				my = C.MaxY() - my - 1
			}
			if me.S != 0 {
				// Scroll
				if t.merger.Length() > 0 {
					if t.multi && me.Mod {
						toggle()
					}
					t.vmove(me.S)
					req(reqList)
				}
			} else if me.Double {
				// Double-click
				if my >= 2 {
					if t.vset(my-2) && t.cy < t.merger.Length() {
						req(reqClose)
					}
				}
			} else if me.Down {
				if my == 0 && mx >= 0 {
					// Prompt
					t.cx = mx
				} else if my >= 2 {
					// List
					if t.vset(t.offset+my-2) && t.multi && me.Mod {
						toggle()
					}
					req(reqList)
				}
			}
		}
		changed := string(previousInput) != string(t.input)
		t.mutex.Unlock() // Must be unlocked before touching reqBox

		if changed {
			t.eventBox.Set(EvtSearchNew, nil)
		}
		for _, event := range events {
			t.reqBox.Set(event, nil)
		}
	}
}
开发者ID:zennro,项目名称:fzf,代码行数:101,代码来源:terminal.go


示例11: resizeWindows

func (t *Terminal) resizeWindows() {
	screenWidth := C.MaxX()
	screenHeight := C.MaxY()
	marginInt := [4]int{}
	for idx, sizeSpec := range t.margin {
		if sizeSpec.percent {
			var max float64
			if idx%2 == 0 {
				max = float64(screenHeight)
			} else {
				max = float64(screenWidth)
			}
			marginInt[idx] = int(max * sizeSpec.size * 0.01)
		} else {
			marginInt[idx] = int(sizeSpec.size)
		}
	}
	adjust := func(idx1 int, idx2 int, max int, min int) {
		if max >= min {
			margin := marginInt[idx1] + marginInt[idx2]
			if max-margin < min {
				desired := max - min
				marginInt[idx1] = desired * marginInt[idx1] / margin
				marginInt[idx2] = desired * marginInt[idx2] / margin
			}
		}
	}
	minAreaWidth := minWidth
	minAreaHeight := minHeight
	if t.isPreviewEnabled() {
		switch t.preview.position {
		case posUp, posDown:
			minAreaHeight *= 2
		case posLeft, posRight:
			minAreaWidth *= 2
		}
	}
	adjust(1, 3, screenWidth, minAreaWidth)
	adjust(0, 2, screenHeight, minAreaHeight)
	if t.window != nil {
		t.window.Close()
	}
	if t.bwindow != nil {
		t.bwindow.Close()
		t.pwindow.Close()
	}

	width := screenWidth - marginInt[1] - marginInt[3]
	height := screenHeight - marginInt[0] - marginInt[2]
	if t.isPreviewEnabled() {
		createPreviewWindow := func(y int, x int, w int, h int) {
			t.bwindow = C.NewWindow(y, x, w, h, true)
			t.pwindow = C.NewWindow(y+1, x+2, w-4, h-2, false)
		}
		switch t.preview.position {
		case posUp:
			pheight := calculateSize(height, t.preview.size, minHeight, 3)
			t.window = C.NewWindow(
				marginInt[0]+pheight, marginInt[3], width, height-pheight, false)
			createPreviewWindow(marginInt[0], marginInt[3], width, pheight)
		case posDown:
			pheight := calculateSize(height, t.preview.size, minHeight, 3)
			t.window = C.NewWindow(
				marginInt[0], marginInt[3], width, height-pheight, false)
			createPreviewWindow(marginInt[0]+height-pheight, marginInt[3], width, pheight)
		case posLeft:
			pwidth := calculateSize(width, t.preview.size, minWidth, 5)
			t.window = C.NewWindow(
				marginInt[0], marginInt[3]+pwidth, width-pwidth, height, false)
			createPreviewWindow(marginInt[0], marginInt[3], pwidth, height)
		case posRight:
			pwidth := calculateSize(width, t.preview.size, minWidth, 5)
			t.window = C.NewWindow(
				marginInt[0], marginInt[3], width-pwidth, height, false)
			createPreviewWindow(marginInt[0], marginInt[3]+width-pwidth, pwidth, height)
		}
	} else {
		t.window = C.NewWindow(
			marginInt[0],
			marginInt[3],
			width,
			height, false)
	}
}
开发者ID:infokiller,项目名称:fzf,代码行数:84,代码来源:terminal.go


示例12: maxItems

func (t *Terminal) maxItems() int {
	if t.inlineInfo {
		return C.MaxY() - 1
	}
	return C.MaxY() - 2
}
开发者ID:blakejennings,项目名称:fzf,代码行数:6,代码来源:terminal.go



注:本文中的github.com/junegunn/fzf/src/curses.MaxY函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang curses.Refresh函数代码示例发布时间:2022-05-23
下一篇:
Golang curses.MaxX函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap