コード例 #1
0
func updateBarsWin(msg currentBars, barsWin *gc.Window, colors colorsDefined, scale int64) {

	whiteOnBlack := colors.whiteOnBlack
	redOnBlack := colors.redOnBlack
	greenOnBlack := colors.greenOnBlack
	barsWin.Erase()
	barsWin.Box(0, 0)
	edibleCopy := make([]int64, len(msg.cols))
	copy(edibleCopy, msg.cols)
	barsHeight, barsWidth := barsWin.MaxYX()
	startI := len(edibleCopy) - barsWidth
	if startI < 0 {
		startI = 0
	}
	currentSec := time.Now().Second()
	prevSec := currentSec - 1
	if prevSec < 0 {
		prevSec = 59
	}
	for row := 0; row < barsHeight-2; row++ {
		for col := range edibleCopy[startI:len(edibleCopy)] {
			if edibleCopy[col]/scale > 0 {
				turnOffColor := int16(0)
				currChar := "="
				// row is an int--32-bit, right?
				if shouldShowFail(msg.failCols[col], scale, row) {
					barsWin.ColorOff(whiteOnBlack)
					barsWin.ColorOn(redOnBlack)
					currChar = "x"
					turnOffColor = redOnBlack

				} else if col == currentSec ||
					col == currentSec-1 {
					// current second is still in progress, so make the previous second
					// green too--not precisely correct, but close enough here
					barsWin.ColorOff(whiteOnBlack)
					barsWin.ColorOn(greenOnBlack)
					turnOffColor = greenOnBlack
				}

				barsWin.MovePrint(barsHeight-2-row, col+1, currChar)

				if turnOffColor != 0 {
					barsWin.ColorOff(turnOffColor)
					barsWin.ColorOn(whiteOnBlack)
				}

				edibleCopy[col] = edibleCopy[col] - scale
			}
		}
	}
	barsWin.NoutRefresh()
}
コード例 #2
0
func updateMsgWin(msg ncursesMsg, msgWin *gc.Window, workerCountWin *gc.Window) {
	var row int
	if msg.msgType == MSG_TYPE_RESULT {
		row = 1
	} else if msg.msgType == MSG_TYPE_INFO {
		row = 2
	} else {
		row = 3
	}
	msgWin.MovePrint(row, 1, fmt.Sprintf("%-40s", msg.msgStr))
	msgWin.Box(0, 0)
	msgWin.NoutRefresh()
	if msg.currentCount >= 0 {
		workerCountWin.MovePrint(1, 1, fmt.Sprintf("%5d", msg.currentCount))
		workerCountWin.NoutRefresh()
	}
}