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


Golang curses.MaxX函数代码示例

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


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

示例1: 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

示例2: 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

示例3: printHighlighted

func (t *Terminal) printHighlighted(item *Item, bold bool, col1 int, col2 int, current bool) {
	var maxe int32
	for _, offset := range item.offsets {
		if offset[1] > maxe {
			maxe = offset[1]
		}
	}

	// Overflow
	text := make([]rune, len(item.text))
	copy(text, item.text)
	offsets := item.colorOffsets(col2, bold, current)
	maxWidth := C.MaxX() - 3 - t.marginInt[1] - t.marginInt[3]
	fullWidth := displayWidth(text)
	if fullWidth > maxWidth {
		if t.hscroll {
			// Stri..
			matchEndWidth := displayWidth(text[:maxe])
			if matchEndWidth <= maxWidth-2 {
				text, _ = trimRight(text, maxWidth-2)
				text = append(text, []rune("..")...)
			} else {
				// Stri..
				if matchEndWidth < fullWidth-2 {
					text = append(text[:maxe], []rune("..")...)
				}
				// ..ri..
				var diff int32
				text, diff = trimLeft(text, maxWidth-2)

				// Transform offsets
				for idx, offset := range offsets {
					b, e := offset.offset[0], offset.offset[1]
					b += 2 - diff
					e += 2 - diff
					b = util.Max32(b, 2)
					offsets[idx].offset[0] = b
					offsets[idx].offset[1] = util.Max32(b, e)
				}
				text = append([]rune(".."), text...)
			}
		} else {
			text, _ = trimRight(text, maxWidth-2)
			text = append(text, []rune("..")...)

			for idx, offset := range offsets {
				offsets[idx].offset[0] = util.Min32(offset.offset[0], int32(maxWidth-2))
				offsets[idx].offset[1] = util.Min32(offset.offset[1], int32(maxWidth))
			}
		}
	}

	var index int32
	var substr string
	var prefixWidth int
	maxOffset := int32(len(text))
	for _, offset := range offsets {
		b := util.Constrain32(offset.offset[0], index, maxOffset)
		e := util.Constrain32(offset.offset[1], index, maxOffset)

		substr, prefixWidth = processTabs(text[index:b], prefixWidth)
		C.CPrint(col1, bold, substr)

		if b < e {
			substr, prefixWidth = processTabs(text[b:e], prefixWidth)
			C.CPrint(offset.color, offset.bold, substr)
		}

		index = e
		if index >= maxOffset {
			break
		}
	}
	if index < maxOffset {
		substr, _ = processTabs(text[index:], prefixWidth)
		C.CPrint(col1, bold, substr)
	}
}
开发者ID:eshenhu,项目名称:fzf,代码行数:78,代码来源:terminal.go

示例4: 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


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