11use std:: str:: FromStr ;
22
33use mlua:: { ExternalError , FromLua , IntoLua , Lua , Value } ;
4- use yazi_fs:: SortBy ;
4+ use yazi_fs:: { SortBy , SortBys } ;
55use yazi_shared:: event:: CmdCow ;
66
77#[ derive( Debug , Default ) ]
88pub struct SortOpt {
9- pub by : Option < Vec < SortBy > > ,
9+ pub by : Option < SortBys > ,
1010 pub reverse : Option < bool > ,
1111 pub dir_first : Option < bool > ,
1212 pub sensitive : Option < bool > ,
@@ -17,9 +17,11 @@ impl TryFrom<CmdCow> for SortOpt {
1717 type Error = anyhow:: Error ;
1818
1919 fn try_from ( c : CmdCow ) -> Result < Self , Self :: Error > {
20+ let by =
21+ ( 0 ..) . map_while ( |i| c. str ( i) ) . map ( SortBy :: from_str) . collect :: < Result < Vec < SortBy > , _ > > ( ) ?;
22+
2023 Ok ( Self {
21- // TODO(SuniRein): multiple sort by methods
22- by : c. first_str ( ) . map ( SortBy :: from_str) . transpose ( ) ?. map ( |v| vec ! [ v] ) ,
24+ by : if by. is_empty ( ) { None } else { Some ( SortBys ( by) ) } ,
2325 reverse : c. maybe_bool ( "reverse" ) ,
2426 dir_first : c. maybe_bool ( "dir-first" ) ,
2527 sensitive : c. maybe_bool ( "sensitive" ) ,
0 commit comments