on master help sign in
make bat -L use pager
cffacadStefan Kunkel
CHANGELOG.md+1
@@ -2,6 +2,7 @@
2
2
3
3
4## Features
4## Features
5+- make `bat -L` use built-in pager
5
6
6## Bugfixes
7## Bugfixes
7
8
src/bin/bat/main.rs+14−13
@@ -78,7 +78,9 @@ fn get_syntax_mapping_to_paths<'a>(
78 map
78 map
79}
79}
80
80
81−pub fn list_languages(config: &Config) -> Result<()> {
81+pub fn get_languages(config: &Config) -> Result<String> {
82+ let mut result: String = String::new();
83+
82 let assets = assets_from_cache_or_binary()?;
84 let assets = assets_from_cache_or_binary()?;
83 let mut languages = assets
85 let mut languages = assets
84 .syntaxes()
86 .syntaxes()
@@ -119,12 +121,9 @@ pub fn list_languages(config: &Config) -> Result<()> {
119 }
121 }
120 }
122 }
121
123
122− let stdout = io::stdout();
123− let mut stdout = stdout.lock();
124−
125 if config.loop_through {
124 if config.loop_through {
126 for lang in languages {
125 for lang in languages {
127− writeln!(stdout, "{}:{}", lang.name, lang.file_extensions.join(","))?;
126+ result += &format!("{}:{}\n", lang.name, lang.file_extensions.join(","));
128 }
127 }
129 } else {
128 } else {
130 let longest = languages
129 let longest = languages
@@ -145,7 +144,7 @@ pub fn list_languages(config: &Config) -> Result<()> {
145 };
144 };
146
145
147 for lang in languages {
146 for lang in languages {
148− write!(stdout, "{:width$}{}", lang.name, separator, width = longest)?;
147+ result += &format!("{:width$}{}", lang.name, separator, width = longest);
149
148
150 // Number of characters on this line so far, wrap before `desired_width`
149 // Number of characters on this line so far, wrap before `desired_width`
151 let mut num_chars = 0;
150 let mut num_chars = 0;
@@ -156,20 +155,20 @@ pub fn list_languages(config: &Config) -> Result<()> {
156 let new_chars = word.len() + comma_separator.len();
155 let new_chars = word.len() + comma_separator.len();
157 if num_chars + new_chars >= desired_width {
156 if num_chars + new_chars >= desired_width {
158 num_chars = 0;
157 num_chars = 0;
159− write!(stdout, "\n{:width$}{}", "", separator, width = longest)?;
158+ result += &format!("\n{:width$}{}", "", separator, width = longest);
160 }
159 }
161
160
162 num_chars += new_chars;
161 num_chars += new_chars;
163− write!(stdout, "{}", style.paint(&word[..]))?;
162+ result += &format!("{}", style.paint(&word[..]));
164 if extension.peek().is_some() {
163 if extension.peek().is_some() {
165− write!(stdout, "{}", comma_separator)?;
164+ result += &format!("{}", comma_separator);
166 }
165 }
167 }
166 }
168− writeln!(stdout)?;
167+ result += "\n";
169 }
168 }
170 }
169 }
171
170
172− Ok(())
171+ Ok(result)
173}
172}
174
173
175fn theme_preview_file<'a>() -> Input<'a> {
174fn theme_preview_file<'a>() -> Input<'a> {
@@ -248,8 +247,10 @@ fn run() -> Result<bool> {
248 let config = app.config(&inputs)?;
247 let config = app.config(&inputs)?;
249
248
250 if app.matches.is_present("list-languages") {
249 if app.matches.is_present("list-languages") {
251− list_languages(&config)?;
250+ let languages: String = get_languages(&config)?;
252− Ok(true)
251+ let inputs: Vec<Input> = vec!(Input::from_reader(Box::new(languages.as_bytes())));
252+ let config = app.config(&inputs)?;
253+ run_controller(inputs, &config)
253 } else if app.matches.is_present("list-themes") {
254 } else if app.matches.is_present("list-themes") {
254 list_themes(&config)?;
255 list_themes(&config)?;
255 Ok(true)
256 Ok(true)