@@ -30,6 +30,8 @@ mod terminal;
31use std::collections::HashSet;
31use std::collections::HashSet;
32use std::io;
32use std::io;
33use std::path::Path;
35use std::path::Path;
34use std::process;
36use std::process;
@@ -80,13 +82,13 @@ fn run_cache_subcommand(matches: &clap::ArgMatches) -> Result<()> {
80 } else if matches.is_present("clear") {
82 } else if matches.is_present("clear") {
81 clear_assets();
83 clear_assets();
82 } else if matches.is_present("config-dir") {
84 } else if matches.is_present("config-dir") {
83− println!("{}", config_dir());
85+ writeln!(stdout(), "{}", config_dir())?;
89−pub fn list_languages(assets: &HighlightingAssets, term_width: usize) {
91+pub fn list_languages(assets: &HighlightingAssets, term_width: usize) -> Result<()> {
90 let mut languages = assets
92 let mut languages = assets
91 .syntax_set
93 .syntax_set
92 .syntaxes()
94 .syntaxes()
@@ -107,7 +109,13 @@ pub fn list_languages(assets: &HighlightingAssets, term_width: usize) {
107 let desired_width = term_width - longest - separator.len();
109 let desired_width = term_width - longest - separator.len();
109 for lang in languages {
111 for lang in languages {
110− print!("{:width$}{}", lang.name, separator, width = longest);
117+ width = longest
112 // Number of characters on this line so far, wrap before `desired_width`
120 // Number of characters on this line so far, wrap before `desired_width`
113 let mut num_chars = 0;
121 let mut num_chars = 0;
@@ -118,20 +126,22 @@ pub fn list_languages(assets: &HighlightingAssets, term_width: usize) {
118 let new_chars = word.len() + comma_separator.len();
126 let new_chars = word.len() + comma_separator.len();
119 if num_chars + new_chars >= desired_width {
127 if num_chars + new_chars >= desired_width {
120 num_chars = 0;
128 num_chars = 0;
121− print!("\n{:width$}{}", "", separator, width = longest);
129+ write!(stdout(), "\n{:width$}{}", "", separator, width = longest)?;
124 num_chars += new_chars;
132 num_chars += new_chars;
125− print!("{}", Green.paint(&word[..]));
133+ write!(stdout(), "{}", Green.paint(&word[..]))?;
126 if extension.peek().is_some() {
134 if extension.peek().is_some() {
127− print!("{}", comma_separator);
135+ write!(stdout(), "{}", comma_separator)?;
130− println!();
138+ writeln!(stdout())?;
134−pub fn list_themes(assets: &HighlightingAssets, cfg: &Config) {
144+pub fn list_themes(assets: &HighlightingAssets, cfg: &Config) -> Result<()> {
135 let themes = &assets.theme_set.themes;
145 let themes = &assets.theme_set.themes;
136 let mut config = cfg.clone();
146 let mut config = cfg.clone();
137 let mut style = HashSet::new();
147 let mut style = HashSet::new();
@@ -139,11 +149,17 @@ pub fn list_themes(assets: &HighlightingAssets, cfg: &Config) {
139 config.files = vec![InputFile::ThemePreviewFile];
149 config.files = vec![InputFile::ThemePreviewFile];
140 config.output_components = OutputComponents(style);
150 config.output_components = OutputComponents(style);
141 for (theme, _) in themes.iter() {
151 for (theme, _) in themes.iter() {
142− println!("Theme: {}\n", Style::new().bold().paint(theme.to_string()));
155+ Style::new().bold().paint(theme.to_string())
143 config.theme = theme.to_string();
157 config.theme = theme.to_string();
144 let _controller = Controller::new(&config, &assets).run();
158 let _controller = Controller::new(&config, &assets).run();
145− println!()
159+ writeln!(stdout())?;
149/// Returns `Err(..)` upon fatal errors. Otherwise, returns `Some(true)` on full success and
165/// Returns `Err(..)` upon fatal errors. Otherwise, returns `Some(true)` on full success and
@@ -161,11 +177,11 @@ fn run() -> Result<bool> {
161 let assets = HighlightingAssets::new();
177 let assets = HighlightingAssets::new();
163 if app.matches.is_present("list-languages") {
179 if app.matches.is_present("list-languages") {
164− list_languages(&assets, config.term_width);
180+ list_languages(&assets, config.term_width)?;
167 } else if app.matches.is_present("list-themes") {
183 } else if app.matches.is_present("list-themes") {
168− list_themes(&assets, &config);
184+ list_themes(&assets, &config)?;