Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit b154b31

Browse files
committed
Add custom ResultHander for multi-table
- For now instead of trying to handle this centrally in spring-shell add quick fix via custom handler. - Relates #4795
1 parent 8b0b479 commit b154b31

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

spring-cloud-dataflow-shell-core/src/main/java/org/springframework/cloud/dataflow/shell/config/ShellAutoConfiguration.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.cloud.dataflow.shell.config;
1818

19+
import org.jline.terminal.Terminal;
20+
1921
import org.springframework.boot.ApplicationRunner;
2022
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2123
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -56,6 +58,11 @@ public RestTemplate restTemplate() {
5658
return DataFlowTemplate.getDefaultDataflowRestTemplate();
5759
}
5860

61+
@Bean
62+
public TablesResultHandler tablesResultHandler(Terminal terminal) {
63+
return new TablesResultHandler(terminal);
64+
}
65+
5966
@Configuration(proxyBeanMethods = false)
6067
static class ShellRunnerConfiguration {
6168

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.cloud.dataflow.shell.config;
17+
18+
import java.util.List;
19+
20+
import org.jline.terminal.Terminal;
21+
22+
import org.springframework.shell.result.TerminalAwareResultHandler;
23+
import org.springframework.shell.table.Table;
24+
25+
/**
26+
* Result handler which output's multiple tables.
27+
*
28+
* @author Janne Valkealahti
29+
*/
30+
public class TablesResultHandler extends TerminalAwareResultHandler<List<Table>> {
31+
32+
public TablesResultHandler(Terminal terminal) {
33+
super(terminal);
34+
}
35+
36+
@Override
37+
protected void doHandleResult(List<Table> tables) {
38+
for (Table table : tables) {
39+
terminal.writer().println(table.render(terminal.getWidth()));
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)