fix: fix overflow table border

This commit is contained in:
Embers-of-the-Fire 2024-08-03 10:58:57 +08:00
parent 85b06b22d9
commit b03080704a
3 changed files with 37 additions and 2 deletions

1
Cargo.lock generated
View File

@ -3157,6 +3157,7 @@ dependencies = [
"nu-path", "nu-path",
"nu-protocol", "nu-protocol",
"nu-utils", "nu-utils",
"terminal_size",
] ]
[[package]] [[package]]

View File

@ -16,6 +16,7 @@ nu-path = { path = "../nu-path", version = "0.96.2" }
nu-glob = { path = "../nu-glob", version = "0.96.2" } nu-glob = { path = "../nu-glob", version = "0.96.2" }
nu-utils = { path = "../nu-utils", version = "0.96.2" } nu-utils = { path = "../nu-utils", version = "0.96.2" }
log = { workspace = true } log = { workspace = true }
terminal_size = { workspace = true }
[features] [features]
plugin = [] plugin = []

View File

@ -7,6 +7,7 @@ use nu_protocol::{
Spanned, SyntaxShape, Type, Value, Spanned, SyntaxShape, Type, Value,
}; };
use std::{collections::HashMap, fmt::Write}; use std::{collections::HashMap, fmt::Write};
use terminal_size::{Height, Width};
pub fn get_full_help( pub fn get_full_help(
command: &dyn Command, command: &dyn Command,
@ -234,6 +235,14 @@ fn get_documentation(
} }
} }
fn get_term_width() -> usize {
if let Some((Width(w), Height(_))) = terminal_size::terminal_size() {
w as usize
} else {
80
}
}
if !is_parser_keyword && !sig.input_output_types.is_empty() { if !is_parser_keyword && !sig.input_output_types.is_empty() {
if let Some(decl_id) = engine_state.find_decl(b"table", &[]) { if let Some(decl_id) = engine_state.find_decl(b"table", &[]) {
// FIXME: we may want to make this the span of the help command in the future // FIXME: we may want to make this the span of the help command in the future
@ -256,7 +265,18 @@ fn get_documentation(
&Call { &Call {
decl_id, decl_id,
head: span, head: span,
arguments: vec![], arguments: vec![Argument::Named((
Spanned {
item: "width".to_string(),
span: Span::unknown(),
},
None,
Some(Expression::new_unknown(
Expr::Int(get_term_width() as i64 - 2), // padding, see below
Span::unknown(),
Type::Int,
)),
))],
parser_info: HashMap::new(), parser_info: HashMap::new(),
}, },
PipelineData::Value(Value::list(vals, span), None), PipelineData::Value(Value::list(vals, span), None),
@ -334,6 +354,19 @@ fn get_documentation(
None, None,
)) ))
} }
table_call.add_named((
Spanned {
item: "expand".to_string(),
span: Span::unknown(),
},
None,
Some(Expression::new_unknown(
Expr::Int(get_term_width() as i64 - 2),
Span::unknown(),
Type::Int,
)),
));
let table = engine_state let table = engine_state
.find_decl("table".as_bytes(), &[]) .find_decl("table".as_bytes(), &[])
.and_then(|decl_id| { .and_then(|decl_id| {