viuer terminal images
This commit is contained in:
+23
-1
@@ -8,6 +8,7 @@ use std::path::Path;
|
||||
use std::fmt;
|
||||
use log::{info, debug, error};
|
||||
use bktree::*;
|
||||
use viuer::{Config, print};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum SaveError {
|
||||
@@ -102,10 +103,31 @@ impl DescriptorStore {
|
||||
/// K-nearest neighbors
|
||||
pub fn knn(&self, from: u64, k: isize) {
|
||||
println!("{from:b}");
|
||||
let mut x = 0;
|
||||
let mut y = 8;
|
||||
let (term_width, _) = viuer::terminal_size();
|
||||
println!("\t\t\t\t\tTERMWIDTH {term_width}");
|
||||
for (element, distance) in self.bktree.find(from, k) {
|
||||
let name = self.map.get(element);
|
||||
match name {
|
||||
Some(n) => println!("{element:b}: {n} (distance: {distance})"),
|
||||
Some(n) => {
|
||||
println!("{element:b}: {n} (distance: {distance})");
|
||||
if x+16 >= term_width {
|
||||
x = 0;
|
||||
y += 8;
|
||||
}
|
||||
let conf = viuer::Config {
|
||||
width: Some(16),
|
||||
height: Some(8),
|
||||
x: x,
|
||||
y: y,
|
||||
..Default::default()
|
||||
};
|
||||
x += 16;
|
||||
let path = "data/".to_string() + &n;
|
||||
let img = image::open(&path).unwrap();
|
||||
viuer::print(&img, &conf).expect("Image printing failed.");
|
||||
},
|
||||
None => ()
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user