mirror of
https://github.com/jht5945/finding.git
synced 2025-12-28 05:30:04 +08:00
update crates
This commit is contained in:
@@ -5,43 +5,10 @@ use std:: {
|
||||
io::prelude::*,
|
||||
};
|
||||
|
||||
use rust_util::*;
|
||||
|
||||
pub fn get_term_width() -> Option<usize> {
|
||||
match term_size::dimensions() {
|
||||
None => None,
|
||||
Some((w, _h)) => Some(w),
|
||||
}
|
||||
}
|
||||
|
||||
// thanks https://blog.csdn.net/star_xiong/article/details/89401149
|
||||
pub fn find_char_boundary(s: &str, index: usize) -> usize {
|
||||
if s.len() <= index {
|
||||
return index;
|
||||
}
|
||||
let mut new_index = index;
|
||||
while !s.is_char_boundary(new_index) {
|
||||
new_index += 1;
|
||||
}
|
||||
new_index
|
||||
}
|
||||
|
||||
pub fn get_term_width_message(message: &str, left: usize) -> String {
|
||||
match get_term_width() {
|
||||
None => message.to_string(),
|
||||
Some(w) => {
|
||||
let len = message.len();
|
||||
if w > len {
|
||||
return message.to_string();
|
||||
}
|
||||
let mut s = String::new();
|
||||
s.push_str(&message[0..find_char_boundary(&message, w-10-5-left)]);
|
||||
s.push_str("[...]");
|
||||
s.push_str(&message[find_char_boundary(&message, len-10)..]);
|
||||
s
|
||||
},
|
||||
}
|
||||
}
|
||||
use rust_util::{
|
||||
XResult,
|
||||
new_box_error,
|
||||
};
|
||||
|
||||
pub fn read_file_content(file: &Path, large_file_len: u64) -> XResult<String> {
|
||||
if ! file.exists() {
|
||||
|
||||
@@ -13,7 +13,13 @@ use std::{
|
||||
};
|
||||
|
||||
use opt::*;
|
||||
use rust_util::*;
|
||||
use rust_util::{
|
||||
XResult,
|
||||
new_box_error,
|
||||
util_file::*,
|
||||
util_size::*,
|
||||
util_msg::*,
|
||||
};
|
||||
use local_util::*;
|
||||
|
||||
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
|
||||
use argparse::{ArgumentParser, StoreTrue, Store};
|
||||
|
||||
use rust_util::*;
|
||||
use rust_util::{
|
||||
XResult,
|
||||
util_size::*,
|
||||
};
|
||||
|
||||
pub struct Options {
|
||||
pub version: bool,
|
||||
|
||||
Reference in New Issue
Block a user