From 6bf438a9d51ba3cc16b5f2e7aa4f102d12ae770f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jakub=20Sko=C5=99epa?= <jakub@skorepa.info>
Date: Sun, 23 Aug 2015 20:03:26 +0200
Subject: [PATCH] Proper terminal size detection & dont break line in s mode

---
 dserial-cli/src/commands/ReadCommand.vala | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/dserial-cli/src/commands/ReadCommand.vala b/dserial-cli/src/commands/ReadCommand.vala
index f42ac47..8e5b16a 100644
--- a/dserial-cli/src/commands/ReadCommand.vala
+++ b/dserial-cli/src/commands/ReadCommand.vala
@@ -56,7 +56,18 @@ public class ReadCommand : Object, Command
 		} else {
 			int rows;
 			int cols;
+            if(!state.interactive) Readline.initialize();
 			Readline.get_screen_size(out rows, out cols);
+            if(rows == 0 || cols == 0) {
+                string? v = Environment.get_variable("LINES");
+                if(v!=null) rows = int.parse(v);
+                v = Environment.get_variable("COLUMNS");
+                if(v!=null) cols = int.parse(v);
+            }
+            if(rows == 0 || cols == 0) {
+                rows = 23;
+                cols = 80;
+            }
 			int chars_per = 0;
 			for(int i = 0; i < printers.length; i++) {
 				chars_per += printers[i].width_per_char;
@@ -97,7 +108,7 @@ public class ReadCommand : Object, Command
 						stdout.printf("   ");
 						printers[x].a(tmpbuf);
 					}
-					stdout.printf("\n");
+					if(display_fields != "s") stdout.printf("\n");
 					counter = 0;
 				}
 			}
-- 
GitLab