@@ -7,11 +7,13 @@ import (
77 "path"
88 "time"
99
10+ "github.com/mitchellh/go-wordwrap"
1011 "github.com/pkg/errors"
1112 ui "github.com/replicatedhq/termui/v3"
1213 "github.com/replicatedhq/termui/v3/widgets"
1314 "github.com/replicatedhq/troubleshoot/internal/util"
1415 analyzerunner "github.com/replicatedhq/troubleshoot/pkg/analyze"
16+ "github.com/replicatedhq/troubleshoot/pkg/constants"
1517)
1618
1719var (
@@ -178,7 +180,10 @@ func drawDetails(analysisResult *analyzerunner.AnalyzeResult) {
178180
179181 currentTop := 4
180182 title := widgets .NewParagraph ()
181- title .Text = analysisResult .Title
183+ // WrapText is set to false to prevent internal wordwrap which is not accounting for the padding
184+ title .WrapText = false
185+ // For long title that lead to wrapping text, the terminal width is divided by 2 and deducted by MESSAGE_TEXT_PADDING to account for the padding
186+ title .Text = wordwrap .WrapString (analysisResult .Title , uint (termWidth / 2 - constants .MESSAGE_TEXT_PADDING ))
182187 title .Border = false
183188 if analysisResult .IsPass {
184189 title .TextStyle = ui .NewStyle (ui .ColorGreen , ui .ColorClear , ui .ModifierBold )
@@ -187,34 +192,26 @@ func drawDetails(analysisResult *analyzerunner.AnalyzeResult) {
187192 } else if analysisResult .IsFail {
188193 title .TextStyle = ui .NewStyle (ui .ColorRed , ui .ColorClear , ui .ModifierBold )
189194 }
190- height := estimateNumberOfLines (title .Text , termWidth / 2 )
195+ height := util . EstimateNumberOfLines (title .Text )
191196 title .SetRect (termWidth / 2 , currentTop , termWidth , currentTop + height )
192197 ui .Render (title )
193198 currentTop = currentTop + height + 1
194199
195200 message := widgets .NewParagraph ()
196- message .Text = analysisResult .Message
201+ // WrapText is set to false to prevent internal wordwrap which is not accounting for the padding
202+ message .WrapText = false
203+ // For long text that lead to wrapping text, the terminal width is divided by 2 and deducted by MESSAGE_TEXT_PADDING to account for the padding
204+ message .Text = wordwrap .WrapString (analysisResult .Message , uint (termWidth / 2 - constants .MESSAGE_TEXT_PADDING ))
205+ if analysisResult .URI != "" {
206+ // Add URL to the message with wordwrap
207+ // Add emply lines as separator
208+ urlText := wordwrap .WrapString (fmt .Sprintf ("For more information: %s" , analysisResult .URI ), uint (termWidth / 2 - constants .MESSAGE_TEXT_PADDING ))
209+ message .Text = message .Text + "\n \n " + urlText
210+ }
211+ height = util .EstimateNumberOfLines (message .Text ) + constants .MESSAGE_TEXT_LINES_MARGIN_TO_BOTTOM
197212 message .Border = false
198- height = estimateNumberOfLines (message .Text , termWidth / 2 ) + 2
199213 message .SetRect (termWidth / 2 , currentTop , termWidth , currentTop + height )
200214 ui .Render (message )
201- currentTop = currentTop + height + 1
202-
203- if analysisResult .URI != "" {
204- uri := widgets .NewParagraph ()
205- uri .Text = fmt .Sprintf ("For more information: %s" , analysisResult .URI )
206- uri .Border = false
207- // For long urls that lead to wrapping text, make the rectangle bigger by
208- // increasing the calculated height by 2
209- height = estimateNumberOfLines (uri .Text , termWidth / 2 ) + 2
210- uri .SetRect (termWidth / 2 , currentTop , termWidth , currentTop + height )
211- ui .Render (uri )
212- }
213- }
214-
215- func estimateNumberOfLines (text string , width int ) int {
216- lines := len (text )/ width + 1
217- return lines
218215}
219216
220217func showSaved (filename string ) {
0 commit comments