package lipglossimport ()// JoinHorizontal is a utility function for horizontally joining two// potentially multi-lined strings along a vertical axis. The first argument is// the position, with 0 being all the way at the top and 1 being all the way// at the bottom.//// If you just want to align to the top, center or bottom you may as well just// use the helper constants Top, Center, and Bottom.//// Example://// blockB := "...\n...\n..."// blockA := "...\n...\n...\n...\n..."//// // Join 20% from the top// str := lipgloss.JoinHorizontal(0.2, blockA, blockB)//// // Join on the top edge// str := lipgloss.JoinHorizontal(lipgloss.Top, blockA, blockB)func ( Position, ...string) string {iflen() == 0 {return"" }iflen() == 1 {return [0] }var (// Groups of strings broken into multiple lines = make([][]string, len())// Max line widths for the above text blocks = make([]int, len())// Height of the tallest blockint )// Break text blocks into lines and get max widths for each text blockfor , := range { [], [] = getLines()iflen([]) > { = len([]) } }// Add extra lines to make each side the same heightfor := range {iflen([]) >= {continue } := make([]string, -len([]))switch {caseTop: [] = append([], ...)caseBottom: [] = append(, []...)default: // Somewhere in the middle := len() := int(math.Round(float64() * .value())) := - := - [] = append([:], []...) [] = append([], [:]...) } }// Merge linesvarstrings.Builderfor := range [0] { // remember, all blocks have the same number of members nowfor , := range { .WriteString([])// Also make lines the same length .WriteString(strings.Repeat(" ", []-ansi.StringWidth([]))) }if < len([0])-1 { .WriteRune('\n') } }return .String()}// JoinVertical is a utility function for vertically joining two potentially// multi-lined strings along a horizontal axis. The first argument is the// position, with 0 being all the way to the left and 1 being all the way to// the right.//// If you just want to align to the left, right or center you may as well just// use the helper constants Left, Center, and Right.//// Example://// blockB := "...\n...\n..."// blockA := "...\n...\n...\n...\n..."//// // Join 20% from the top// str := lipgloss.JoinVertical(0.2, blockA, blockB)//// // Join on the right edge// str := lipgloss.JoinVertical(lipgloss.Right, blockA, blockB)func ( Position, ...string) string {iflen() == 0 {return"" }iflen() == 1 {return [0] }var ( = make([][]string, len())int )for := range {varint [], = getLines([])if > { = } }varstrings.Builderfor , := range {for , := range { := - ansi.StringWidth()switch {caseLeft: .WriteString() .WriteString(strings.Repeat(" ", ))caseRight: .WriteString(strings.Repeat(" ", )) .WriteString()default: // Somewhere in the middleif < 1 { .WriteString()break } := int(math.Round(float64() * .value())) := - := - .WriteString(strings.Repeat(" ", )) .WriteString() .WriteString(strings.Repeat(" ", )) }// Write a newline as long as we're not on the last line of the // last block.if !( == len()-1 && == len()-1) { //nolint:staticcheck .WriteRune('\n') } } }return .String()}
The pages are generated with Goldsv0.8.7. (GOOS=linux GOARCH=amd64)