summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2021-08-20 19:57:11 -0700
committerGitHub <noreply@github.com>2021-08-20 19:57:11 -0700
commit2c0b35f89cc00073ee0cca1aa8e4d629bb3be1e7 (patch)
tree2817034b04c356e69a4098ab9dae867b2ea33f2b /src/main.rs
parent130b0b6a2146d4b42be6f8cfeda4d120e65576f2 (diff)
Refactoring for #693 (#696)
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/main.rs b/src/main.rs
index 1b77808f..3fb223e2 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -58,7 +58,7 @@ pub mod errors {
// arguments and without standard input; 2 is used to report a real problem.
fn run_app() -> std::io::Result<i32> {
let assets = HighlightingAssets::new();
- let opt = cli::Opt::from_args_and_git_config(&mut git_config::GitConfig::try_create(), assets);
+ let opt = cli::Opt::from_args_and_git_config(git_config::GitConfig::try_create(), assets);
if opt.list_languages {
list_languages()?;
@@ -351,19 +351,17 @@ fn show_themes(dark: bool, light: bool, computed_theme_is_light: bool) -> std::i
}
};
- let mut git_config = git_config::GitConfig::try_create();
- let opt = cli::Opt::from_iter_and_git_config(
- &["", "", "--navigate", "--show-themes"],
- &mut git_config,
- );
+ let git_config = git_config::GitConfig::try_create();
+ let opt =
+ cli::Opt::from_iter_and_git_config(&["", "", "--navigate", "--show-themes"], git_config);
let mut output_type =
OutputType::from_mode(PagingMode::Always, None, &config::Config::from(opt)).unwrap();
let title_style = ansi_term::Style::new().bold();
let writer = output_type.handle().unwrap();
for theme in &get_themes(git_config::GitConfig::try_create()) {
- let opt =
- cli::Opt::from_iter_and_git_config(&["", "", "--features", theme], &mut git_config);
+ let git_config = git_config::GitConfig::try_create();
+ let opt = cli::Opt::from_iter_and_git_config(&["", "", "--features", theme], git_config);
let is_dark_theme = opt.dark;
let is_light_theme = opt.light;
let config = config::Config::from(opt);
@@ -389,7 +387,6 @@ fn show_themes(dark: bool, light: bool, computed_theme_is_light: bool) -> std::i
#[cfg(not(tarpaulin_include))]
fn show_syntax_themes() -> std::io::Result<()> {
- let mut opt = cli::Opt::from_args();
let assets = HighlightingAssets::new();
let mut output_type = OutputType::from_mode(
PagingMode::QuitIfOneScreen,
@@ -398,7 +395,6 @@ fn show_syntax_themes() -> std::io::Result<()> {
)
.unwrap();
let mut writer = output_type.handle().unwrap();
- opt.computed.syntax_set = assets.syntax_set;
let stdin_data = if !atty::is(atty::Stream::Stdin) {
let mut buf = Vec::new();
@@ -412,9 +408,16 @@ fn show_syntax_themes() -> std::io::Result<()> {
None
};
+ let make_opt = || {
+ let mut opt = cli::Opt::from_args();
+ opt.computed.syntax_set = assets.syntax_set.clone();
+ opt
+ };
+ let opt = make_opt();
+
if !(opt.dark || opt.light) {
- _show_syntax_themes(opt.clone(), false, &mut writer, stdin_data.as_ref())?;
- _show_syntax_themes(opt, true, &mut writer, stdin_data.as_ref())?;
+ _show_syntax_themes(opt, false, &mut writer, stdin_data.as_ref())?;
+ _show_syntax_themes(make_opt(), true, &mut writer, stdin_data.as_ref())?;
} else if opt.light {
_show_syntax_themes(opt, true, &mut writer, stdin_data.as_ref())?;
} else {