Skip to content

Commit a3a6a22

Browse files
committed
feat: add padding support
1 parent 165e6f5 commit a3a6a22

File tree

7 files changed

+19
-4
lines changed

7 files changed

+19
-4
lines changed

completions/bash/code-minimap.bash

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ _code-minimap() {
2626

2727
case "${cmd}" in
2828
code-minimap)
29-
opts=" -h -H -V --help --version --horizontal-scale --vertical-scale <FILE> completion help"
29+
opts=" -h -H -V --help --version --horizontal-scale --vertical-scale --padding <FILE> completion help"
3030
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
3131
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
3232
return 0
@@ -49,6 +49,10 @@ _code-minimap() {
4949
COMPREPLY=($(compgen -f "${cur}"))
5050
return 0
5151
;;
52+
--padding)
53+
COMPREPLY=($(compgen -f "${cur}"))
54+
return 0
55+
;;
5256
*)
5357
COMPREPLY=()
5458
;;

completions/elvish/code-minimap.elv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ edit:completion:arg-completer[code-minimap] = [@words]{
1919
cand --horizontal-scale 'Specify horizontal scale factor'
2020
cand -V 'Specify vertical scale factor'
2121
cand --vertical-scale 'Specify vertical scale factor'
22+
cand --padding 'Specify padding width'
2223
cand -h 'Prints help information'
2324
cand --help 'Prints help information'
2425
cand --version 'Prints version information'

completions/fish/code-minimap.fish

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
complete -c code-minimap -n "__fish_use_subcommand" -s H -l horizontal-scale -d 'Specify horizontal scale factor'
22
complete -c code-minimap -n "__fish_use_subcommand" -s V -l vertical-scale -d 'Specify vertical scale factor'
3+
complete -c code-minimap -n "__fish_use_subcommand" -l padding -d 'Specify padding width'
34
complete -c code-minimap -n "__fish_use_subcommand" -s h -l help -d 'Prints help information'
45
complete -c code-minimap -n "__fish_use_subcommand" -l version -d 'Prints version information'
56
complete -c code-minimap -n "__fish_use_subcommand" -f -a "completion" -d 'Generate shell completion file'

completions/powershell/_code-minimap.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Register-ArgumentCompleter -Native -CommandName 'code-minimap' -ScriptBlock {
2424
[CompletionResult]::new('--horizontal-scale', 'horizontal-scale', [CompletionResultType]::ParameterName, 'Specify horizontal scale factor')
2525
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Specify vertical scale factor')
2626
[CompletionResult]::new('--vertical-scale', 'vertical-scale', [CompletionResultType]::ParameterName, 'Specify vertical scale factor')
27+
[CompletionResult]::new('--padding', 'padding', [CompletionResultType]::ParameterName, 'Specify padding width')
2728
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Prints help information')
2829
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Prints help information')
2930
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information')

completions/zsh/_code-minimap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ _code-minimap() {
1919
'--horizontal-scale=[Specify horizontal scale factor]' \
2020
'-V+[Specify vertical scale factor]' \
2121
'--vertical-scale=[Specify vertical scale factor]' \
22+
'--padding=[Specify padding width]' \
2223
'-h[Prints help information]' \
2324
'--help[Prints help information]' \
2425
'--version[Prints version information]' \

src/cli.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ pub struct Opt {
2121
#[structopt(short = "V", long = "vertical-scale", default_value = "1.0")]
2222
pub vscale: f64,
2323

24+
/// Specify padding width
25+
#[structopt(long = "padding")]
26+
pub padding: Option<usize>,
27+
2428
/// Subcommand
2529
#[structopt(subcommand)]
2630
pub subcommand: Option<Subcommand>,

src/core.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ pub fn print_minimap(reader: Box<dyn BufRead>, opt: &Opt) -> io::Result<()> {
2525
frame[i] = beg..=end;
2626
}
2727
scale_frame(&mut frame, hscale);
28-
print_frame(&frame);
28+
print_frame(&frame, opt.padding);
2929
}
3030
Ok(())
3131
}
3232

33-
fn print_frame(frame: &Vec<RangeInclusive<usize>>) {
33+
fn print_frame(frame: &Vec<RangeInclusive<usize>>, padding: Option<usize>) {
3434
let idx = |pos| {
3535
frame
3636
.iter()
@@ -42,7 +42,10 @@ fn print_frame(frame: &Vec<RangeInclusive<usize>>) {
4242
.step_by(2)
4343
.map(|i| BRAILLE_MATRIX[(idx(i)) + (idx(i + 1) << 4)])
4444
.collect();
45-
println!("{}", line);
45+
match padding {
46+
Some(padding) => println!("{0:<1$}", line, padding),
47+
None => println!("{}", line),
48+
}
4649
}
4750

4851
fn scale_frame(frame: &mut Vec<RangeInclusive<usize>>, factor: f64) {

0 commit comments

Comments
 (0)