@@ -4,20 +4,35 @@ use chewing::dictionary::{Dictionary, SystemDictionaryLoader, UserDictionaryLoad
4
4
use crate :: flags;
5
5
6
6
pub ( crate ) fn run ( args : flags:: Info ) -> Result < ( ) > {
7
- let mut dictionaries = vec ! [ ] ;
8
- if args. user {
9
- dictionaries. push ( UserDictionaryLoader :: new ( ) . load ( ) ?) ;
10
- }
11
7
if args. system {
12
- dictionaries. extend ( SystemDictionaryLoader :: new ( ) . load ( ) ?) ;
8
+ let dictionaries = SystemDictionaryLoader :: new ( ) . load ( ) ?;
9
+ if args. json {
10
+ print_json_info ( & dictionaries, "base" ) ;
11
+ } else {
12
+ print_info ( & dictionaries, "base" ) ;
13
+ }
14
+ let extra = SystemDictionaryLoader :: new ( ) . load_extra ( ) ?;
15
+ if args. json {
16
+ print_json_info ( & extra, "extra" ) ;
17
+ } else {
18
+ print_info ( & extra, "extra" ) ;
19
+ }
13
20
}
14
- if let Some ( path) = args. path {
15
- dictionaries. push ( UserDictionaryLoader :: new ( ) . userphrase_path ( path) . load ( ) ?) ;
21
+ if args. user {
22
+ let dict = UserDictionaryLoader :: new ( ) . load ( ) ?;
23
+ if args. json {
24
+ print_json_info ( & [ dict] , "user" ) ;
25
+ } else {
26
+ print_info ( & [ dict] , "user" ) ;
27
+ }
16
28
}
17
- if args. json {
18
- print_json_info ( & dictionaries) ;
19
- } else {
20
- print_info ( & dictionaries) ;
29
+ if let Some ( path) = args. path {
30
+ let dict = UserDictionaryLoader :: new ( ) . userphrase_path ( path) . load ( ) ?;
31
+ if args. json {
32
+ print_json_info ( & [ dict] , "input" ) ;
33
+ } else {
34
+ print_info ( & [ dict] , "input" ) ;
35
+ }
21
36
}
22
37
Ok ( ( ) )
23
38
}
@@ -39,7 +54,7 @@ fn escape_json(str: String) -> String {
39
54
out
40
55
}
41
56
42
- fn print_json_info ( dictionaries : & [ Box < dyn Dictionary > ] ) {
57
+ fn print_json_info ( dictionaries : & [ Box < dyn Dictionary > ] , from : & str ) {
43
58
let mut iter = dictionaries. iter ( ) . peekable ( ) ;
44
59
println ! ( "[" ) ;
45
60
while let Some ( dict) = iter. next ( ) {
@@ -49,6 +64,7 @@ fn print_json_info(dictionaries: &[Box<dyn Dictionary>]) {
49
64
. unwrap_or ( String :: new ( ) ) ;
50
65
let info = dict. about ( ) ;
51
66
println ! ( " {{" ) ;
67
+ println ! ( r#" "from": "{from}","# ) ;
52
68
println ! ( r#" "path": "{}","# , escape_json( path) ) ;
53
69
println ! ( r#" "name": "{}","# , escape_json( info. name) ) ;
54
70
println ! ( r#" "version": "{}","# , escape_json( info. version) ) ;
@@ -60,14 +76,15 @@ fn print_json_info(dictionaries: &[Box<dyn Dictionary>]) {
60
76
println ! ( "]" ) ;
61
77
}
62
78
63
- fn print_info ( dictionaries : & [ Box < dyn Dictionary > ] ) {
79
+ fn print_info ( dictionaries : & [ Box < dyn Dictionary > ] , from : & str ) {
64
80
for dict in dictionaries {
65
81
let path = dict
66
82
. path ( )
67
83
. map ( |p| p. display ( ) . to_string ( ) )
68
84
. unwrap_or ( String :: new ( ) ) ;
69
85
let info = dict. about ( ) ;
70
86
println ! ( "---" ) ;
87
+ println ! ( "From : {from}" ) ;
71
88
println ! ( "Path : {}" , path) ;
72
89
println ! ( "Name : {}" , info. name) ;
73
90
println ! ( "Version : {}" , info. version) ;
0 commit comments