Skip to content

Commit 4bfc79b

Browse files
authored
Merge pull request #481 from allmightyspiff/termWrapping
Disables text wrapping for Table rows,…
2 parents f47cfc8 + 17adcd0 commit 4bfc79b

5 files changed

Lines changed: 26 additions & 30 deletions

File tree

bluemix/authentication/iam/iam_test.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -311,25 +311,6 @@ func TestRefreshSession(t *testing.T) {
311311
assert.Nil(t, err)
312312
}
313313

314-
func TestAllowPrintCorrelationID(t *testing.T) {
315-
testCases := []struct {
316-
path string
317-
allowPrintCorrelationID bool
318-
}{
319-
{
320-
path: "/v1/sessions",
321-
allowPrintCorrelationID: false,
322-
},
323-
{
324-
path: "/v1/tokens",
325-
allowPrintCorrelationID: true,
326-
},
327-
}
328-
329-
for _, testCase := range testCases {
330-
assert.Equal(t, AllowPrintCorrelationID(testCase.path), testCase.allowPrintCorrelationID)
331-
}
332-
}
333314

334315
// startMockIAMServerForCRExchange will start a mock server endpoint that supports both the
335316
// IAM operations that we'll need to call.

bluemix/terminal/prompt.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (p *Prompt) resolveSingle(dest interface{}) error {
8282
for {
8383
input, readErr := p.read(prompt)
8484
if readErr != nil {
85-
return fmt.Errorf(T("Could not read from input: ") + readErr.Error())
85+
return fmt.Errorf("%s", T("Could not read from input: ") + readErr.Error())
8686
}
8787

8888
var err error
@@ -224,7 +224,7 @@ func (p *Prompt) resolveChoices(dest interface{}) error {
224224
for {
225225
input, readErr := p.read(prompt)
226226
if readErr != nil {
227-
return fmt.Errorf(T("Could not read from input: ") + readErr.Error())
227+
return fmt.Errorf("%s", T("Could not read from input: ") + readErr.Error())
228228
}
229229

230230
var selectedNum int

bluemix/terminal/table.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ func (t *PrintableTable) createColumnConfigs() []table.ColumnConfig {
162162
Align: text.AlignLeft,
163163
WidthMax: maxColWidth,
164164
Number: colIndex + 1,
165+
WidthMaxEnforcer: func(str string, warpLen int) string {
166+
// This effectively disables wrapping.
167+
// https://github.com/jedib0t/go-pretty/blob/main/table/config.go#L68C2-L68C18
168+
return str
169+
},
165170
}
166171

167172
// assuming the table has headers: store columns with wide content where the max width may need to be adjusted

bluemix/terminal/table_test.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,12 @@ func TestMoreColThanTerminalWidth(t *testing.T) {
100100
}
101101

102102
func TestWideHeaderNames(t *testing.T) {
103-
t.Skip("Skip until terminal width issue is fixed")
104103
buf := bytes.Buffer{}
105104
testTable := NewTable(&buf, []string{"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt u", "NAME"})
106105
testTable.Add("col1", "col2")
107106
testTable.Print()
108107
assert.Contains(t, buf.String(), "Lorem ipsum dolor sit amet, consectetu")
109-
assert.Equal(t, bold+"ID "+reset+bold+"Name "+reset+"\nABCDEFG-9b8babbd-f2ed-4371-b817-a839e4130332 row2\n", buf.String())
108+
assert.Equal(t, bold+"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt u "+reset+bold+"NAME "+reset+"\ncol1 col2\n", buf.String())
110109
}
111110

112111
func TestWidestColumn(t *testing.T) {
@@ -120,16 +119,27 @@ func TestWidestColumn(t *testing.T) {
120119
}
121120

122121
func TestMultiWideColumns(t *testing.T) {
123-
t.Skip("Skip until terminal width issue is fixed")
124122
buf := bytes.Buffer{}
125123
id := "ABCDEFG-9b8babbd-f2ed-4371-b817-a839e4130332"
126124
desc := "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut"
127125
testTable := NewTable(&buf, []string{"ID", "Description", "Name"})
128126
testTable.Add(id, desc, "col3")
129127
testTable.Print()
130-
assert.Contains(t, buf.String(), "ABCDEFG-9b8babbd-f2ed-4371-b817-a839")
131-
assert.Contains(t, buf.String(), "e4130332")
132-
assert.Equal(t, buf.String(), "ID Description Name\nABCDEFG-9b8babbd-f2ed-4371-b817-a839 Lorem ipsum dolor sit amet, consect col3\ne4130332 etur adipiscing elit, sed do eiusmo\n d tempor incididunt ut\n")
128+
result := strings.Split(buf.String(), "\n")
129+
assert.Equal(t, result[0], bold+"ID "+reset+bold+"Description "+reset+bold+"Name "+reset)
130+
assert.Equal(t, result[1], "ABCDEFG-9b8babbd-f2ed-4371-b817-a839e4130332 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut col3")
131+
}
132+
133+
func TestMultiWideColumnsWithoutDescription(t *testing.T) {
134+
buf := bytes.Buffer{}
135+
id := "ABCDEFG-9b8babbd-f2ed-4371-b817-a839e4130332"
136+
desc := "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
137+
testTable := NewTable(&buf, []string{"AA", "BB", "CC", "DD", "FF", "ZZ"})
138+
testTable.Add(id, desc, "col3", "Column The fourth", "Yet another column value", "ZZZZZZ")
139+
testTable.Print()
140+
result := strings.Split(buf.String(), "\n")
141+
assert.Equal(t, result[0], "\x1b[1mAA \x1b[0m\x1b[1mBB \x1b[0m\x1b[1mCC \x1b[0m\x1b[1mDD \x1b[0m\x1b[1mFF \x1b[0m\x1b[1mZZ \x1b[0m")
142+
assert.Equal(t, result[1], "ABCDEFG-9b8babbd-f2ed-4371-b817-a839e4130332 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. col3 Column The fourth Yet another column value ZZZZZZ")
133143
}
134144

135145
func TestNotEnoughRowEntiresJson(t *testing.T) {

testhelpers/terminal/test_ui.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (ui *FakeUI) Ok() {
7070
if ui.quiet {
7171
return
7272
}
73-
ui.Say(term.SuccessColor("OK"))
73+
ui.Say("%s", term.SuccessColor("OK"))
7474
}
7575

7676
func (ui *FakeUI) Info(template string, args ...interface{}) {
@@ -82,8 +82,8 @@ func (ui *FakeUI) Info(template string, args ...interface{}) {
8282

8383
func (ui *FakeUI) Failed(template string, args ...interface{}) {
8484
message := fmt.Sprintf(template, args...)
85-
ui.Info(term.FailureColor("FAILED"))
86-
ui.error(message)
85+
ui.Info("%s", term.FailureColor("FAILED"))
86+
ui.error("%s", message)
8787
ui.Info("")
8888
}
8989

0 commit comments

Comments
 (0)