mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 14:40:06 +02:00
Add command_prelude
module (#12291)
# Description When implementing a `Command`, one must also import all the types present in the function signatures for `Command`. This makes it so that we often import the same set of types in each command implementation file. E.g., something like this: ```rust use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ record, Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, ShellError, Signature, Span, Type, Value, }; ``` This PR adds the `nu_engine::command_prelude` module which contains the necessary and commonly used types to implement a `Command`: ```rust // command_prelude.rs pub use crate::CallExt; pub use nu_protocol::{ ast::{Call, CellPath}, engine::{Command, EngineState, Stack}, record, Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, IntoSpanned, PipelineData, Record, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value, }; ``` This should reduce the boilerplate needed to implement a command and also gives us a place to track the breadth of the `Command` API. I tried to be conservative with what went into the prelude modules, since it might be hard/annoying to remove items from the prelude in the future. Let me know if something should be included or excluded.
This commit is contained in:
@ -1,10 +1,8 @@
|
||||
use nu_color_config::{Alignment, StyleComputer, TextStyle};
|
||||
use nu_protocol::{Config, FooterMode, ShellError, Span, Value};
|
||||
use nu_protocol::{TableMode, TrimStrategy};
|
||||
|
||||
use crate::{
|
||||
clean_charset, colorize_space_str, string_wrap, NuTableConfig, TableOutput, TableTheme,
|
||||
};
|
||||
use nu_color_config::{Alignment, StyleComputer, TextStyle};
|
||||
use nu_protocol::{Config, FooterMode, ShellError, Span, TableMode, TrimStrategy, Value};
|
||||
|
||||
pub type NuText = (String, TextStyle);
|
||||
pub type TableResult = Result<Option<TableOutput>, ShellError>;
|
||||
|
@ -3,8 +3,7 @@ use nu_ansi_term::Style;
|
||||
use nu_color_config::TextStyle;
|
||||
use nu_protocol::TrimStrategy;
|
||||
use nu_utils::strip_ansi_unlikely;
|
||||
use std::cmp::min;
|
||||
use std::collections::HashMap;
|
||||
use std::{cmp::min, collections::HashMap};
|
||||
use tabled::{
|
||||
builder::Builder,
|
||||
grid::{
|
||||
|
@ -1,14 +1,10 @@
|
||||
use crate::{
|
||||
common::{get_index_style, load_theme, nu_value_to_string_clean},
|
||||
StringResult, TableOpts, UnstructuredTable,
|
||||
};
|
||||
use nu_color_config::StyleComputer;
|
||||
use nu_protocol::{Config, Record, TableMode, Value};
|
||||
|
||||
use crate::UnstructuredTable;
|
||||
|
||||
use crate::common::nu_value_to_string_clean;
|
||||
use crate::{
|
||||
common::{get_index_style, load_theme},
|
||||
StringResult, TableOpts,
|
||||
};
|
||||
|
||||
pub struct CollapsedTable;
|
||||
|
||||
impl CollapsedTable {
|
||||
|
@ -1,11 +1,3 @@
|
||||
use std::cmp::max;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use nu_color_config::{Alignment, StyleComputer, TextStyle};
|
||||
use nu_engine::column::get_columns;
|
||||
use nu_protocol::{Config, Record, ShellError, Span, Value};
|
||||
use tabled::grid::config::Position;
|
||||
|
||||
use crate::{
|
||||
common::{
|
||||
create_nu_table_config, error_sign, get_header_style, get_index_style, load_theme,
|
||||
@ -16,6 +8,11 @@ use crate::{
|
||||
types::has_index,
|
||||
NuTable, NuTableCell, TableOpts, TableOutput,
|
||||
};
|
||||
use nu_color_config::{Alignment, StyleComputer, TextStyle};
|
||||
use nu_engine::column::get_columns;
|
||||
use nu_protocol::{Config, Record, ShellError, Span, Value};
|
||||
use std::{cmp::max, collections::HashMap};
|
||||
use tabled::grid::config::Position;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ExpandedTable {
|
||||
|
@ -1,7 +1,4 @@
|
||||
use nu_color_config::TextStyle;
|
||||
use nu_engine::column::get_columns;
|
||||
use nu_protocol::{Config, Record, ShellError, Value};
|
||||
|
||||
use super::has_index;
|
||||
use crate::{
|
||||
clean_charset, colorize_space,
|
||||
common::{
|
||||
@ -10,8 +7,9 @@ use crate::{
|
||||
},
|
||||
NuTable, NuTableCell, StringResult, TableOpts, TableOutput, TableResult,
|
||||
};
|
||||
|
||||
use super::has_index;
|
||||
use nu_color_config::TextStyle;
|
||||
use nu_engine::column::get_columns;
|
||||
use nu_protocol::{Config, Record, ShellError, Value};
|
||||
|
||||
pub struct JustTable;
|
||||
|
||||
|
@ -2,15 +2,14 @@ mod collapse;
|
||||
mod expanded;
|
||||
mod general;
|
||||
|
||||
use std::sync::{atomic::AtomicBool, Arc};
|
||||
|
||||
pub use collapse::CollapsedTable;
|
||||
pub use expanded::ExpandedTable;
|
||||
pub use general::JustTable;
|
||||
use nu_color_config::StyleComputer;
|
||||
use nu_protocol::{Config, Span, TableIndexMode, TableMode};
|
||||
|
||||
use crate::{common::INDEX_COLUMN_NAME, NuTable};
|
||||
use nu_color_config::StyleComputer;
|
||||
use nu_protocol::{Config, Span, TableIndexMode, TableMode};
|
||||
use std::sync::{atomic::AtomicBool, Arc};
|
||||
|
||||
pub struct TableOutput {
|
||||
pub table: NuTable,
|
||||
|
@ -1,3 +1,4 @@
|
||||
use crate::{string_width, string_wrap, TableTheme};
|
||||
use nu_color_config::StyleComputer;
|
||||
use nu_protocol::{Config, Record, Span, Value};
|
||||
use tabled::{
|
||||
@ -10,8 +11,6 @@ use tabled::{
|
||||
tables::{PoolTable, TableValue},
|
||||
};
|
||||
|
||||
use crate::{string_width, string_wrap, TableTheme};
|
||||
|
||||
/// UnstructuredTable has a recursive table representation of nu_protocol::Value.
|
||||
///
|
||||
/// It doesn't support alignment and a proper width control.
|
||||
|
@ -1,9 +1,8 @@
|
||||
mod common;
|
||||
|
||||
use common::{create_row, test_table, TestCase};
|
||||
use nu_protocol::TrimStrategy;
|
||||
use nu_table::{NuTable, NuTableConfig, TableTheme as theme};
|
||||
|
||||
use common::{create_row, test_table, TestCase};
|
||||
use tabled::grid::records::vec_records::CellInfo;
|
||||
|
||||
#[test]
|
||||
|
Reference in New Issue
Block a user