@@ -8,23 +8,18 @@ mod range;
88mod watermark;
99mod window;
1010
11- use std:: fs;
1211use std:: fs:: read_to_string;
13- use std:: path:: Path ;
1412
1513use anyhow:: bail;
1614use clap:: value_parser;
1715use clap:: Parser ;
1816use code:: create_code;
1917use code_config:: create_code_config;
20- use codesnap:: assets:: Assets ;
21- use codesnap:: assets:: AssetsURL ;
2218use codesnap:: config:: CodeSnap ;
2319use codesnap:: config:: SnapshotConfig ;
24- use codesnap:: utils :: path :: parse_home_variable ;
20+ use codesnap:: themes :: parse_code_theme ;
2521use config:: CodeSnapCLIConfig ;
2622use egg:: say;
27- use theme_converter:: { parser:: Parser as ThemeParser , vscode} ;
2823use watermark:: create_watermark;
2924use window:: create_window;
3025
@@ -33,7 +28,7 @@ use std::time::Duration;
3328
3429use indicatif:: { ProgressBar , ProgressStyle } ;
3530
36- pub const STDIN_CODE_DEFAULT_CHAR : & ' static str = "-" ;
31+ pub const STDIN_CODE_DEFAULT_CHAR : & str = "-" ;
3732
3833/// CodeSnap is a CLI tool to generate beautiful snapshots of your code from terminal.
3934#[ derive( Parser ) ]
@@ -275,78 +270,37 @@ fn output_snapshot(cli: &CLI, snapshot: &SnapshotConfig) -> anyhow::Result<Strin
275270}
276271
277272async fn generate_snapshot_with_config ( cli : & CLI , codesnap : CodeSnap ) -> anyhow:: Result < ( ) > {
278- let snapshot = create_snapshot_config ( & cli, codesnap) . await ?;
273+ let snapshot = create_snapshot_config ( cli, codesnap) . await ?;
279274 let snapshot_type = cli. r#type . clone ( ) ;
280275
281276 if snapshot_type == "ascii" && cli. output != "clipboard" {
282277 logger:: warn ( "ASCII snapshot only supports copying to clipboard" ) ;
283278 return Ok ( ( ) ) ;
284279 }
285280
286- let message = with_spinner ( || output_snapshot ( & cli, & snapshot) ) ?;
281+ let message = with_spinner ( || output_snapshot ( cli, & snapshot) ) ?;
287282
288283 logger:: success ( & message) ;
289284
290285 Ok ( ( ) )
291286}
292287
293- // If the code theme is URL, download it and return the path
294- async fn parse_code_theme ( path : & str , code_theme : & str ) -> anyhow:: Result < String > {
295- let assets_url = AssetsURL :: from_url ( code_theme) ;
296-
297- match assets_url {
298- Ok ( assets_url) => {
299- let assets = Assets :: from ( path) ;
300- let assets_store_path_str = assets. download ( code_theme) . await ?;
301- let assets_store_path = Path :: new ( & assets_store_path_str) ;
302- let extension = assets_store_path. extension ( ) . unwrap_or_default ( ) ;
303-
304- // If the code theme is JSON file, we treat it as a VSCode theme file
305- if extension == "json" {
306- let root = vscode:: VSCodeThemeParser :: from_config ( & assets_store_path_str)
307- . unwrap ( )
308- . parse ( & assets_url. name ) ;
309- let path = Path :: new ( & assets_store_path)
310- . with_file_name ( format ! ( "{}.{}" , & assets_url. name, "tmTheme" ) ) ;
311-
312- plist:: to_writer_xml ( & mut fs:: File :: create ( path) . unwrap ( ) , & root) ?;
313- }
314-
315- Ok ( assets_url. name )
316- }
317- Err ( _) => {
318- // If the code theme is not a URL, we will use it as a local file
319- Ok ( code_theme. to_string ( ) )
320- }
321- }
322- }
323-
324288async fn create_snapshot_config (
325289 cli : & CLI ,
326290 mut codesnap : CodeSnap ,
327291) -> anyhow:: Result < SnapshotConfig > {
328292 // Build screenshot config
329293 let mut codesnap = codesnap
330- . map_code_config ( |code_config| create_code_config ( & cli, code_config) ) ?
331- . map_code ( |raw_code| create_code ( & cli, raw_code) ) ?
332- . map_watermark ( |watermark| create_watermark ( & cli, watermark) ) ?
333- . map_window ( |window| create_window ( & cli, window) ) ?
294+ . map_code_config ( |code_config| create_code_config ( cli, code_config) ) ?
295+ . map_code ( |raw_code| create_code ( cli, raw_code) ) ?
296+ . map_watermark ( |watermark| create_watermark ( cli, watermark) ) ?
297+ . map_window ( |window| create_window ( cli, window) ) ?
334298 . scale_factor ( cli. scale_factor )
335299 . build ( ) ?;
336300
337- let mut themes_folders = codesnap. themes_folders ;
338- let remote_themes_path = parse_home_variable ( "~/.config/CodeSnap/remote_themes" ) ?;
339-
340- std:: fs:: create_dir_all ( & remote_themes_path) ?;
341- // The remote themes folder is used to store the themes downloaded from the internet
342- themes_folders. push ( remote_themes_path. clone ( ) ) ;
343-
344- codesnap. themes_folders = themes_folders;
345- codesnap. fonts_folders = codesnap. fonts_folders ;
346301 codesnap. line_number_color = cli. line_number_color . clone ( ) ;
347302 codesnap. title = cli. title . clone ( ) ;
348303 codesnap. theme = parse_code_theme (
349- & remote_themes_path,
350304 cli. code_theme
351305 . clone ( )
352306 . unwrap_or ( codesnap. theme . clone ( ) )
0 commit comments