Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflicts #1

Merged
merged 36 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ed93baf
fixed tests
Sakapoi Aug 12, 2024
3b2283c
Merge pull request #1429 from Sakapoi/former_fix
Wandalen Aug 13, 2024
76f4042
Format tools experiment 1 (#1431)
Wandalen Aug 13, 2024
3db5943
Merge pull request #1367 from Wandalen/alpha
Wandalen Aug 20, 2024
b13e9e3
Merge pull request #1439 from Wandalen/alpha
Wandalen Aug 29, 2024
2cf4f77
Merge remote-tracking branch 'main_repo/master' into beta
Sakapoi Aug 29, 2024
ce9d675
Merge pull request #1441 from Sakapoi/new_master_merge
Wandalen Aug 30, 2024
9ae6281
Merge pull request #1436 from Wandalen/beta
Wandalen Aug 30, 2024
857016f
READY: (willbe): Add Test for Emulation of Publication Sequence (#1481)
Barsik-sus Nov 8, 2024
ef63270
NOT READY : Assistant: OpenAI (#1478)
InAnYan Nov 8, 2024
e54ed4f
.
Wandalen Nov 8, 2024
e9e56b3
Merge branch 'alpha' into refactoring_4
Wandalen Nov 8, 2024
4c17fa5
assistant : newer version of dependency
Wandalen Nov 10, 2024
9beca47
test_tools : standalone mem_tools
Wandalen Nov 10, 2024
e33a2b7
Merge pull request #1483 from Wandalen/refactoring_4
Wandalen Nov 11, 2024
c055473
Fix assistant (#1484)
InAnYan Nov 11, 2024
9370621
Fix for `format_tools` for overflow subtract (#1490)
InAnYan Nov 14, 2024
5b52e5f
publishing deterministic_rand
Wandalen Nov 15, 2024
d3bf267
READY : Continue work on assistant (#1489)
InAnYan Nov 18, 2024
ea86324
READY : `format_tools`: limit table width (#1494)
InAnYan Nov 22, 2024
3620512
READY : `format_tools` - alternative API function (#1496)
InAnYan Nov 22, 2024
9f6ec87
READY : Agents framework design draft (#1488)
InAnYan Nov 22, 2024
d762865
READY : `format_tools` test for dyn. container of dyn. struct (#1497)
InAnYan Nov 22, 2024
039445d
Add maximum table width to assistants CLI (#1499)
InAnYan Dec 2, 2024
4330d03
NOT READY : Agents implementation (#1498)
InAnYan Dec 3, 2024
2e7e3de
READY : Test task Google Sheets CLI (#1495)
sevabakutov Dec 3, 2024
f8ab967
READY : Agents (#1500)
InAnYan Dec 3, 2024
958c514
Remove doc comment (#1502)
InAnYan Dec 4, 2024
2d5382e
Add documentation to `format_tools` (#1501)
InAnYan Dec 4, 2024
7e9afae
READY: Fix module/core/process_tools/src/process.rs (#1508)
sevabakutov Dec 4, 2024
8fdf362
dependecies fix (#1509)
sevabakutov Dec 4, 2024
39907f7
READY: (wca): qqq (#1492)
Barsik-sus Dec 4, 2024
40f5e25
Fix gspread error handling (#1512)
sevabakutov Dec 11, 2024
9c2cbf4
secret description fixed (#1510)
sevabakutov Dec 11, 2024
b0f9911
NOT READY: (willbe): `qqq` processing (#1511)
Barsik-sus Dec 11, 2024
0567562
Merge branch 'alpha' of github.com:Barsik-sus/wTools into willbe_fix
Barsik-sus Dec 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ version = "~0.2.0"
path = "module/move/sqlx_query"

[workspace.dependencies.deterministic_rand]
version = "~0.5.0"
version = "~0.6.0"
path = "module/move/deterministic_rand"

[workspace.dependencies.crates_tools]
Expand Down
1 change: 0 additions & 1 deletion module/core/diagnostics_tools/src/diag/rta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,3 @@ pub mod prelude
};

}

3 changes: 0 additions & 3 deletions module/core/diagnostics_tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ pub mod own
#[ doc( inline ) ]
pub use orphan::*;
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use super::diag::orphan::*;
}

Expand All @@ -54,7 +53,6 @@ pub mod exposed
#[ doc( inline ) ]
pub use prelude::*;
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use super::diag::exposed::*;
}

Expand All @@ -65,6 +63,5 @@ pub mod prelude
{
use super::*;
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use super::diag::prelude::*;
}
4 changes: 4 additions & 0 deletions module/core/format_tools/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ pub mod string;
pub mod table;
pub mod to_string;
pub mod to_string_with_fallback;
pub mod text_wrap;

/// A strucutre for diagnostic and demonstration purpose.
#[ doc( hidden ) ]
Expand Down Expand Up @@ -317,6 +318,7 @@ pub mod own
table::orphan::*,
to_string::orphan::*,
to_string_with_fallback::orphan::*,
text_wrap::orphan::*,
};

}
Expand Down Expand Up @@ -369,6 +371,7 @@ pub mod exposed
table::exposed::*,
to_string::exposed::*,
to_string_with_fallback::exposed::*,
text_wrap::exposed::*,
};

}
Expand All @@ -391,6 +394,7 @@ pub mod prelude
table::prelude::*,
to_string::prelude::*,
to_string_with_fallback::prelude::*,
text_wrap::prelude::*,
};

}
14 changes: 7 additions & 7 deletions module/core/format_tools/src/format/as_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ mod private
)
where
RowKey : table::RowKey,
Row : Cells< CellKey>,
Row : Cells< CellKey >,
CellKey : table::CellKey + ?Sized,
// CellRepr : table::CellRepr
;
Expand All @@ -41,7 +41,7 @@ mod private
AsTable< 'table, Table, RowKey, Row, CellKey>
where
RowKey : table::RowKey,
Row : Cells< CellKey>,
Row : Cells< CellKey >,
CellKey : table::CellKey + ?Sized,
// CellRepr : table::CellRepr,
{
Expand All @@ -56,7 +56,7 @@ mod private
for AsTable< 'table, Table, RowKey, Row, CellKey>
where
RowKey : table::RowKey,
Row : Cells< CellKey>,
Row : Cells< CellKey >,
CellKey : table::CellKey + ?Sized,
// CellRepr : table::CellRepr,
{
Expand All @@ -70,7 +70,7 @@ mod private
for AsTable< 'table, Table, RowKey, Row, CellKey>
where
RowKey : table::RowKey,
Row : Cells< CellKey>,
Row : Cells< CellKey >,
CellKey : table::CellKey + ?Sized,
// CellRepr : table::CellRepr,
{
Expand All @@ -86,7 +86,7 @@ mod private
for AsTable< 'table, Table, RowKey, Row, CellKey>
where
RowKey : table::RowKey,
Row : Cells< CellKey>,
Row : Cells< CellKey >,
CellKey : table::CellKey + ?Sized,
// CellRepr : table::CellRepr,
{
Expand All @@ -101,7 +101,7 @@ mod private
where
Table : fmt::Debug,
RowKey : table::RowKey,
Row : Cells< CellKey>,
Row : Cells< CellKey >,
CellKey : table::CellKey + ?Sized,
// CellRepr : table::CellRepr,
{
Expand Down Expand Up @@ -146,7 +146,7 @@ mod private
for AsTable< 'table, Table, RowKey, Row, CellKey>
where
RowKey : table::RowKey,
Row : Cells< CellKey>,
Row : Cells< CellKey >,
CellKey : table::CellKey + ?Sized,
// CellRepr : table::CellRepr,
Self : Copy,
Expand Down
33 changes: 33 additions & 0 deletions module/core/format_tools/src/format/output_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
mod private
{

use std::borrow::Cow;

use crate::*;
use print::
{
Expand Down Expand Up @@ -78,6 +80,36 @@ mod private
}
}

/// Print table, which is constructed with vectors and `Cow`s, with the
/// specified output formatter.
///
/// This function is useful when you do not want to use `AsTable`, or implement `Fields`, and
/// other traits, but you just have string slices in vectors.
///
/// `rows` should not contain header of the table, it will be automatically added if `has_header`
/// is true.
pub fn vector_table_write< 'data, 'context >
(
column_names : Vec< Cow< 'data, str > >,
has_header : bool,
rows : Vec< Vec< Cow< 'data, str > > >,
c : &mut Context< 'context >,
) -> fmt::Result
{
InputExtract::extract_from_raw_table
(
column_names,
has_header,
rows,
c.printer.filter_col,
c.printer.filter_row,
| x |
{
c.printer.output_format.extract_write( x, c )
}
)
}

}

mod table;
Expand Down Expand Up @@ -106,6 +138,7 @@ pub mod own
#[ doc( inline ) ]
pub use private::
{
vector_table_write,
};

}
Expand Down
122 changes: 82 additions & 40 deletions module/core/format_tools/src/format/output_format/records.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
//!

use crate::*;
use md_math::MdOffset;
use print::
{
InputExtract,
Context,
};
use std::borrow::Cow;
use core::
{
fmt,
Expand Down Expand Up @@ -59,6 +59,8 @@ pub struct Records
pub cell_postfix : String,
/// Separator used between table columns.
pub cell_separator : String,
/// Limit table width. If the value is zero, then no limitation.
pub max_width: usize,
// /// Horizontal line character.
// pub h : char,
// /// Vertical line character.
Expand Down Expand Up @@ -91,6 +93,25 @@ impl Records
static INSTANCE : OnceLock< Records > = OnceLock::new();
INSTANCE.get_or_init( || Records::default() )
}

/// Calculate how much space is minimally needed in order to generate an output with this output formatter.
/// It will be impossible to render tables smaller than the result of `min_width()`.
///
/// This function is similar to `output_format::Table::min_width`, but it does not contain a
/// `column_count` as it always equal to 2, and it aslo uses the `output_format::Records`
/// style parameters.
pub fn min_width
(
&self,
) -> usize
{
// 2 is used here, because `Records` displays 2 columns: keys and values.
self.row_prefix.chars().count()
+ self.row_postfix.chars().count()
+ 2 * ( self.cell_postfix.chars().count() + self.cell_prefix.chars().count() )
+ self.cell_separator.chars().count()
+ 2
}
}

impl Default for Records
Expand All @@ -108,6 +129,8 @@ impl Default for Records
let table_postfix = "".to_string();
let table_separator = "\n".to_string();

let max_width = 0;

// let h = '─';
// let v = '|';
// let t_l = '├';
Expand All @@ -131,6 +154,7 @@ impl Default for Records
cell_prefix,
cell_postfix,
cell_separator,
max_width,
// h,
// v,
// t_l,
Expand All @@ -155,70 +179,88 @@ impl TableOutputFormat for Records
c : & mut Context< 'buf >,
) -> fmt::Result
{
use format::text_wrap::{ text_wrap, width_calculate };

if self.max_width != 0 && self.max_width < self.min_width()
{
return Err( fmt::Error );
}

// 2 because there are only 2 columns: key and value.
let columns_max_width = if self.max_width == 0 { 0 } else { self.max_width - self.min_width() + 2 };

let label_width = x.header().fold( 0, | acc, cell | acc.max( cell.1[ 0 ] ) );
let keys : Vec< ( Cow< 'data, str >, [ usize; 2 ] ) > = x.header().collect();
let keys_width = width_calculate( &keys );

write!( c.buf, "{}", self.table_prefix )?;

let mut first = true;
// Write each record
for ( irow, row ) in x.rows()
{
let mut printed_tables_count = 0;

if !row.vis
for ( itable_descriptor, table_descriptor ) in x.row_descriptors.iter().enumerate()
{
if !table_descriptor.vis || ( x.has_header && itable_descriptor == 0 )
{
continue;
}

if first
{
first = false;
}
else
if printed_tables_count > 0
{
write!( c.buf, "{}", self.table_separator )?;
}

let slice_width = x.data[ irow ].iter().fold( 0, | acc, cell | acc.max( cell.1[ 0 ] ) );
printed_tables_count += 1;

writeln!( c.buf, " = {}", table_descriptor.irow )?;

writeln!( c.buf, " = {}", irow )?;
let values = &x.data[ itable_descriptor ];
let values_width = width_calculate( &values );

for ( icol, _col ) in x.col_descriptors.iter().enumerate()
let table_for_wrapping : Vec< Vec< ( Cow< 'data, str >, [ usize; 2] ) > > =
keys.iter().enumerate().map( | ( ikey, key ) |
{
let cell = &x.data[ irow ][ icol ];
let height = cell.1[ 1 ];
vec![ key.clone(), values[ ikey ].clone() ]
}).collect();

for islice in 0..height
let wrapped_text = text_wrap
(
table_for_wrapping.iter(),
&[ keys_width, values_width ],
columns_max_width,
keys_width + values_width,
);

for ( irow, cols ) in wrapped_text.data.into_iter().enumerate()
{
if irow != 0
{
let label = x.header_slice( islice, icol );
let md_index = [ islice, icol, irow ];
let slice = x.slices[ x.slices_dim.md_offset( md_index ) ];

if icol > 0 || islice > 0
{
write!( c.buf, "{}", self.row_separator )?;
}

write!( c.buf, "{}", self.row_prefix )?;

write!( c.buf, "{}", self.cell_prefix )?;
write!( c.buf, "{:<label_width$}", label )?;
write!( c.buf, "{}", self.cell_postfix )?;
write!( c.buf, "{}", self.cell_separator )?;
write!( c.buf, "{}", self.cell_prefix )?;
write!( c.buf, "{:<slice_width$}", slice )?;
write!( c.buf, "{}", self.cell_postfix )?;

write!( c.buf, "{}", self.row_postfix )?;
write!( c.buf, "{}", self.row_separator )?;
}

}
let key = &cols[ 0 ];
let value = &cols[ 1 ];

let key_width = wrapped_text.column_widthes[ 0 ];
let value_width = wrapped_text.column_widthes[ 1 ];

write!( c.buf, "{}", self.row_prefix )?;

write!( c.buf, "{}", self.cell_prefix )?;
write!( c.buf, "{:<key_width$}", key.content )?;
write!( c.buf, "{}", self.cell_postfix )?;
write!( c.buf, "{}", self.cell_separator )?;
write!( c.buf, "{}", self.cell_prefix )?;
// No need to use `wrap_width` of `WrappedCell`, as `output_format::Records`
// does not center values in cells (they are always left aligned).
write!( c.buf, "{:<value_width$}", value.content )?;
write!( c.buf, "{}", self.cell_postfix )?;

write!( c.buf, "{}", self.row_postfix )?;
}
}

write!( c.buf, "{}", self.table_postfix )?;

Ok(())
Ok( () )
}

}
Loading