summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-08-29 00:40:28 -0400
committerBen Morrison <ben@gbmor.dev>2019-08-29 00:40:28 -0400
commit25323a54aed498f03fca1bd99935db004d4217fd (patch)
treeb012059daa589bcd46fea355a3f1ba32cbf385a0 /src
parent6dd17c5a5de31725d7a1ed7f636b001ea8a23a51 (diff)
downloadclinte-0.1.0.tar.gz
limit number of displayed posts to 30 v0.1.0
Diffstat (limited to 'src')
-rw-r--r--src/main.rs16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs
index 92a8613..65a6022 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -65,15 +65,23 @@ fn list_matches(db: &db::Conn) {
         })
         .unwrap();
 
+    let mut postvec = Vec::new();
     out.for_each(|row| {
         if let Ok(post) = row {
-            println!(
-                "{}. {} -> by {}\n{}",
+            postvec.push(format!(
+                "{}. {} -> by {}\n{}\n\n",
                 post.id, post.title, post.author, post.body
-            );
-            println!();
+            ));
         }
     });
+
+    for (i, e) in postvec.iter().enumerate() {
+        if postvec.len() >= 30 && i >= postvec.len() - 31 {
+            print!("{}", e);
+        } else if postvec.len() < 30 {
+            print!("{}", e);
+        }
+    }
 }
 
 fn post(db: &db::Conn) {
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201