File tree 2 files changed +54
-1
lines changed
2 files changed +54
-1
lines changed Original file line number Diff line number Diff line change 10
10
11
11
# mock files with unique endsong data?
12
12
ex * .txt
13
+
14
+ # folder with plots generated at runtime
15
+ /plots /
Original file line number Diff line number Diff line change @@ -31,8 +31,58 @@ pub fn artist(entries: &SongEntries, art: &Artist) {
31
31
let layout = Layout :: new ( ) . title ( format ! ( "<b>{art}</b>" ) . as_str ( ) . into ( ) ) ;
32
32
plot. set_layout ( layout) ;
33
33
34
+ // creates plots/ folder
35
+ std:: fs:: create_dir_all ( "plots" ) . unwrap ( ) ;
36
+
34
37
// opens the plot in the browser
35
- plot. show ( ) ;
38
+ match std:: env:: consts:: OS {
39
+ // see https://github.com/igiagkiozis/plotly/issues/132#issuecomment-1488920563
40
+ "windows" => {
41
+ let path = format ! (
42
+ "{}\\ plots\\ {}.html" ,
43
+ std:: env:: current_dir( ) . unwrap( ) . display( ) ,
44
+ & art. name
45
+ ) ;
46
+ plot. write_html ( path. as_str ( ) ) ;
47
+ std:: process:: Command :: new ( "explorer" )
48
+ . arg ( & path)
49
+ . output ( )
50
+ . unwrap ( ) ;
51
+ }
52
+ "macos" => {
53
+ let path = format ! (
54
+ "{}/plots/{}.html" ,
55
+ std:: env:: current_dir( ) . unwrap( ) . display( ) ,
56
+ & art. name
57
+ ) ;
58
+ plot. write_html ( path. as_str ( ) ) ;
59
+ std:: process:: Command :: new ( "open" )
60
+ . arg ( & path)
61
+ . output ( )
62
+ . unwrap ( ) ;
63
+ }
64
+ _ => {
65
+ let path = format ! (
66
+ "{}/plots/{}.html" ,
67
+ std:: env:: current_dir( ) . unwrap( ) . display( ) ,
68
+ & art. name
69
+ ) ;
70
+ plot. write_html ( path. as_str ( ) ) ;
71
+
72
+ // https://doc.rust-lang.org/book/ch12-05-working-with-environment-variables.html
73
+ match std:: env:: var ( "BROWSER" ) {
74
+ Ok ( browser) => {
75
+ std:: process:: Command :: new ( & browser)
76
+ . arg ( & path)
77
+ . output ( )
78
+ . unwrap ( ) ;
79
+ }
80
+ Err ( _) => {
81
+ eprintln ! ( "Your BROWSER environmental variable is not set!" ) ;
82
+ }
83
+ }
84
+ }
85
+ } ;
36
86
}
37
87
38
88
/// Used by [`artist()`] to get the dates of all of its occurrence
You can’t perform that action at this time.
0 commit comments