You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by "CMoH (via GitHub)" <gi...@apache.org> on 2023/03/13 22:43:26 UTC

[GitHub] [karaf] CMoH opened a new pull request, #1716: [KARAF-7678] Fix ShellTable multiline clipping

CMoH opened a new pull request, #1716:
URL: https://github.com/apache/karaf/pull/1716

   Account for multi-line cell contents when calculating cell width and clipping the text to maxSize. The cell contents might be either wrapped or originally split by the caller with \n characters


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@karaf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [karaf] wborn commented on a diff in pull request #1716: [KARAF-7678] Fix ShellTable multiline clipping

Posted by "wborn (via GitHub)" <gi...@apache.org>.
wborn commented on code in PR #1716:
URL: https://github.com/apache/karaf/pull/1716#discussion_r1139062134


##########
shell/core/src/main/java/org/apache/karaf/shell/support/table/Col.java:
##########
@@ -148,8 +149,14 @@ String format(Object cellData) {
         if (fullContent.length() == 0) {
             return "";
         }
-        String finalContent = cut(fullContent, getClippedSize(fullContent.length()));
-        updateSize(finalContent.length());
+        if (wrap && size < fullContent.length()) {
+            // make sure splitLines will have an estimate cell size if wrap is true
+            updateSize(fullContent.length());
+        }
+        List<String> lines = splitLines(fullContent);
+        int maxLineSize = lines.stream().mapToInt(String::length).max().getAsInt(); // at least one line exists due to test above
+        updateSize(maxLineSize); // calls getClippedSize()
+        String finalContent = lines.stream().map(line -> cut(line, getClippedSize(line.length()))).collect(Collectors.joining("\n"));

Review Comment:
   Will this work on Windows which uses a different line separator?
   E.g. using `System.lineSeparator()` instead of `\n` would be based on the OS.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@karaf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [karaf] CMoH commented on a diff in pull request #1716: [KARAF-7678] Fix ShellTable multiline clipping

Posted by "CMoH (via GitHub)" <gi...@apache.org>.
CMoH commented on code in PR #1716:
URL: https://github.com/apache/karaf/pull/1716#discussion_r1140019185


##########
shell/core/src/main/java/org/apache/karaf/shell/support/table/Col.java:
##########
@@ -148,8 +149,14 @@ String format(Object cellData) {
         if (fullContent.length() == 0) {
             return "";
         }
-        String finalContent = cut(fullContent, getClippedSize(fullContent.length()));
-        updateSize(finalContent.length());
+        if (wrap && size < fullContent.length()) {
+            // make sure splitLines will have an estimate cell size if wrap is true
+            updateSize(fullContent.length());
+        }
+        List<String> lines = splitLines(fullContent);
+        int maxLineSize = lines.stream().mapToInt(String::length).max().getAsInt(); // at least one line exists due to test above
+        updateSize(maxLineSize); // calls getClippedSize()
+        String finalContent = lines.stream().map(line -> cut(line, getClippedSize(line.length()))).collect(Collectors.joining("\n"));

Review Comment:
   I think in this particular case I think it will work, since `\n` is included in the Windows line separator, `\n\r`. Also, the contents of `splitLines()` is the verbatim top-section of the `getContents()` method, so at least I don't expect the behaviour to change after this commit.
   
   However, the comment is valid in principle. As you mentioned in https://github.com/apache/karaf/pull/1715#discussion_r1139063272, this seems to be a style issue across the entire code base. If so, would it be worth adressing them all as a separate issue?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@karaf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [karaf] wborn commented on a diff in pull request #1716: [KARAF-7678] Fix ShellTable multiline clipping

Posted by "wborn (via GitHub)" <gi...@apache.org>.
wborn commented on code in PR #1716:
URL: https://github.com/apache/karaf/pull/1716#discussion_r1139062134


##########
shell/core/src/main/java/org/apache/karaf/shell/support/table/Col.java:
##########
@@ -148,8 +149,14 @@ String format(Object cellData) {
         if (fullContent.length() == 0) {
             return "";
         }
-        String finalContent = cut(fullContent, getClippedSize(fullContent.length()));
-        updateSize(finalContent.length());
+        if (wrap && size < fullContent.length()) {
+            // make sure splitLines will have an estimate cell size if wrap is true
+            updateSize(fullContent.length());
+        }
+        List<String> lines = splitLines(fullContent);
+        int maxLineSize = lines.stream().mapToInt(String::length).max().getAsInt(); // at least one line exists due to test above
+        updateSize(maxLineSize); // calls getClippedSize()
+        String finalContent = lines.stream().map(line -> cut(line, getClippedSize(line.length()))).collect(Collectors.joining("\n"));

Review Comment:
   Will this work on Windows which uses a different line separator?
   E.g. using `System.lineSeparator()` would be based on the OS.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@karaf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [karaf] jbonofre merged pull request #1716: [KARAF-7678] Fix ShellTable multiline clipping

Posted by "jbonofre (via GitHub)" <gi...@apache.org>.
jbonofre merged PR #1716:
URL: https://github.com/apache/karaf/pull/1716


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@karaf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [karaf] jbonofre commented on a diff in pull request #1716: [KARAF-7678] Fix ShellTable multiline clipping

Posted by "jbonofre (via GitHub)" <gi...@apache.org>.
jbonofre commented on code in PR #1716:
URL: https://github.com/apache/karaf/pull/1716#discussion_r1270231790


##########
shell/core/src/main/java/org/apache/karaf/shell/support/table/Col.java:
##########
@@ -148,8 +149,14 @@ String format(Object cellData) {
         if (fullContent.length() == 0) {
             return "";
         }
-        String finalContent = cut(fullContent, getClippedSize(fullContent.length()));
-        updateSize(finalContent.length());
+        if (wrap && size < fullContent.length()) {
+            // make sure splitLines will have an estimate cell size if wrap is true
+            updateSize(fullContent.length());
+        }
+        List<String> lines = splitLines(fullContent);
+        int maxLineSize = lines.stream().mapToInt(String::length).max().getAsInt(); // at least one line exists due to test above
+        updateSize(maxLineSize); // calls getClippedSize()
+        String finalContent = lines.stream().map(line -> cut(line, getClippedSize(line.length()))).collect(Collectors.joining("\n"));

Review Comment:
   I would address the split line separator in another PR. Anyway I don't think it's a big deal :)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@karaf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org