Beispiel #1
0
func (t *Terminal) resizeWindows() {
	screenWidth := tui.MaxX()
	screenHeight := tui.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 = tui.NewWindow(y, x, w, h, true)
			t.pwindow = tui.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 = tui.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 = tui.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 = tui.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 = tui.NewWindow(
				marginInt[0], marginInt[3], width-pwidth, height, false)
			createPreviewWindow(marginInt[0], marginInt[3]+width-pwidth, pwidth, height)
		}
	} else {
		t.window = tui.NewWindow(
			marginInt[0],
			marginInt[3],
			width,
			height, false)
	}
}
Beispiel #2
0
func (t *Terminal) resizeWindows() {
	screenWidth := tui.MaxX()
	screenHeight := tui.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 = tui.NewWindow(y, x, w, h, true)
			pwidth := w - 4
			// ncurses auto-wraps the line when the cursor reaches the right-end of
			// the window. To prevent unintended line-wraps, we use the width one
			// column larger than the desired value.
			if !t.preview.wrap && tui.DoesAutoWrap() {
				pwidth += 1
			}
			t.pwindow = tui.NewWindow(y+1, x+2, pwidth, h-2, false)
		}
		switch t.preview.position {
		case posUp:
			pheight := calculateSize(height, t.preview.size, minHeight, 3)
			t.window = tui.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 = tui.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 = tui.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 = tui.NewWindow(
				marginInt[0], marginInt[3], width-pwidth, height, false)
			createPreviewWindow(marginInt[0], marginInt[3]+width-pwidth, pwidth, height)
		}
	} else {
		t.window = tui.NewWindow(
			marginInt[0],
			marginInt[3],
			width,
			height, false)
	}
}