github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/cmds/core/elvish/edit/navigation_width.go (about)

     1  package edit
     2  
     3  // getNavWidths calculates the widths for the three (parent, current and
     4  // preview) columns in the navigation mode. It takes the available width, full
     5  // width required to display the current and preview columns, and returns
     6  // suitable widths for the columns.
     7  //
     8  // The parent column always gets 1/6 of the total width. The current and preview
     9  // columns initially get 1/2 of the remaining width each, but if one of them
    10  // does not have enough widths and another has some spare width, the amount of
    11  // spare width or the needed width (whichever is smaller) is donated from the
    12  // latter to the former.
    13  func getNavWidths(total, currentFull, previewFull int) (int, int, int) {
    14  	parent := total / 6
    15  
    16  	remain := total - parent
    17  	current := remain / 2
    18  	preview := remain - current
    19  
    20  	if current < currentFull && preview > previewFull {
    21  		donate := min(currentFull-current, preview-previewFull)
    22  		current += donate
    23  		preview -= donate
    24  	} else if preview < previewFull && current > currentFull {
    25  		donate := min(previewFull-preview, current-currentFull)
    26  		preview += donate
    27  		current -= donate
    28  	}
    29  	return parent, current, preview
    30  }