@@ -141,6 +141,17 @@ impl App {
141141 see all available themes",
142142 ),
143143 )
144+ .arg(
145+ Arg::with_name("line-range")
146+ .long("line-range")
147+ .overrides_with("line-range")
148+ .takes_value(true)
149+ .help("Print range of lines")
150+ .long_help(
151+ "Print a specified range of lines from the files \
152+ --line-range 30-40 or --line-range 30-",
153+ ),
154+ )
144155 .arg(
145156 Arg::with_name("list-themes")
146157 .long("list-themes")
@@ -269,6 +280,7 @@ impl App {
269280 term_width: Term::stdout().size().1 as usize,
270281 files,
271282 theme: self.matches.value_of("theme"),
283+ line_range: get_ranges(self.matches.value_of("line-range")),
272284 })
273285 }
274286
@@ -322,6 +334,7 @@ pub struct Config<'a> {
322334 pub term_width: usize,
323335 pub files: Vec<Option<&'a str>>,
324336 pub theme: Option<&'a str>,
337+ pub line_range: Option<(usize, usize)>,
325338}
326339
327340fn is_truecolor_terminal() -> bool {
@@ -329,3 +342,29 @@ fn is_truecolor_terminal() -> bool {
329342 .map(|colorterm| colorterm == "truecolor" || colorterm == "24bit")
330343 .unwrap_or(false)
331344}
345+
346+fn get_ranges(value: Option<&str>) -> Option<(usize, usize)> {
347+ match value {
348+ None => None,
349+ Some(str_range) => {
350+ let mut new_range = (usize::min_value(), usize::max_value());
351+ if str_range.bytes().nth(0).expect("Something should be here!") == b':' {
352+ new_range.1 = str_range[1..].parse().expect("This should be a number!");
353+ return Some(new_range);
354+ } else if str_range.bytes().last().expect("There should be a last!") == b':' {
355+ new_range.0 = str_range[..str_range.len() - 1]
356+ .parse()
357+ .expect("This should be a number!");
358+ return Some(new_range);
359+ }
360+
361+ let line_numbers: Vec<&str> = str_range.split(':').collect();
362+ if line_numbers.len() == 2 {
363+ new_range.0 = line_numbers[0].parse().expect("Should be a number!");
364+ new_range.1 = line_numbers[1].parse().expect("Should be a number!");
365+ }
366+
367+ Some(new_range)
368+ }
369+ }
370+}