mirror of
https://github.com/bootandy/dust.git
synced 2025-12-12 15:49:58 -08:00
hack
This commit is contained in:
35
Cargo.lock
generated
35
Cargo.lock
generated
@@ -344,6 +344,7 @@ dependencies = [
|
||||
"sysinfo",
|
||||
"tempfile",
|
||||
"terminal_size",
|
||||
"termion",
|
||||
"thousands",
|
||||
"unicode-width",
|
||||
"winapi-util",
|
||||
@@ -486,6 +487,7 @@ checksum = "1580801010e535496706ba011c15f8532df6b42297d2e471fec38ceadd8c0638"
|
||||
dependencies = [
|
||||
"bitflags 2.9.1",
|
||||
"libc",
|
||||
"redox_syscall",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -562,6 +564,12 @@ dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "numtoa"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6aa2c4e539b869820a2b82e1aef6ff40aa85e65decdd5185e83fb4b1249cd00f"
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.21.3"
|
||||
@@ -657,6 +665,21 @@ dependencies = [
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.5.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d04b7d0ee6b4a0207a0a7adb104d23ecb0b47d6beae7152d0fa34b692b29fd6"
|
||||
dependencies = [
|
||||
"bitflags 2.9.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_termios"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "20145670ba436b55d91fc92d25e71160fbfbdd57831631c8d7d36377a476f1cb"
|
||||
|
||||
[[package]]
|
||||
name = "redox_users"
|
||||
version = "0.4.6"
|
||||
@@ -841,6 +864,18 @@ dependencies = [
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termion"
|
||||
version = "4.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3669a69de26799d6321a5aa713f55f7e2cd37bd47be044b50f2acafc42c122bb"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"libredox",
|
||||
"numtoa",
|
||||
"redox_termios",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termtree"
|
||||
version = "0.5.1"
|
||||
|
||||
@@ -43,6 +43,7 @@ directories = "4"
|
||||
sysinfo = "0.27"
|
||||
ctrlc = "3.4"
|
||||
chrono = "0.4"
|
||||
termion="4"
|
||||
|
||||
[target.'cfg(not(target_has_atomic = "64"))'.dependencies]
|
||||
portable-atomic = "1.4"
|
||||
|
||||
@@ -4,14 +4,17 @@ use crate::node::FileTime;
|
||||
use ansi_term::Colour::Red;
|
||||
use lscolors::{LsColors, Style};
|
||||
|
||||
use termion::raw::RawTerminal;
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
|
||||
use stfu8::encode_u8;
|
||||
|
||||
use std::io::{Write};
|
||||
use chrono::{DateTime, Local, TimeZone, Utc};
|
||||
use std::cmp::max;
|
||||
use std::cmp::min;
|
||||
use std::fs;
|
||||
use std::io::Stdout;
|
||||
use std::iter::repeat_n;
|
||||
use std::path::Path;
|
||||
use thousands::Separable;
|
||||
@@ -129,6 +132,7 @@ pub fn draw_it(
|
||||
no_percent_bars: bool,
|
||||
terminal_width: usize,
|
||||
skip_total: bool,
|
||||
stdout: &mut RawTerminal<Stdout>,
|
||||
) {
|
||||
let num_chars_needed_on_left_most = if idd.by_filecount {
|
||||
let max_size = root_node.size;
|
||||
@@ -143,6 +147,8 @@ pub fn draw_it(
|
||||
terminal_width > num_chars_needed_on_left_most + 2,
|
||||
"Not enough terminal width"
|
||||
);
|
||||
// write!(stdout, "{}{}Hello!", termion::clear::All, termion::cursor::Goto(1, 1)).unwrap();
|
||||
// write!(stdout, "{}", termion::cursor::Goto(2, 1)).unwrap();
|
||||
|
||||
let allowed_width = terminal_width - num_chars_needed_on_left_most - 2;
|
||||
let num_indent_chars = 3;
|
||||
@@ -171,7 +177,7 @@ pub fn draw_it(
|
||||
};
|
||||
|
||||
if !skip_total {
|
||||
display_node(root_node, &draw_data, true, true);
|
||||
display_node(root_node, stdout, &draw_data, true, true);
|
||||
} else {
|
||||
for (count, c) in root_node
|
||||
.get_children_from_node(draw_data.display_data.initial.is_reversed)
|
||||
@@ -179,7 +185,7 @@ pub fn draw_it(
|
||||
{
|
||||
let is_biggest = display_data.is_biggest(count, root_node.num_siblings());
|
||||
let was_i_last = display_data.is_last(count, root_node.num_siblings());
|
||||
display_node(c, &draw_data, is_biggest, was_i_last);
|
||||
display_node(c, stdout, &draw_data, is_biggest, was_i_last);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -218,22 +224,24 @@ fn find_longest_dir_name(
|
||||
.fold(longest, max)
|
||||
}
|
||||
|
||||
fn display_node(node: &DisplayNode, draw_data: &DrawData, is_biggest: bool, is_last: bool) {
|
||||
fn display_node(node: &DisplayNode,
|
||||
stdout: &mut RawTerminal<Stdout>,
|
||||
draw_data: &DrawData, is_biggest: bool, is_last: bool) {
|
||||
// hacky way of working out how deep we are in the tree
|
||||
let indent = draw_data.get_new_indent(!node.children.is_empty(), is_last);
|
||||
let level = ((indent.chars().count() - 1) / 2) - 1;
|
||||
let bar_text = draw_data.generate_bar(node, level);
|
||||
|
||||
let to_print = format_string(node, &indent, &bar_text, is_biggest, draw_data.display_data);
|
||||
let to_print = format_string(node, &indent, &bar_text, is_biggest, &draw_data.display_data);
|
||||
|
||||
if !draw_data.display_data.initial.is_reversed {
|
||||
println!("{to_print}")
|
||||
write!(stdout, "{to_print}").unwrap()
|
||||
}
|
||||
|
||||
let dd = DrawData {
|
||||
indent: clean_indentation_string(&indent),
|
||||
percent_bar: bar_text,
|
||||
display_data: draw_data.display_data,
|
||||
display_data:draw_data.display_data,
|
||||
};
|
||||
|
||||
let num_siblings = node.num_siblings();
|
||||
@@ -244,11 +252,11 @@ fn display_node(node: &DisplayNode, draw_data: &DrawData, is_biggest: bool, is_l
|
||||
{
|
||||
let is_biggest = dd.display_data.is_biggest(count, num_siblings);
|
||||
let was_i_last = dd.display_data.is_last(count, num_siblings);
|
||||
display_node(c, &dd, is_biggest, was_i_last);
|
||||
display_node( c, stdout, &dd, is_biggest, was_i_last);
|
||||
}
|
||||
|
||||
if draw_data.display_data.initial.is_reversed {
|
||||
println!("{to_print}")
|
||||
write!(stdout, "{to_print}").unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
68
src/main.rs
68
src/main.rs
@@ -20,10 +20,14 @@ use display::InitialDisplayData;
|
||||
use filter::AggregateData;
|
||||
use progress::PIndicator;
|
||||
use regex::Error;
|
||||
use termion::raw::RawTerminal;
|
||||
use std::collections::HashSet;
|
||||
use std::env;
|
||||
use std::fs::read_to_string;
|
||||
use std::io;
|
||||
use std::io::stdin;
|
||||
use std::io::stdout;
|
||||
use std::io::Stdout;
|
||||
use std::panic;
|
||||
use std::process;
|
||||
use std::sync::Arc;
|
||||
@@ -31,6 +35,11 @@ use std::sync::Mutex;
|
||||
use sysinfo::{System, SystemExt};
|
||||
use utils::canonicalize_absolute_path;
|
||||
|
||||
use termion::event::{Key, Event};
|
||||
use termion::input::{TermRead};
|
||||
use termion::raw::IntoRawMode;
|
||||
use std::io::{Write};
|
||||
|
||||
use self::display::draw_it;
|
||||
use config::get_config;
|
||||
use dir_walker::walk_it;
|
||||
@@ -309,24 +318,60 @@ fn main() {
|
||||
let print_errors = config.get_print_errors(&options);
|
||||
print_any_errors(print_errors, walk_data.errors);
|
||||
|
||||
print_output(
|
||||
config,
|
||||
options,
|
||||
tree,
|
||||
walk_data.by_filecount,
|
||||
let stdin = stdin();
|
||||
let mut out = stdout().into_raw_mode().unwrap();
|
||||
|
||||
write!(out, "{}{}Dust interactive (q to quit)", termion::clear::All, termion::cursor::Goto(1, 1)).unwrap();
|
||||
write!(out, "{}", termion::cursor::Goto(1, 2)).unwrap();
|
||||
print_output(
|
||||
&config,
|
||||
&options,
|
||||
&tree,
|
||||
is_colors,
|
||||
terminal_width,
|
||||
)
|
||||
});
|
||||
&mut out,
|
||||
);
|
||||
out.flush().unwrap();
|
||||
|
||||
for c in stdin.events() {
|
||||
write!(out, "{}{}Dust interactive (q to quit)", termion::clear::All, termion::cursor::Goto(1, 1)).unwrap();
|
||||
write!(out, "{}", termion::cursor::Goto(1, 2)).unwrap();
|
||||
let evt = c.unwrap();
|
||||
match evt {
|
||||
Event::Key(Key::Char('q')) => break,
|
||||
Event::Key(Key::Char(x)) => {
|
||||
// println!("{}key ", x);
|
||||
},
|
||||
Event::Key(Key::Left) =>{
|
||||
// println!("left ");
|
||||
}
|
||||
Event::Key(Key::Right) =>{
|
||||
// println!("right ");
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
print_output(
|
||||
&config,
|
||||
&options,
|
||||
&tree,
|
||||
is_colors,
|
||||
terminal_width,
|
||||
&mut out,
|
||||
);
|
||||
out.flush().unwrap();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
fn print_output(
|
||||
config: Config,
|
||||
options: Cli,
|
||||
tree: DisplayNode,
|
||||
by_filecount: bool,
|
||||
config: &Config,
|
||||
options: &Cli,
|
||||
tree: &DisplayNode,
|
||||
is_colors: bool,
|
||||
terminal_width: usize,
|
||||
stdout: &mut RawTerminal<Stdout>
|
||||
) {
|
||||
let output_format = config.get_output_format(&options);
|
||||
|
||||
@@ -353,6 +398,7 @@ fn print_output(
|
||||
config.get_no_bars(&options),
|
||||
terminal_width,
|
||||
config.get_skip_total(&options),
|
||||
stdout,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user