on master help sign in
Merge remote-tracking branch 'upstream/master' into bat_style
commit63d32bc818b8a8375ddf70d069e7ee903b63d55c authorsharkdp <davidpeter@web.de> dateWed 12 Sep 2018, 21:40 (8 years ago) parentdccf8d897129ab
39 files changed+1361−242
.gitmodules+3 .travis.yml+7−1 assets/syntaxes/PowerShell+1 assets/syntaxes/PowerShell.sublime-syntax+466 ci/before_deploy.bash+14−1 ci/before_install.bash+8 ci/script.bash+1−1 src/app.rs+218−185 src/main.rs+1 src/preprocessor.rs+34 src/printer.rs+35−18 tests/snapshots/generate_snapshots.py+27−6 tests/snapshots/output/changes.snapshot.txt+15−1 tests/snapshots/output/changes,grid.snapshot.txt → tests/snapshots/output/changes_grid.snapshot.txt+15−1 tests/snapshots/output/changes,grid,header.snapshot.txt → tests/snapshots/output/changes_grid_header.snapshot.txt+15−1 tests/snapshots/output/changes_grid_header_numbers.snapshot.txt+40 tests/snapshots/output/changes,grid,numbers.snapshot.txt → tests/snapshots/output/changes_grid_numbers.snapshot.txt+15−1 tests/snapshots/output/changes,header.snapshot.txt → tests/snapshots/output/changes_header.snapshot.txt+15−1 tests/snapshots/output/changes,header,numbers.snapshot.txt → tests/snapshots/output/changes_header_numbers.snapshot.txt+15−1 tests/snapshots/output/changes,numbers.snapshot.txt → tests/snapshots/output/changes_numbers.snapshot.txt+15−1 tests/snapshots/output/full.snapshot.txt+15−1 tests/snapshots/output/grid.snapshot.txt+14 tests/snapshots/output/grid,header.snapshot.txt → tests/snapshots/output/grid_header.snapshot.txt+14 tests/snapshots/output/grid,header,numbers.snapshot.txt → tests/snapshots/output/grid_header_numbers.snapshot.txt+14 tests/snapshots/output/grid,numbers.snapshot.txt → tests/snapshots/output/grid_numbers.snapshot.txt+14 tests/snapshots/output/header.snapshot.txt+14 tests/snapshots/output/header,numbers.snapshot.txt → tests/snapshots/output/header_numbers.snapshot.txt+14 tests/snapshots/output/numbers.snapshot.txt+14 tests/snapshots/output/plain.snapshot.txt+14 tests/snapshots/output/tabs_4.snapshot.txt+40 tests/snapshots/output/tabs_4_wrapped.snapshot.txt+40 tests/snapshots/output/tabs_8.snapshot.txt+40 tests/snapshots/output/tabs_8_wrapped.snapshot.txt+40 tests/snapshots/output/changes,grid,header,numbers.snapshot.txt → tests/snapshots/output/tabs_passthrough.snapshot.txt+15−1 tests/snapshots/output/tabs_passthrough_wrapped.snapshot.txt+40 tests/snapshots/sample.modified.rs+14 tests/snapshots/sample.rs+14 tests/tester.rs+6−2 tests/tests.rs+25−19
.gitmodules+3
@@ -88,3 +88,6 @@
8888[submodule "assets/syntaxes/Crystal"]
8989 path = assets/syntaxes/Crystal
9090 url = https://github.com/crystal-lang-tools/sublime-crystal.git
91+[submodule "assets/syntaxes/PowerShell"]
92+ path = assets/syntaxes/PowerShell
93+ url = https://github.com/PowerShell/EditorSyntax
.travis.yml+7−1
@@ -23,7 +23,13 @@ matrix:
2323 - TARGET=arm-unknown-linux-gnueabihf
2424 - CC_arm_unknown_linux_gnueabihf=/usr/bin/arm-linux-gnueabihf-gcc-4.8
2525 - CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc-4.8
26−
26+ - os: linux
27+ rust: stable
28+ env:
29+ - TARGET=aarch64-unknown-linux-gnu
30+ - CC_aarch64-unknown-linux-gnu=/usr/bin/aarch64-linux-gnu-gcc-4.8
31+ - CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc-4.8
32+
2733 # Minimum Rust supported channel.
2834 - os: linux
2935 rust: 1.26.0
assets/syntaxes/PowerShellnew file+1

Submodule changed.

assets/syntaxes/PowerShell.sublime-syntaxnew file+466
@@ -0,0 +1,466 @@
1+%YAML 1.2
2+---
3+# http://www.sublimetext.com/docs/3/syntax.html
4+name: PowerShell
5+file_extensions:
6+ - ps1
7+ - psm1
8+ - psd1
9+scope: source.powershell
10+contexts:
11+ main:
12+ - match: "<#"
13+ captures:
14+ 0: punctuation.definition.comment.block.begin.powershell
15+ push:
16+ - meta_scope: comment.block.powershell
17+ - match: "#>"
18+ captures:
19+ 0: punctuation.definition.comment.block.end.powershell
20+ pop: true
21+ - include: commentEmbeddedDocs
22+ - match: '[2-6]>&1|>>|>|<<|<|>|>\||[1-6]>|[1-6]>>'
23+ scope: keyword.operator.redirection.powershell
24+ - include: commands
25+ - include: commentLine
26+ - include: variable
27+ - include: interpolatedStringContent
28+ - include: function
29+ - include: attribute
30+ - include: UsingDirective
31+ - include: type
32+ - include: hashtable
33+ - include: doubleQuotedString
34+ - include: scriptblock
35+ - include: doubleQuotedStringEscapes
36+ - match: (?<!')'
37+ captures:
38+ 0: punctuation.definition.string.begin.powershell
39+ push:
40+ - meta_scope: string.quoted.single.powershell
41+ - match: "'(?!')"
42+ captures:
43+ 0: punctuation.definition.string.end.powershell
44+ pop: true
45+ - match: "''"
46+ scope: constant.character.escape.powershell
47+ - match: \@"(?=$)
48+ push:
49+ - meta_scope: string.quoted.double.heredoc.powershell
50+ - match: ^"@
51+ pop: true
52+ - include: variableNoProperty
53+ - include: doubleQuotedStringEscapes
54+ - include: interpolation
55+ - match: \@'(?=$)
56+ push:
57+ - meta_scope: string.quoted.single.heredoc.powershell
58+ - match: ^'@
59+ pop: true
60+ - match: "''"
61+ scope: constant.character.escape.powershell
62+ - include: numericConstant
63+ - match: (@)(\()
64+ captures:
65+ 1: keyword.other.array.begin.powershell
66+ 2: punctuation.section.group.begin.powershell
67+ push:
68+ - meta_scope: meta.group.array-expression.powershell
69+ - match: \)
70+ captures:
71+ 0: punctuation.section.group.end.powershell
72+ pop: true
73+ - include: main
74+ - match: (\$)(\()
75+ comment: "TODO: move to repo; make recursive."
76+ captures:
77+ 1: punctuation.definition.variable.powershell
78+ 2: punctuation.section.group.begin.powershell
79+ push:
80+ - meta_scope: meta.group.complex.subexpression.powershell
81+ - match: \)
82+ captures:
83+ 0: punctuation.section.group.end.powershell
84+ pop: true
85+ - include: main
86+ - match: '(\b(([A-Za-z0-9\-_\.]+)\.(?i:exe|com|cmd|bat))\b)'
87+ scope: support.function.powershell
88+ - match: (?<!\w|-|\.)((?i:begin|break|catch|continue|data|default|define|do|dynamicparam|else|elseif|end|exit|finally|for|from|if|in|inlinescript|parallel|param|process|return|sequence|switch|throw|trap|try|until|var|while)|%|\?)(?!\w)
89+ scope: keyword.control.powershell
90+ - match: '(?<!\w|-|[^\)]\.)((?i:(foreach|where)(?!-object))|%|\?)(?!\w)'
91+ scope: keyword.control.powershell
92+ - match: (?<!\w)(--%)(?!\w)
93+ comment: This should be moved to the repository at some point.
94+ captures:
95+ 1: keyword.control.powershell
96+ push:
97+ - match: $
98+ pop: true
99+ - match: .+
100+ scope: string.unquoted.powershell
101+ - match: (?<!\w)((?i:hidden|static))(?!\w)
102+ comment: This should only be relevant inside a class but will require a rework of how classes are matched. This is a temp fix.
103+ scope: storage.modifier.powershell
104+ - match: '(?<!\w|-)((?i:class)|%|\?)(?:\s)+((?:\p{L}|\d|_|-|)+)\b'
105+ comment: capture should be entity.name.type, but it doesn't provide a good color in the default schema.
106+ captures:
107+ 1: storage.type.powershell
108+ 2: entity.name.function
109+ - match: (?<!\w)-(?i:is(?:not)?|as)\b
110+ scope: keyword.operator.comparison.powershell
111+ - match: '(?<!\w)-(?i:[ic]?(?:eq|ne|[gl][te]|(?:not)?(?:like|match|contains|in)|replace))(?!\p{L})'
112+ scope: keyword.operator.comparison.powershell
113+ - match: '(?<!\w)-(?i:join|split)(?!\p{L})|!'
114+ scope: keyword.operator.unary.powershell
115+ - match: '(?<!\w)-(?i:and|or|not|xor)(?!\p{L})|!'
116+ scope: keyword.operator.logical.powershell
117+ - match: '(?<!\w)-(?i:band|bor|bnot|bxor|shl|shr)(?!\p{L})'
118+ scope: keyword.operator.bitwise.powershell
119+ - match: '(?<!\w)-(?i:f)(?!\p{L})'
120+ scope: keyword.operator.string-format.powershell
121+ - match: "[+%*/-]?=|[+/*%-]"
122+ scope: keyword.operator.assignment.powershell
123+ - match: '\|{2}|&{2}|;'
124+ scope: punctuation.terminator.statement.powershell
125+ - match: '&|(?<!\w)\.(?= )|`|,|\|'
126+ scope: keyword.operator.other.powershell
127+ - match: (?<!\s|^)\.\.(?=\-?\d|\(|\$)
128+ comment: This is very imprecise, is there a syntax for 'must come after...'
129+ scope: keyword.operator.range.powershell
130+ RequiresDirective:
131+ - match: (?<=#)(?i:(requires))\s
132+ captures:
133+ 0: keyword.control.requires.powershell
134+ push:
135+ - meta_scope: meta.requires.powershell
136+ - match: $
137+ pop: true
138+ - match: \-(?i:Modules|PSSnapin|RunAsAdministrator|ShellId|Version)
139+ scope: keyword.other.powershell
140+ - match: '(?<!-)\b\p{L}+|\d+(?:\.\d+)*'
141+ scope: variable.parameter.powershell
142+ - include: hashtable
143+ UsingDirective:
144+ - match: (?<!\w)(?i:(using))\s+(?i:(namespace|module))\s+(?i:((?:\w+(?:\.)?)+))
145+ captures:
146+ 1: keyword.control.using.powershell
147+ 2: keyword.other.powershell
148+ 3: variable.parameter.powershell
149+ attribute:
150+ - match: '(\[)\s*\b(?i)(cmdletbinding|alias|outputtype|parameter|validatenotnull|validatenotnullorempty|validatecount|validateset|allownull|allowemptycollection|allowemptystring|validatescript|validaterange|validatepattern|validatelength)\b'
151+ captures:
152+ 1: punctuation.section.bracket.begin.powershell
153+ 2: support.function.attribute.powershell
154+ push:
155+ - meta_scope: meta.attribute.powershell
156+ - match: '(\])'
157+ captures:
158+ 1: punctuation.section.bracket.end.powershell
159+ pop: true
160+ - match: \(
161+ captures:
162+ 0: punctuation.section.group.begin.powershell
163+ push:
164+ - match: \)
165+ captures:
166+ 0: punctuation.section.group.end.powershell
167+ pop: true
168+ - include: variable
169+ - include: variableNoProperty
170+ - include: hashtable
171+ - include: scriptblock
172+ - include: doubleQuotedStringEscapes
173+ - include: doubleQuotedString
174+ - include: type
175+ - include: numericConstant
176+ - include: doubleQuotedString
177+ - include: main
178+ - match: (?i)\b(mandatory|valuefrompipeline|valuefrompipelinebypropertyname|valuefromremainingarguments|position|parametersetname|defaultparametersetname|supportsshouldprocess|supportspaging|positionalbinding|helpuri|confirmimpact|helpmessage)\b(?:\s+)?(=)?
179+ captures:
180+ 1: variable.parameter.attribute.powershell
181+ 2: keyword.operator.assignment.powershell
182+ - match: (?<!')'
183+ captures:
184+ 0: punctuation.definition.string.begin.powershell
185+ push:
186+ - meta_scope: string.quoted.single.powershell
187+ - match: "'(?!')"
188+ captures:
189+ 0: punctuation.definition.string.end.powershell
190+ pop: true
191+ - match: "''"
192+ scope: constant.character.escape.powershell
193+ commands:
194+ - match: '(?:(\p{L}|\d|_|-|\\|\:)*\\)?\b(?i:Add|Approve|Assert|Backup|Block|Build|Checkpoint|Clear|Close|Compare|Complete|Compress|Confirm|Connect|Convert|ConvertFrom|ConvertTo|Copy|Debug|Deny|Deploy|Disable|Disconnect|Dismount|Edit|Enable|Enter|Exit|Expand|Export|Find|Format|Get|Grant|Group|Hide|Import|Initialize|Install|Invoke|Join|Limit|Lock|Measure|Merge|Mount|Move|New|Open|Optimize|Out|Ping|Pop|Protect|Publish|Push|Read|Receive|Redo|Register|Remove|Rename|Repair|Request|Reset|Resize|Resolve|Restart|Restore|Resume|Revoke|Save|Search|Select|Send|Set|Show|Skip|Split|Start|Step|Stop|Submit|Suspend|Switch|Sync|Test|Trace|Unblock|Undo|Uninstall|Unlock|Unprotect|Unpublish|Unregister|Update|Use|Wait|Watch|Write)\-.+?(?:\.(?i:exe|cmd|bat|ps1))?\b'
195+ comment: "Verb-Noun pattern:"
196+ scope: support.function.powershell
197+ - match: (?<!\w)(?i:foreach-object)(?!\w)
198+ comment: Builtin cmdlets with reserved verbs
199+ scope: support.function.powershell
200+ - match: (?<!\w)(?i:where-object)(?!\w)
201+ comment: Builtin cmdlets with reserved verbs
202+ scope: support.function.powershell
203+ - match: (?<!\w)(?i:sort-object)(?!\w)
204+ comment: Builtin cmdlets with reserved verbs
205+ scope: support.function.powershell
206+ - match: (?<!\w)(?i:tee-object)(?!\w)
207+ comment: Builtin cmdlets with reserved verbs
208+ scope: support.function.powershell
209+ commentEmbeddedDocs:
210+ - match: ^(?i:(?:\s?|#)+(\.)(COMPONENT|DESCRIPTION|EXAMPLE|EXTERNALHELP|FORWARDHELPCATEGORY|FORWARDHELPTARGETNAME|FUNCTIONALITY|INPUTS|LINK|NOTES|OUTPUTS|REMOTEHELPRUNSPACE|ROLE|SYNOPSIS))
211+ scope: comment.documentation.embedded.powershell
212+ captures:
213+ 1: constant.string.documentation.powershell
214+ 2: keyword.operator.documentation.powershell
215+ - match: '(?i:\s?(\.)(PARAMETER|FORWARDHELPTARGETNAME|FORWARDHELPCATEGORY|REMOTEHELPRUNSPACE|EXTERNALHELP)\s+([a-z0-9-_]+))'
216+ scope: comment.documentation.embedded.powershell
217+ captures:
218+ 1: constant.string.documentation.powershell
219+ 2: keyword.operator.documentation.powershell
220+ 3: keyword.operator.documentation.powershell
221+ commentLine:
222+ - match: '(?<![`\\-])#'
223+ captures:
224+ 0: punctuation.definition.comment.powershell
225+ push:
226+ - meta_scope: comment.line.powershell
227+ - match: $\n?
228+ captures:
229+ 0: punctuation.definition.comment.powershell
230+ pop: true
231+ - include: commentEmbeddedDocs
232+ - include: RequiresDirective
233+ doubleQuotedString:
234+ - match: (?<!(?<!`)")"
235+ captures:
236+ 0: punctuation.definition.string.begin.powershell
237+ push:
238+ - meta_scope: string.quoted.double.powershell
239+ - match: '"(?!")'
240+ captures:
241+ 0: punctuation.definition.string.end.powershell
242+ pop: true
243+ - match: '(?i)\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,64}\b'
244+ - include: variableNoProperty
245+ - include: variable
246+ - include: doubleQuotedStringEscapes
247+ - include: interpolation
248+ - match: '`\s*$'
249+ scope: keyword.other.powershell
250+ doubleQuotedStringEscapes:
251+ - match: '`[0abnfrvt"''$`]'
252+ scope: constant.character.escape.powershell
253+ - match: '""'
254+ scope: constant.character.escape.powershell
255+ function:
256+ - match: '^(?:\s*+)(?i)(function|filter|configuration|workflow)\s+(?:(global|local|script|private):)?((?:\p{L}|\d|_|-|\.)+)'
257+ captures:
258+ 0: meta.function.powershell
259+ 1: storage.type.powershell
260+ 2: storage.modifier.scope.powershell
261+ 3: entity.name.function.powershell
262+ push:
263+ - match: '(?=\{|\()'
264+ pop: true
265+ - include: commentLine
266+ hashtable:
267+ - match: '(@)(\{)'
268+ captures:
269+ 1: keyword.other.hashtable.begin.powershell
270+ 2: punctuation.section.braces.begin.powershell
271+ push:
272+ - meta_scope: meta.hashtable.powershell
273+ - match: '(\})'
274+ captures:
275+ 1: punctuation.section.braces.end.powershell
276+ pop: true
277+ - match: \b((?:\'|\")?)(\w+)((?:\'|\")?)(?:\s+)?(=)(?:\s+)?
278+ scope: meta.hashtable.assignment.powershell
279+ captures:
280+ 1: punctuation.definition.string.begin.powershell
281+ 2: variable.other.readwrite.powershell
282+ 3: punctuation.definition.string.end.powershell
283+ 4: keyword.operator.assignment.powershell
284+ - include: scriptblock
285+ - include: main
286+ interpolatedStringContent:
287+ - match: \(
288+ captures:
289+ 0: punctuation.section.group.begin.powershell
290+ push:
291+ - meta_content_scope: interpolated.simple.source.powershell
292+ - match: \)
293+ captures:
294+ 0: punctuation.section.group.end.powershell
295+ pop: true
296+ - include: main
297+ - include: interpolation
298+ - include: interpolatedStringContent
299+ interpolation:
300+ - match: (\$)(\()
301+ captures:
302+ 1: punctuation.definition.variable.powershell
303+ 2: punctuation.section.group.begin.powershell
304+ push:
305+ - meta_content_scope: interpolated.complex.source.powershell
306+ - match: \)
307+ captures:
308+ 0: punctuation.section.group.end.powershell
309+ pop: true
310+ - include: main
311+ - include: interpolation
312+ - include: interpolatedStringContent
313+ numericConstant:
314+ - match: '(?<!\w)([-+]?0(?:x|X)[0-9a-fA-F_]+(?:U|u|L|l|UL|Ul|uL|ul|LU|Lu|lU|lu)?)((?i:[kmgtp]b)?)\b'
315+ captures:
316+ 1: constant.numeric.hex.powershell
317+ 2: keyword.other.powershell
318+ - match: '(?<!\w)([-+]?(?:[0-9_]+)?\.[0-9_]+(?:(?:e|E)[0-9]+)?(?:F|f|D|d|M|m)?)((?i:[kmgtp]b)?)\b'
319+ captures:
320+ 1: constant.numeric.integer.powershell
321+ 2: keyword.other.powershell
322+ - match: '(?<!\w)([-+]?0(?:b|B)[01_]+(?:U|u|L|l|UL|Ul|uL|ul|LU|Lu|lU|lu)?)((?i:[kmgtp]b)?)\b'
323+ captures:
324+ 1: constant.numeric.octal.powershell
325+ 2: keyword.other.powershell
326+ - match: '(?<!\w)([-+]?[0-9_]+(?:e|E)(?:[0-9_])?+(?:F|f|D|d|M|m)?)((?i:[kmgtp]b)?)\b'
327+ captures:
328+ 1: constant.numeric.integer.powershell
329+ 2: keyword.other.powershell
330+ - match: '(?<!\w)([-+]?[0-9_]+\.(?:e|E)(?:[0-9_])?+(?:F|f|D|d|M|m)?)((?i:[kmgtp]b)?)\b'
331+ captures:
332+ 1: constant.numeric.integer.powershell
333+ 2: keyword.other.powershell
334+ - match: '(?<!\w)([-+]?[0-9_]+[\.]?(?:F|f|D|d|M|m))((?i:[kmgtp]b)?)\b'
335+ captures:
336+ 1: constant.numeric.integer.powershell
337+ 2: keyword.other.powershell
338+ - match: '(?<!\w)([-+]?[0-9_]+[\.]?(?:U|u|L|l|UL|Ul|uL|ul|LU|Lu|lU|lu)?)((?i:[kmgtp]b)?)\b'
339+ captures:
340+ 1: constant.numeric.integer.powershell
341+ 2: keyword.other.powershell
342+ scriptblock:
343+ - match: '\{'
344+ captures:
345+ 0: punctuation.section.braces.begin.powershell
346+ push:
347+ - meta_scope: meta.scriptblock.powershell
348+ - match: '\}'
349+ captures:
350+ 0: punctuation.section.braces.end.powershell
351+ pop: true
352+ - include: main
353+ type:
354+ - match: '\['
355+ captures:
356+ 0: punctuation.section.bracket.begin.powershell
357+ push:
358+ - match: '\]'
359+ captures:
360+ 0: punctuation.section.bracket.end.powershell
361+ pop: true
362+ - match: '(?!\d+|\.)(?:\p{L}|\p{N}|\.)+'
363+ scope: storage.type.powershell
364+ - include: main
365+ variable:
366+ - match: (\$)(?i:(False|Null|True))\b
367+ comment: These are special constants.
368+ captures:
369+ 0: constant.language.powershell
370+ 1: punctuation.definition.variable.powershell
371+ - match: '(\$)(?i:(Error|ExecutionContext|Host|Home|PID|PsHome|PsVersionTable|ShellID))((?:\.(?:\p{L}|\d|_)+)*\b)?\b'
372+ comment: These are the other built-in constants.
373+ captures:
374+ 0: support.constant.variable.powershell
375+ 1: punctuation.definition.variable.powershell
376+ 3: variable.other.member.powershell
377+ - match: '(\$)(?i:(\$|\^|\?|_|Args|ConsoleFileName|Event|EventArgs|EventSubscriber|ForEach|Input|LastExitCode|Matches|MyInvocation|NestedPromptLevel|Profile|PSBoundParameters|PsCmdlet|PsCulture|PSDebugContext|PSItem|PSCommandPath|PSScriptRoot|PsUICulture|Pwd|Sender|SourceArgs|SourceEventArgs|StackTrace|Switch|This))((?:\.(?:\p{L}|\d|_)+)*\b)?\b'
378+ comment: Automatic variables are not constants, but they are read-only. In monokai (default) color schema support.variable doesn't have color, so we use constant.
379+ captures:
380+ 0: support.constant.automatic.powershell
381+ 1: punctuation.definition.variable.powershell
382+ 3: variable.other.member.powershell
383+ - match: '(\$)(?i:(ConfirmPreference|DebugPreference|ErrorActionPreference|ErrorView|FormatEnumerationLimit|MaximumAliasCount|MaximumDriveCount|MaximumErrorCount|MaximumFunctionCount|MaximumHistoryCount|MaximumVariableCount|OFS|OutputEncoding|ProgressPreference|PsCulture|PSDebugContext|PSDefaultParameterValues|PSEmailServer|PSItem|PSModuleAutoloadingPreference|PSSenderInfo|PSSessionApplicationName|PSSessionConfigurationName|PSSessionOption|VerbosePreference|WarningPreference|WhatIfPreference))((?:\.(?:\p{L}|\d|_)+)*\b)?\b'
384+ comment: Style preference variables as language variables so that they stand out.
385+ captures:
386+ 0: variable.language.powershell
387+ 1: punctuation.definition.variable.powershell
388+ 3: variable.other.member.powershell
389+ - match: '(?i:(\$|@)(global|local|private|script|using|workflow):((?:\p{L}|\d|_)+))((?:\.(?:\p{L}|\d|_)+)*\b)?'
390+ captures:
391+ 0: variable.other.readwrite.powershell
392+ 1: punctuation.definition.variable.powershell
393+ 2: storage.modifier.scope.powershell
394+ 4: variable.other.member.powershell
395+ - match: '(?i:(\$)(\{)(global|local|private|script|using|workflow):([^}]*[^}`])(\}))((?:\.(?:\p{L}|\d|_)+)*\b)?'
396+ captures:
397+ 0: variable.other.readwrite.powershell
398+ 1: punctuation.definition.variable.powershell
399+ 2: punctuation.section.braces.begin.powershell
400+ 3: storage.modifier.scope.powershell
401+ 5: punctuation.section.braces.end.powershell
402+ 6: variable.other.member.powershell
403+ - match: '(?i:(\$|@)((?:\p{L}|\d|_)+:)?((?:\p{L}|\d|_)+))((?:\.(?:\p{L}|\d|_)+)*\b)?'
404+ captures:
405+ 0: variable.other.readwrite.powershell
406+ 1: punctuation.definition.variable.powershell
407+ 2: support.variable.drive.powershell
408+ 4: variable.other.member.powershell
409+ - match: '(?i:(\$)(\{)((?:\p{L}|\d|_)+:)?([^}]*[^}`])(\}))((?:\.(?:\p{L}|\d|_)+)*\b)?'
410+ captures:
411+ 0: variable.other.readwrite.powershell
412+ 1: punctuation.definition.variable.powershell
413+ 2: punctuation.section.braces.begin.powershell
414+ 3: support.variable.drive.powershell
415+ 5: punctuation.section.braces.end.powershell
416+ 6: variable.other.member.powershell
417+ variableNoProperty:
418+ - match: (\$)(?i:(False|Null|True))\b
419+ comment: These are special constants.
420+ captures:
421+ 0: constant.language.powershell
422+ 1: punctuation.definition.variable.powershell
423+ - match: (\$)(?i:(Error|ExecutionContext|Host|Home|PID|PsHome|PsVersionTable|ShellID))\b
424+ comment: These are the other built-in constants.
425+ captures:
426+ 0: support.constant.variable.powershell
427+ 1: punctuation.definition.variable.powershell
428+ 3: variable.other.member.powershell
429+ - match: (\$)(?i:(\$|\^|\?|_|Args|ConsoleFileName|Event|EventArgs|EventSubscriber|ForEach|Input|LastExitCode|Matches|MyInvocation|NestedPromptLevel|Profile|PSBoundParameters|PsCmdlet|PsCulture|PSDebugContext|PSItem|PSCommandPath|PSScriptRoot|PsUICulture|Pwd|Sender|SourceArgs|SourceEventArgs|StackTrace|Switch|This))\b
430+ comment: Automatic variables are not constants, but they are read-only...
431+ captures:
432+ 0: support.variable.automatic.powershell
433+ 1: punctuation.definition.variable.powershell
434+ 3: variable.other.member.powershell
435+ - match: (\$)(?i:(ConfirmPreference|DebugPreference|ErrorActionPreference|ErrorView|FormatEnumerationLimit|MaximumAliasCount|MaximumDriveCount|MaximumErrorCount|MaximumFunctionCount|MaximumHistoryCount|MaximumVariableCount|OFS|OutputEncoding|ProgressPreference|PsCulture|PSDebugContext|PSDefaultParameterValues|PSEmailServer|PSItem|PSModuleAutoloadingPreference|PSSenderInfo|PSSessionApplicationName|PSSessionConfigurationName|PSSessionOption|VerbosePreference|WarningPreference|WhatIfPreference))\b
436+ comment: Style preference variables as language variables so that they stand out.
437+ captures:
438+ 0: variable.language.powershell
439+ 1: punctuation.definition.variable.powershell
440+ 3: variable.other.member.powershell
441+ - match: '(?i:(\$|@)(global|local|private|script|using|workflow):((?:\p{L}|\d|_)+))'
442+ captures:
443+ 0: variable.other.readwrite.powershell
444+ 1: punctuation.definition.variable.powershell
445+ 2: storage.modifier.scope.powershell
446+ 4: variable.other.member.powershell
447+ - match: '(?i:(\$)(\{)(global|local|private|script|using|workflow):([^}]*[^}`])(\}))'
448+ captures:
449+ 0: variable.other.readwrite.powershell
450+ 1: punctuation.definition.variable.powershell
451+ 2: storage.modifier.scope.powershell
452+ 4: keyword.other.powershell
453+ 5: variable.other.member.powershell
454+ - match: '(?i:(\$)((?:\p{L}|\d|_)+:)?((?:\p{L}|\d|_)+))'
455+ captures:
456+ 0: variable.other.readwrite.powershell
457+ 1: punctuation.definition.variable.powershell
458+ 2: support.variable.drive.powershell
459+ 4: variable.other.member.powershell
460+ - match: '(?i:(\$)(\{)((?:\p{L}|\d|_)+:)?([^}]*[^}`])(\}))'
461+ captures:
462+ 0: variable.other.readwrite.powershell
463+ 1: punctuation.definition.variable.powershell
464+ 2: punctuation.section.braces.begin
465+ 3: support.variable.drive.powershell
466+ 5: punctuation.section.braces.end
ci/before_deploy.bash+14−1
@@ -19,6 +19,8 @@ pack() {
1919
2020 if [[ $TARGET == "arm-unknown-linux-gnueabihf" ]]; then
2121 gcc_prefix="arm-linux-gnueabihf-"
22+ elif [[ $TARGET == "aarch64-unknown-linux-gnu" ]]; then
23+ gcc_prefix="aarch64-linux-gnu-"
2224 else
2325 gcc_prefix=""
2426 fi
@@ -49,13 +51,24 @@ make_deb() {
4951 local version
5052 local dpkgname
5153 local conflictname
54+ local gcc_prefix
5255
5356 case $TARGET in
5457 x86_64*)
5558 architecture=amd64
59+ gcc_prefix=""
5660 ;;
5761 i686*)
5862 architecture=i386
63+ gcc_prefix=""
64+ ;;
65+ aarch64*)
66+ architecture=arm64
67+ gcc_prefix="aarch64-linux-gnu-"
68+ ;;
69+ arm*hf)
70+ architecture=armhf
71+ gcc_prefix="arm-linux-gnueabihf-"
5972 ;;
6073 *)
6174 echo "make_deb: skipping target '${TARGET}'" >&2
@@ -75,7 +88,7 @@ make_deb() {
7588
7689 # copy the main binary
7790 install -Dm755 "target/$TARGET/release/$PROJECT_NAME" "$tempdir/usr/bin/$PROJECT_NAME"
78− strip "$tempdir/usr/bin/$PROJECT_NAME"
91+ "${gcc_prefix}"strip "$tempdir/usr/bin/$PROJECT_NAME"
7992
8093 # manpage
8194 install -Dm644 "doc/$PROJECT_NAME.1" "$tempdir/usr/share/man/man1/$PROJECT_NAME.1"
ci/before_install.bash+8
@@ -27,3 +27,11 @@ if [[ $TARGET == arm-unknown-linux-gnueabihf ]]; then
2727 libc6-armhf-cross \
2828 libc6-dev-armhf-cross
2929fi
30+
31+# needed for cross-compiling for arm64
32+if [[ $TARGET == aarch64-unknown-linux-gnu ]]; then
33+ sudo apt-get install -y \
34+ gcc-4.8-aarch64-linux-gnu \
35+ binutils-aarch64-linux-gnu \
36+ gcc-aarch64-linux-gnu
37+fi
ci/script.bash+1−1
@@ -6,7 +6,7 @@ set -ex
66cargo build --target "$TARGET" --verbose
77
88# We cannot run arm executables on linux
9−if [[ $TARGET != arm-unknown-linux-gnueabihf ]]; then
9+if [[ $TARGET != arm-unknown-linux-gnueabihf ]] && [[ $TARGET != aarch64-unknown-linux-gnu ]]; then
1010 cargo test --target "$TARGET" --verbose
1111
1212 # Run 'bat' on its own source code and the README
src/app.rs+218−185
@@ -17,7 +17,7 @@ use errors::*;
1717use line_range::LineRange;
1818use style::{OutputComponent, OutputComponents, OutputWrap};
1919
20−#[derive(Debug, Clone, Copy)]
20+#[derive(Debug, Clone, Copy, PartialEq)]
2121pub enum PagingMode {
2222 Always,
2323 QuitIfOneScreen,
@@ -42,6 +42,10 @@ pub struct Config<'a> {
4242 /// The character width of the terminal
4343 pub term_width: usize,
4444
45+ /// The width of tab characters.
46+ /// Currently, a value of 0 will cause tabs to be passed through without expanding them.
47+ pub tab_width: usize,
48+
4549 /// Whether or not to simply loop through all input (`cat` mode)
4650 pub loop_through: bool,
4751
@@ -131,7 +135,7 @@ impl App {
131135 to read from standard input.",
132136 ).multiple(true)
133137 .empty_values(false),
134− )
138+ )
135139 .arg(
136140 Arg::with_name("language")
137141 .short("l")
@@ -145,196 +149,210 @@ impl App {
145149 language names and file extensions."
146150 ).takes_value(true),
147151 ).arg(
148− Arg::with_name("list-languages")
149− .long("list-languages")
150− .conflicts_with("list-themes")
151− .help("Display all supported languages.")
152− .long_help("Display a list of supported languages for syntax highlighting."),
153− ).arg(
154− Arg::with_name("theme")
155− .long("theme")
156− .overrides_with("theme")
157− .takes_value(true)
158− .help("Set the color theme for syntax highlighting.")
159− .long_help(
160− "Set the theme for syntax highlighting. Use '--list-themes' to \
152+ Arg::with_name("list-languages")
153+ .long("list-languages")
154+ .conflicts_with("list-themes")
155+ .help("Display all supported languages.")
156+ .long_help("Display a list of supported languages for syntax highlighting."),
157+ ).arg(
158+ Arg::with_name("theme")
159+ .long("theme")
160+ .overrides_with("theme")
161+ .takes_value(true)
162+ .help("Set the color theme for syntax highlighting.")
163+ .long_help(
164+ "Set the theme for syntax highlighting. Use '--list-themes' to \
161165 see all available themes. To set a default theme, export the \
162166 BAT_THEME environment variable (e.g.: export \
163167 BAT_THEME=\"TwoDark\").",
164− ),
165− ).arg(
166− Arg::with_name("list-themes")
167− .long("list-themes")
168− .help("Display all supported highlighting themes.")
169− .long_help("Display a list of supported themes for syntax highlighting."),
170− ).arg(
171− Arg::with_name("style")
172− .long("style")
173− .value_name("style-components")
174− .use_delimiter(true)
175− .takes_value(true)
176− .possible_values(&[
177− "auto", "full", "plain", "changes", "header", "grid", "numbers",
178− ])
179− .help("Comma-separated list of style elements to display.")
180− .long_help(
181− "Configure which elements (line numbers, file headers, grid \
168+ ),
169+ ).arg(
170+ Arg::with_name("list-themes")
171+ .long("list-themes")
172+ .help("Display all supported highlighting themes.")
173+ .long_help("Display a list of supported themes for syntax highlighting."),
174+ ).arg(
175+ Arg::with_name("style")
176+ .long("style")
177+ .value_name("style-components")
178+ .use_delimiter(true)
179+ .takes_value(true)
180+ .possible_values(&[
181+ "auto", "full", "plain", "changes", "header", "grid", "numbers",
182+ ])
183+ .help("Comma-separated list of style elements to display.")
184+ .long_help(
185+ "Configure which elements (line numbers, file headers, grid \
182186 borders, Git modifications, ..) to display in addition to the \
183187 file contents. The argument is a comma-separated list of \
184188 components to display (e.g. 'numbers,changes,grid') or a \
185189 pre-defined style ('full'). To set a default theme, export the \
186190 BAT_STYLE environment variable (e.g.: export BAT_STYLE=\"numbers\").",
187− ),
188− ).arg(
189− Arg::with_name("plain")
190− .overrides_with("plain")
191− .short("p")
192− .long("plain")
193− .conflicts_with("style")
194− .conflicts_with("number")
195− .help("Show plain style (alias for '--style=plain').")
196− .long_help(
197− "Only show plain style, no decorations. This is an alias for \
191+ ),
192+ ).arg(
193+ Arg::with_name("plain")
194+ .overrides_with("plain")
195+ .short("p")
196+ .long("plain")
197+ .conflicts_with("style")
198+ .conflicts_with("number")
199+ .help("Show plain style (alias for '--style=plain').")
200+ .long_help(
201+ "Only show plain style, no decorations. This is an alias for \
198202 '--style=plain'",
199− ),
200− ).arg(
201− Arg::with_name("number")
202− .long("number")
203− .overrides_with("number")
204− .short("n")
205− .conflicts_with("style")
206− .help("Show line numbers (alias for '--style=numbers').")
207− .long_help(
208− "Only show line numbers, no other decorations. This is an alias for \
203+ ),
204+ ).arg(
205+ Arg::with_name("number")
206+ .long("number")
207+ .overrides_with("number")
208+ .short("n")
209+ .conflicts_with("style")
210+ .help("Show line numbers (alias for '--style=numbers').")
211+ .long_help(
212+ "Only show line numbers, no other decorations. This is an alias for \
209213 '--style=numbers'",
210− ),
211− ).arg(
212− Arg::with_name("line-range")
213− .long("line-range")
214− .overrides_with("line-range")
215− .takes_value(true)
216− .value_name("N:M")
217− .help("Only print the lines from N to M.")
218− .long_help(
219− "Only print the specified range of lines for each file. \
214+ ),
215+ ).arg(
216+ Arg::with_name("line-range")
217+ .long("line-range")
218+ .overrides_with("line-range")
219+ .takes_value(true)
220+ .value_name("N:M")
221+ .help("Only print the lines from N to M.")
222+ .long_help(
223+ "Only print the specified range of lines for each file. \
220224 For example:\n \
221225 '--line-range 30:40' prints lines 30 to 40\n \
222226 '--line-range :40' prints lines 1 to 40\n \
223227 '--line-range 40:' prints lines 40 to the end of the file",
224− ),
225− ).arg(
226− Arg::with_name("color")
227− .long("color")
228− .overrides_with("color")
229− .takes_value(true)
230− .value_name("when")
231− .possible_values(&["auto", "never", "always"])
232− .default_value("auto")
233− .help("When to use colors.")
234− .long_help("Specify when to use colored output. The automatic mode \
228+ ),
229+ ).arg(
230+ Arg::with_name("color")
231+ .long("color")
232+ .overrides_with("color")
233+ .takes_value(true)
234+ .value_name("when")
235+ .possible_values(&["auto", "never", "always"])
236+ .default_value("auto")
237+ .help("When to use colors.")
238+ .long_help("Specify when to use colored output. The automatic mode \
235239 only enables colors if an interactive terminal is detected."),
236− ).arg(
237− Arg::with_name("decorations")
238− .long("decorations")
239− .overrides_with("decorations")
240− .takes_value(true)
241− .value_name("when")
242− .possible_values(&["auto", "never", "always"])
243− .default_value("auto")
244− .help("When to show the decorations specified by '--style'.")
245− .long_help("Specify when to use the decorations that have been specified \
240+ ).arg(
241+ Arg::with_name("decorations")
242+ .long("decorations")
243+ .overrides_with("decorations")
244+ .takes_value(true)
245+ .value_name("when")
246+ .possible_values(&["auto", "never", "always"])
247+ .default_value("auto")
248+ .help("When to show the decorations specified by '--style'.")
249+ .long_help("Specify when to use the decorations that have been specified \
246250 via '--style'. The automatic mode only enables decorations if \
247251 an interactive terminal is detected."),
248− ).arg(
249− Arg::with_name("paging")
250− .long("paging")
251− .overrides_with("paging")
252− .takes_value(true)
253− .value_name("when")
254− .possible_values(&["auto", "never", "always"])
255− .default_value("auto")
256− .help("Specify when to use the pager.")
257− .long_help("Specify when to use the pager. To control which pager \
252+ ).arg(
253+ Arg::with_name("paging")
254+ .long("paging")
255+ .overrides_with("paging")
256+ .takes_value(true)
257+ .value_name("when")
258+ .possible_values(&["auto", "never", "always"])
259+ .default_value("auto")
260+ .help("Specify when to use the pager.")
261+ .long_help("Specify when to use the pager. To control which pager \
258262 is used, set the PAGER or BAT_PAGER environment \
259263 variables (the latter takes precedence). The default \
260264 pager is 'less'. To disable the pager permanently, set \
261265 BAT_PAGER to an empty string."),
266+ ).arg(
267+ Arg::with_name("wrap")
268+ .long("wrap")
269+ .overrides_with("wrap")
270+ .takes_value(true)
271+ .value_name("mode")
272+ .possible_values(&["auto", "never", "character"])
273+ .default_value("auto")
274+ .help("Specify the text-wrapping mode.")
275+ .long_help("Specify the text-wrapping mode."),
276+ ).arg(
277+ Arg::with_name("unbuffered")
278+ .short("u")
279+ .hidden_short_help(true)
280+ .long_help(
281+ "This option exists for POSIX-compliance reasons ('u' is for \
282+ 'unbuffered'). The output is always unbuffered - this option \
283+ is simply ignored.",
284+ ),
285+ ).arg(
286+ Arg::with_name("tabs")
287+ .long("tabs")
288+ .takes_value(true)
289+ .value_name("tabs")
290+ .validator(
291+ |t| t.parse::<u32>()
292+ .map_err(|_t| "must be a number")
293+ .map(|_t| ()) // Convert to Result<(), &str>
294+ .map_err(|e| e.to_string()) // Convert to Result<(), String>
295+ )
296+ .help("Sets the tab width.")
297+ .long_help("Sets the tab width. Use a width of 0 to pass tabs through \
298+ directly"),
299+ ).arg(
300+ Arg::with_name("terminal-width")
301+ .long("terminal-width")
302+ .takes_value(true)
303+ .value_name("width")
304+ .hidden(true)
305+ .help("Set the width of the terminal"),
306+ ).subcommand(
307+ SubCommand::with_name("cache")
308+ .about("Modify the syntax-definition and theme cache")
309+ .arg(
310+ Arg::with_name("init")
311+ .long("init")
312+ .short("i")
313+ .help("Initialize the syntax/theme cache.")
314+ .long_help(
315+ "Initialize the syntax/theme cache by loading from the \
316+ source directory (default: the configuration directory).",
317+ ),
318+ ).arg(
319+ Arg::with_name("clear")
320+ .long("clear")
321+ .short("c")
322+ .help("Remove the cached syntax definitions and themes."),
323+ ).arg(
324+ Arg::with_name("config-dir")
325+ .long("config-dir")
326+ .short("d")
327+ .help("Show bat's configuration directory."),
328+ ).group(
329+ ArgGroup::with_name("cache-actions")
330+ .args(&["init", "clear", "config-dir"])
331+ .required(arg_group_required),
262332 ).arg(
263− Arg::with_name("wrap")
264− .long("wrap")
265− .overrides_with("wrap")
333+ Arg::with_name("source")
334+ .long("source")
335+ .requires("init")
266336 .takes_value(true)
267− .value_name("mode")
268− .possible_values(&["auto", "never", "character"])
269− .default_value("auto")
270− .help("Specify the text-wrapping mode.")
271− .long_help("Specify the text-wrapping mode."),
337+ .value_name("dir")
338+ .help("Use a different directory to load syntaxes and themes from."),
272339 ).arg(
273− Arg::with_name("unbuffered")
274− .short("u")
275− .hidden_short_help(true)
276− .long_help(
277− "This option exists for POSIX-compliance reasons ('u' is for \
278− 'unbuffered'). The output is always unbuffered - this option \
279− is simply ignored.",
340+ Arg::with_name("target")
341+ .long("target")
342+ .requires("init")
343+ .takes_value(true)
344+ .value_name("dir")
345+ .help(
346+ "Use a different directory to store the cached syntax and theme set.",
280347 ),
281348 ).arg(
282− Arg::with_name("terminal-width")
283− .long("terminal-width")
284− .takes_value(true)
285− .value_name("width")
286− .hidden(true)
287− .help("Set the width of the terminal"),
288− ).subcommand(
289− SubCommand::with_name("cache")
290− .about("Modify the syntax-definition and theme cache")
291− .arg(
292− Arg::with_name("init")
293− .long("init")
294− .short("i")
295− .help("Initialize the syntax/theme cache.")
296− .long_help(
297− "Initialize the syntax/theme cache by loading from the \
298− source directory (default: the configuration directory).",
299− ),
300− ).arg(
301− Arg::with_name("clear")
302− .long("clear")
303− .short("c")
304− .help("Remove the cached syntax definitions and themes."),
305− ).arg(
306− Arg::with_name("config-dir")
307− .long("config-dir")
308− .short("d")
309− .help("Show bat's configuration directory."),
310− ).group(
311− ArgGroup::with_name("cache-actions")
312− .args(&["init", "clear", "config-dir"])
313− .required(arg_group_required),
314− ).arg(
315− Arg::with_name("source")
316− .long("source")
317− .requires("init")
318− .takes_value(true)
319− .value_name("dir")
320− .help("Use a different directory to load syntaxes and themes from."),
321− ).arg(
322− Arg::with_name("target")
323− .long("target")
324− .requires("init")
325− .takes_value(true)
326− .value_name("dir")
327− .help(
328− "Use a different directory to store the cached syntax and theme set.",
329− ),
330− ).arg(
331− Arg::with_name("blank")
332− .long("blank")
333− .requires("init")
334− .help("Create completely new syntax and theme sets \
349+ Arg::with_name("blank")
350+ .long("blank")
351+ .requires("init")
352+ .help("Create completely new syntax and theme sets \
335353 (instead of appending to the default sets).")
336− ),
337− ).help_message("Print this help message.")
354+ ),
355+ ).help_message("Print this help message.")
338356 .version_message("Show version information.")
339357 .get_matches()
340358 }
@@ -343,6 +361,27 @@ impl App {
343361 let files = self.files();
344362 let output_components = self.output_components()?;
345363
364+ let paging_mode = match self.matches.value_of("paging") {
365+ Some("always") => PagingMode::Always,
366+ Some("never") => PagingMode::Never,
367+ Some("auto") | _ => if files.contains(&InputFile::StdIn) {
368+ // If we are reading from stdin, only enable paging if we write to an
369+ // interactive terminal and if we do not *read* from an interactive
370+ // terminal.
371+ if self.interactive_output && !atty::is(Stream::Stdin) {
372+ PagingMode::QuitIfOneScreen
373+ } else {
374+ PagingMode::Never
375+ }
376+ } else {
377+ if self.interactive_output {
378+ PagingMode::QuitIfOneScreen
379+ } else {
380+ PagingMode::Never
381+ }
382+ },
383+ };
384+
346385 Ok(Config {
347386 true_color: is_truecolor_terminal(),
348387 language: self.matches.value_of("language"),
@@ -366,26 +405,7 @@ impl App {
366405 Some("never") => false,
367406 Some("auto") | _ => self.interactive_output,
368407 },
369− paging_mode: match self.matches.value_of("paging") {
370− Some("always") => PagingMode::Always,
371− Some("never") => PagingMode::Never,
372− Some("auto") | _ => if files.contains(&InputFile::StdIn) {
373− // If we are reading from stdin, only enable paging if we write to an
374− // interactive terminal and if we do not *read* from an interactive
375− // terminal.
376− if self.interactive_output && !atty::is(Stream::Stdin) {
377− PagingMode::QuitIfOneScreen
378− } else {
379− PagingMode::Never
380− }
381− } else {
382− if self.interactive_output {
383− PagingMode::QuitIfOneScreen
384− } else {
385− PagingMode::Never
386− }
387− },
388− },
408+ paging_mode,
389409 term_width: self
390410 .matches
391411 .value_of("terminal-width")
@@ -395,6 +415,19 @@ impl App {
395415 || self.matches.value_of("color") == Some("always")
396416 || self.matches.value_of("decorations") == Some("always")),
397417 files,
418+ tab_width: self
419+ .matches
420+ .value_of("tabs")
421+ .map(String::from)
422+ .or_else(|| env::var("BAT_TABS").ok())
423+ .and_then(|t| t.parse().ok())
424+ .unwrap_or(
425+ if output_components.plain() && paging_mode == PagingMode::Never {
426+ 0
427+ } else {
428+ 8
429+ },
430+ ),
398431 theme: self
399432 .matches
400433 .value_of("theme")
src/main.rs+1
@@ -24,6 +24,7 @@ mod decorations;
2424mod diff;
2525mod line_range;
2626mod output;
27+mod preprocessor;
2728mod printer;
2829mod style;
2930mod terminal;
src/preprocessor.rsnew file+34
@@ -0,0 +1,34 @@
1+use console::AnsiCodeIterator;
2+
3+/// Expand tabs like an ANSI-enabled expand(1).
4+pub fn expand(line: &str, width: usize, cursor: &mut usize) -> String {
5+ let mut buffer = String::with_capacity(line.len() * 2);
6+
7+ for chunk in AnsiCodeIterator::new(line) {
8+ match chunk {
9+ (text, true) => buffer.push_str(text),
10+ (mut text, false) => {
11+ while let Some(index) = text.find('\t') {
12+ // Add previous text.
13+ if index > 0 {
14+ *cursor += index;
15+ buffer.push_str(&text[0..index]);
16+ }
17+
18+ // Add tab.
19+ let spaces = width - (*cursor % width);
20+ *cursor += spaces;
21+ buffer.push_str(&*" ".repeat(spaces));
22+
23+ // Next.
24+ text = &text[index + 1..text.len()];
25+ }
26+
27+ *cursor += text.len();
28+ buffer.push_str(text);
29+ }
30+ }
31+ }
32+
33+ buffer
34+}
src/printer.rs+35−18
@@ -16,6 +16,7 @@ use decorations::{Decoration, GridBorderDecoration, LineChangesDecoration, LineN
1616use diff::get_git_diff;
1717use diff::LineChanges;
1818use errors::*;
19+use preprocessor::expand;
1920use style::OutputWrap;
2021use terminal::{as_terminal_escaped, to_ansi_color};
2122
@@ -113,9 +114,13 @@ impl<'a> InteractivePrinter<'a> {
113114 }
114115
115116 // Get the Git modifications
116− let line_changes = match file {
117− InputFile::Ordinary(filename) => get_git_diff(filename),
118− _ => None,
117+ let line_changes = if config.output_components.changes() {
118+ match file {
119+ InputFile::Ordinary(filename) => get_git_diff(filename),
120+ _ => None,
121+ }
122+ } else {
123+ None
119124 };
120125
121126 // Determine the type of syntax for highlighting
@@ -148,6 +153,14 @@ impl<'a> InteractivePrinter<'a> {
148153
149154 Ok(())
150155 }
156+
157+ fn preprocess(&self, text: &str, cursor: &mut usize) -> String {
158+ if self.config.tab_width > 0 {
159+ expand(text, self.config.tab_width, cursor)
160+ } else {
161+ text.to_string()
162+ }
163+ }
151164}
152165
153166impl<'a> Printer for InteractivePrinter<'a> {
@@ -200,7 +213,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
200213 line_number: usize,
201214 line_buffer: &[u8],
202215 ) -> Result<()> {
203− let line = String::from_utf8_lossy(&line_buffer);
216+ let line = String::from_utf8_lossy(&line_buffer).to_string();
204217 let regions = self.highlighter.highlight(line.as_ref());
205218
206219 if out_of_range {
@@ -209,6 +222,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
209222
210223 let mut cursor: usize = 0;
211224 let mut cursor_max: usize = self.config.term_width;
225+ let mut cursor_total: usize = 0;
212226 let mut panel_wrap: Option<String> = None;
213227
214228 // Line decorations.
@@ -230,19 +244,18 @@ impl<'a> Printer for InteractivePrinter<'a> {
230244 let true_color = self.config.true_color;
231245 let colored_output = self.config.colored_output;
232246
233− write!(
234− handle,
235− "{}",
236− regions
237− .iter()
238− .map(|&(style, text)| as_terminal_escaped(
239− style,
240− text,
241− true_color,
242− colored_output,
243− )).collect::<Vec<_>>()
244− .join("")
245− )?;
247+ for &(style, region) in regions.iter() {
248+ let text = &*self.preprocess(region, &mut cursor_total);
249+ write!(
250+ handle,
251+ "{}",
252+ as_terminal_escaped(style, &*text, true_color, colored_output,)
253+ )?;
254+ }
255+
256+ if line.bytes().next_back() != Some(b'\n') {
257+ write!(handle, "\n")?;
258+ }
246259 } else {
247260 for &(style, region) in regions.iter() {
248261 let mut ansi_iterator = AnsiCodeIterator::new(region);
@@ -265,7 +278,11 @@ impl<'a> Printer for InteractivePrinter<'a> {
265278
266279 // Regular text.
267280 (text, false) => {
268− let text = text.trim_right_matches(|c| c == '\r' || c == '\n');
281+ let text = self.preprocess(
282+ text.trim_right_matches(|c| c == '\r' || c == '\n'),
283+ &mut cursor_total,
284+ );
285+
269286 let mut chars = text.chars();
270287 let mut remaining = text.chars().count();
271288
tests/snapshots/generate_snapshots.py+27−6
@@ -1,43 +1,64 @@
11#!/usr/bin/env python3
2+
23import itertools
34import subprocess
45import pathlib
56import shutil
67
8+
79def generate_snapshots():
810 single_styles = ["changes", "grid", "header", "numbers"]
911 collective_styles = ["full", "plain"]
1012
1113 for num in range(len(single_styles)):
1214 for grouped in itertools.combinations(single_styles, num + 1):
13− generate_snapshot(",".join(grouped))
15+ generate_style_snapshot(",".join(grouped))
1416
1517 for style in collective_styles:
16− generate_snapshot(style)
18+ generate_style_snapshot(style)
19+
20+ generate_snapshot("tabs_passthrough", "--tabs=0 --style=full --wrap=never")
21+ generate_snapshot("tabs_passthrough_wrapped", "--tabs=0 --style=full --wrap=character")
22+ generate_snapshot("tabs_4", "--tabs=4 --style=full --wrap=never")
23+ generate_snapshot("tabs_4_wrapped", "--tabs=4 --style=full --wrap=character")
24+ generate_snapshot("tabs_8", "--tabs=8 --style=full --wrap=never")
25+ generate_snapshot("tabs_8_wrapped", "--tabs=8 --style=full --wrap=character")
26+
27+
28+def generate_style_snapshot(style):
29+ generate_snapshot(style.replace(",", "_"), "--style={}".format(style))
30+
1731
18−def generate_snapshot(option):
19− command = "../../target/debug/bat --style={0} sample.rs > output/{0}.snapshot.txt".format(
20− option
32+def generate_snapshot(name, arguments):
33+ command = "cargo run -- --paging=never --color=never --decorations=always "
34+ command += "{args} sample.rs > output/{name}.snapshot.txt".format(
35+ name=name,
36+ args=arguments
2137 )
22− print("generating snapshot for {}".format(option))
38+ print("generating snapshot for {}".format(name))
2339 subprocess.call(command, shell=True)
2440
41+
2542def build_bat():
2643 print("building bat")
2744 subprocess.call("cargo build", cwd="../..", shell=True)
2845
46+
2947def prepare_output_dir():
3048 shutil.rmtree("output", ignore_errors=True)
3149 pathlib.Path("output").mkdir()
3250
51+
3352def modify_sample_file():
3453 print("modifying sample.rs to show changes")
3554 shutil.copyfile("sample.modified.rs", "sample.rs")
3655
56+
3757def undo_sample_file_modification():
3858 print("undoing sample.rs modifications")
3959 subprocess.call("git checkout -- sample.rs", shell=True)
4060
61+
4162build_bat()
4263prepare_output_dir()
4364modify_sample_file()
tests/snapshots/output/changes.snapshot.txt+15−1
@@ -16,7 +16,21 @@ _ fn main() {
1616 fn area(rectangle: &Rectangle) -> u32 {
1717 rectangle.width * rectangle.height
1818 }
19−+
19+
2020+ fn perimeter(rectangle: &Rectangle) -> u32 {
2121+ (rectangle.width + rectangle.height) * 2
2222+ }
23++
24+ // Tab alignment:
25+ /*
26+ Indent
27+ 1 2 3 4
28+ 1 ?
29+ 22 ?
30+ 333 ?
31+ 4444 ?
32+ 55555 ?
33+ 666666 ?
34+ 7777777 ?
35+ 88888888 ?
36+~ */
tests/snapshots/output/changes,grid.snapshot.txt → tests/snapshots/output/changes_grid.snapshot.txtrenamed+15−1
@@ -16,8 +16,22 @@ _ │ fn main() {
1616 │ fn area(rectangle: &Rectangle) -> u32 {
1717 │ rectangle.width * rectangle.height
1818 │ }
19−+ │
19+ │
2020+ │ fn perimeter(rectangle: &Rectangle) -> u32 {
2121+ │ (rectangle.width + rectangle.height) * 2
2222+ │ }
23++ │
24+ │ // Tab alignment:
25+ │ /*
26+ │ Indent
27+ │ 1 2 3 4
28+ │ 1 ?
29+ │ 22 ?
30+ │ 333 ?
31+ │ 4444 ?
32+ │ 55555 ?
33+ │ 666666 ?
34+ │ 7777777 ?
35+ │ 88888888 ?
36+~ │ */
2337──┴─────────────────────────────────────────────────────────────────────────────
tests/snapshots/output/changes,grid,header.snapshot.txt → tests/snapshots/output/changes_grid_header.snapshot.txtrenamed+15−1
@@ -19,8 +19,22 @@ _ │ fn main() {
1919 │ fn area(rectangle: &Rectangle) -> u32 {
2020 │ rectangle.width * rectangle.height
2121 │ }
22−+ │
22+ │
2323+ │ fn perimeter(rectangle: &Rectangle) -> u32 {
2424+ │ (rectangle.width + rectangle.height) * 2
2525+ │ }
26++ │
27+ │ // Tab alignment:
28+ │ /*
29+ │ Indent
30+ │ 1 2 3 4
31+ │ 1 ?
32+ │ 22 ?
33+ │ 333 ?
34+ │ 4444 ?
35+ │ 55555 ?
36+ │ 666666 ?
37+ │ 7777777 ?
38+ │ 88888888 ?
39+~ │ */
2640──┴─────────────────────────────────────────────────────────────────────────────
tests/snapshots/output/changes_grid_header_numbers.snapshot.txtnew file+40
@@ -0,0 +1,40 @@
1+───────┬────────────────────────────────────────────────────────────────────────
2+ │ File: sample.rs
3+───────┼────────────────────────────────────────────────────────────────────────
4+ 1 │ struct Rectangle {
5+ 2 │ width: u32,
6+ 3 │ height: u32,
7+ 4 │ }
8+ 5 │
9+ 6 _ │ fn main() {
10+ 7 │ let rect1 = Rectangle { width: 30, height: 50 };
11+ 8 │
12+ 9 │ println!(
13+ 10 ~ │ "The perimeter of the rectangle is {} pixels.",
14+ 11 ~ │ perimeter(&rect1)
15+ 12 │ );
16+ 13 + │ println!(r#"This line contains invalid utf8: "�����"#;
17+ 14 │ }
18+ 15 │
19+ 16 │ fn area(rectangle: &Rectangle) -> u32 {
20+ 17 │ rectangle.width * rectangle.height
21+ 18 │ }
22+ 19 │
23+ 20 + │ fn perimeter(rectangle: &Rectangle) -> u32 {
24+ 21 + │ (rectangle.width + rectangle.height) * 2
25+ 22 + │ }
26+ 23 + │
27+ 24 │ // Tab alignment:
28+ 25 │ /*
29+ 26 │ Indent
30+ 27 │ 1 2 3 4
31+ 28 │ 1 ?
32+ 29 │ 22 ?
33+ 30 │ 333 ?
34+ 31 │ 4444 ?
35+ 32 │ 55555 ?
36+ 33 │ 666666 ?
37+ 34 │ 7777777 ?
38+ 35 │ 88888888 ?
39+ 36 ~ │ */
40+───────┴────────────────────────────────────────────────────────────────────────
tests/snapshots/output/changes,grid,numbers.snapshot.txt → tests/snapshots/output/changes_grid_numbers.snapshot.txtrenamed+15−1
@@ -16,8 +16,22 @@
1616 16 │ fn area(rectangle: &Rectangle) -> u32 {
1717 17 │ rectangle.width * rectangle.height
1818 18 │ }
19− 19 + │
19+ 19 │
2020 20 + │ fn perimeter(rectangle: &Rectangle) -> u32 {
2121 21 + │ (rectangle.width + rectangle.height) * 2
2222 22 + │ }
23+ 23 + │
24+ 24 │ // Tab alignment:
25+ 25 │ /*
26+ 26 │ Indent
27+ 27 │ 1 2 3 4
28+ 28 │ 1 ?
29+ 29 │ 22 ?
30+ 30 │ 333 ?
31+ 31 │ 4444 ?
32+ 32 │ 55555 ?
33+ 33 │ 666666 ?
34+ 34 │ 7777777 ?
35+ 35 │ 88888888 ?
36+ 36 ~ │ */
2337───────┴────────────────────────────────────────────────────────────────────────
tests/snapshots/output/changes,header.snapshot.txt → tests/snapshots/output/changes_header.snapshot.txtrenamed+15−1
@@ -17,7 +17,21 @@ _ fn main() {
1717 fn area(rectangle: &Rectangle) -> u32 {
1818 rectangle.width * rectangle.height
1919 }
20−+
20+
2121+ fn perimeter(rectangle: &Rectangle) -> u32 {
2222+ (rectangle.width + rectangle.height) * 2
2323+ }
24++
25+ // Tab alignment:
26+ /*
27+ Indent
28+ 1 2 3 4
29+ 1 ?
30+ 22 ?
31+ 333 ?
32+ 4444 ?
33+ 55555 ?
34+ 666666 ?
35+ 7777777 ?
36+ 88888888 ?
37+~ */
tests/snapshots/output/changes,header,numbers.snapshot.txt → tests/snapshots/output/changes_header_numbers.snapshot.txtrenamed+15−1
@@ -17,7 +17,21 @@
1717 16 fn area(rectangle: &Rectangle) -> u32 {
1818 17 rectangle.width * rectangle.height
1919 18 }
20− 19 +
20+ 19
2121 20 + fn perimeter(rectangle: &Rectangle) -> u32 {
2222 21 + (rectangle.width + rectangle.height) * 2
2323 22 + }
24+ 23 +
25+ 24 // Tab alignment:
26+ 25 /*
27+ 26 Indent
28+ 27 1 2 3 4
29+ 28 1 ?
30+ 29 22 ?
31+ 30 333 ?
32+ 31 4444 ?
33+ 32 55555 ?
34+ 33 666666 ?
35+ 34 7777777 ?
36+ 35 88888888 ?
37+ 36 ~ */
tests/snapshots/output/changes,numbers.snapshot.txt → tests/snapshots/output/changes_numbers.snapshot.txtrenamed+15−1
@@ -16,7 +16,21 @@
1616 16 fn area(rectangle: &Rectangle) -> u32 {
1717 17 rectangle.width * rectangle.height
1818 18 }
19− 19 +
19+ 19
2020 20 + fn perimeter(rectangle: &Rectangle) -> u32 {
2121 21 + (rectangle.width + rectangle.height) * 2
2222 22 + }
23+ 23 +
24+ 24 // Tab alignment:
25+ 25 /*
26+ 26 Indent
27+ 27 1 2 3 4
28+ 28 1 ?
29+ 29 22 ?
30+ 30 333 ?
31+ 31 4444 ?
32+ 32 55555 ?
33+ 33 666666 ?
34+ 34 7777777 ?
35+ 35 88888888 ?
36+ 36 ~ */
tests/snapshots/output/full.snapshot.txt+15−1
@@ -19,8 +19,22 @@
1919 16 │ fn area(rectangle: &Rectangle) -> u32 {
2020 17 │ rectangle.width * rectangle.height
2121 18 │ }
22− 19 + │
22+ 19 │
2323 20 + │ fn perimeter(rectangle: &Rectangle) -> u32 {
2424 21 + │ (rectangle.width + rectangle.height) * 2
2525 22 + │ }
26+ 23 + │
27+ 24 │ // Tab alignment:
28+ 25 │ /*
29+ 26 │ Indent
30+ 27 │ 1 2 3 4
31+ 28 │ 1 ?
32+ 29 │ 22 ?
33+ 30 │ 333 ?
34+ 31 │ 4444 ?
35+ 32 │ 55555 ?
36+ 33 │ 666666 ?
37+ 34 │ 7777777 ?
38+ 35 │ 88888888 ?
39+ 36 ~ │ */
2640───────┴────────────────────────────────────────────────────────────────────────
tests/snapshots/output/grid.snapshot.txt+14
@@ -20,4 +20,18 @@ fn area(rectangle: &Rectangle) -> u32 {
2020fn perimeter(rectangle: &Rectangle) -> u32 {
2121 (rectangle.width + rectangle.height) * 2
2222}
23+
24+// Tab alignment:
25+/*
26+ Indent
27+ 1 2 3 4
28+1 ?
29+22 ?
30+333 ?
31+4444 ?
32+55555 ?
33+666666 ?
34+7777777 ?
35+88888888 ?
36+*/
2337────────────────────────────────────────────────────────────────────────────────
tests/snapshots/output/grid,header.snapshot.txt → tests/snapshots/output/grid_header.snapshot.txtrenamed+14
@@ -23,4 +23,18 @@ fn area(rectangle: &Rectangle) -> u32 {
2323fn perimeter(rectangle: &Rectangle) -> u32 {
2424 (rectangle.width + rectangle.height) * 2
2525}
26+
27+// Tab alignment:
28+/*
29+ Indent
30+ 1 2 3 4
31+1 ?
32+22 ?
33+333 ?
34+4444 ?
35+55555 ?
36+666666 ?
37+7777777 ?
38+88888888 ?
39+*/
2640────────────────────────────────────────────────────────────────────────────────
tests/snapshots/output/grid,header,numbers.snapshot.txt → tests/snapshots/output/grid_header_numbers.snapshot.txtrenamed+14
@@ -23,4 +23,18 @@
2323 20 │ fn perimeter(rectangle: &Rectangle) -> u32 {
2424 21 │ (rectangle.width + rectangle.height) * 2
2525 22 │ }
26+ 23 │
27+ 24 │ // Tab alignment:
28+ 25 │ /*
29+ 26 │ Indent
30+ 27 │ 1 2 3 4
31+ 28 │ 1 ?
32+ 29 │ 22 ?
33+ 30 │ 333 ?
34+ 31 │ 4444 ?
35+ 32 │ 55555 ?
36+ 33 │ 666666 ?
37+ 34 │ 7777777 ?
38+ 35 │ 88888888 ?
39+ 36 │ */
2640─────┴──────────────────────────────────────────────────────────────────────────
tests/snapshots/output/grid,numbers.snapshot.txt → tests/snapshots/output/grid_numbers.snapshot.txtrenamed+14
@@ -20,4 +20,18 @@
2020 20 │ fn perimeter(rectangle: &Rectangle) -> u32 {
2121 21 │ (rectangle.width + rectangle.height) * 2
2222 22 │ }
23+ 23 │
24+ 24 │ // Tab alignment:
25+ 25 │ /*
26+ 26 │ Indent
27+ 27 │ 1 2 3 4
28+ 28 │ 1 ?
29+ 29 │ 22 ?
30+ 30 │ 333 ?
31+ 31 │ 4444 ?
32+ 32 │ 55555 ?
33+ 33 │ 666666 ?
34+ 34 │ 7777777 ?
35+ 35 │ 88888888 ?
36+ 36 │ */
2337─────┴──────────────────────────────────────────────────────────────────────────
tests/snapshots/output/header.snapshot.txt+14
@@ -21,3 +21,17 @@ fn area(rectangle: &Rectangle) -> u32 {
2121fn perimeter(rectangle: &Rectangle) -> u32 {
2222 (rectangle.width + rectangle.height) * 2
2323}
24+
25+// Tab alignment:
26+/*
27+ Indent
28+ 1 2 3 4
29+1 ?
30+22 ?
31+333 ?
32+4444 ?
33+55555 ?
34+666666 ?
35+7777777 ?
36+88888888 ?
37+*/
tests/snapshots/output/header,numbers.snapshot.txt → tests/snapshots/output/header_numbers.snapshot.txtrenamed+14
@@ -21,3 +21,17 @@
2121 20 fn perimeter(rectangle: &Rectangle) -> u32 {
2222 21 (rectangle.width + rectangle.height) * 2
2323 22 }
24+ 23
25+ 24 // Tab alignment:
26+ 25 /*
27+ 26 Indent
28+ 27 1 2 3 4
29+ 28 1 ?
30+ 29 22 ?
31+ 30 333 ?
32+ 31 4444 ?
33+ 32 55555 ?
34+ 33 666666 ?
35+ 34 7777777 ?
36+ 35 88888888 ?
37+ 36 */
tests/snapshots/output/numbers.snapshot.txt+14
@@ -20,3 +20,17 @@
2020 20 fn perimeter(rectangle: &Rectangle) -> u32 {
2121 21 (rectangle.width + rectangle.height) * 2
2222 22 }
23+ 23
24+ 24 // Tab alignment:
25+ 25 /*
26+ 26 Indent
27+ 27 1 2 3 4
28+ 28 1 ?
29+ 29 22 ?
30+ 30 333 ?
31+ 31 4444 ?
32+ 32 55555 ?
33+ 33 666666 ?
34+ 34 7777777 ?
35+ 35 88888888 ?
36+ 36 */
tests/snapshots/output/plain.snapshot.txt+14
@@ -20,3 +20,17 @@ fn area(rectangle: &Rectangle) -> u32 {
2020fn perimeter(rectangle: &Rectangle) -> u32 {
2121 (rectangle.width + rectangle.height) * 2
2222}
23+
24+// Tab alignment:
25+/*
26+ Indent
27+ 1 2 3 4
28+1 ?
29+22 ?
30+333 ?
31+4444 ?
32+55555 ?
33+666666 ?
34+7777777 ?
35+88888888 ?
36+*/
tests/snapshots/output/tabs_4.snapshot.txtnew file+40
@@ -0,0 +1,40 @@
1+───────┬────────────────────────────────────────────────────────────────────────
2+ │ File: sample.rs
3+───────┼────────────────────────────────────────────────────────────────────────
4+ 1 │ struct Rectangle {
5+ 2 │ width: u32,
6+ 3 │ height: u32,
7+ 4 │ }
8+ 5 │
9+ 6 _ │ fn main() {
10+ 7 │ let rect1 = Rectangle { width: 30, height: 50 };
11+ 8 │
12+ 9 │ println!(
13+ 10 ~ │ "The perimeter of the rectangle is {} pixels.",
14+ 11 ~ │ perimeter(&rect1)
15+ 12 │ );
16+ 13 + │ println!(r#"This line contains invalid utf8: "�����"#;
17+ 14 │ }
18+ 15 │
19+ 16 │ fn area(rectangle: &Rectangle) -> u32 {
20+ 17 │ rectangle.width * rectangle.height
21+ 18 │ }
22+ 19 │
23+ 20 + │ fn perimeter(rectangle: &Rectangle) -> u32 {
24+ 21 + │ (rectangle.width + rectangle.height) * 2
25+ 22 + │ }
26+ 23 + │
27+ 24 │ // Tab alignment:
28+ 25 │ /*
29+ 26 │ Indent
30+ 27 │ 1 2 3 4
31+ 28 │ 1 ?
32+ 29 │ 22 ?
33+ 30 │ 333 ?
34+ 31 │ 4444 ?
35+ 32 │ 55555 ?
36+ 33 │ 666666 ?
37+ 34 │ 7777777 ?
38+ 35 │ 88888888 ?
39+ 36 ~ │ */
40+───────┴────────────────────────────────────────────────────────────────────────
tests/snapshots/output/tabs_4_wrapped.snapshot.txtnew file+40
@@ -0,0 +1,40 @@
1+───────┬────────────────────────────────────────────────────────────────────────
2+ │ File: sample.rs
3+───────┼────────────────────────────────────────────────────────────────────────
4+ 1 │ struct Rectangle {
5+ 2 │ width: u32,
6+ 3 │ height: u32,
7+ 4 │ }
8+ 5 │
9+ 6 _ │ fn main() {
10+ 7 │ let rect1 = Rectangle { width: 30, height: 50 };
11+ 8 │
12+ 9 │ println!(
13+ 10 ~ │ "The perimeter of the rectangle is {} pixels.",
14+ 11 ~ │ perimeter(&rect1)
15+ 12 │ );
16+ 13 + │ println!(r#"This line contains invalid utf8: "�����"#;
17+ 14 │ }
18+ 15 │
19+ 16 │ fn area(rectangle: &Rectangle) -> u32 {
20+ 17 │ rectangle.width * rectangle.height
21+ 18 │ }
22+ 19 │
23+ 20 + │ fn perimeter(rectangle: &Rectangle) -> u32 {
24+ 21 + │ (rectangle.width + rectangle.height) * 2
25+ 22 + │ }
26+ 23 + │
27+ 24 │ // Tab alignment:
28+ 25 │ /*
29+ 26 │ Indent
30+ 27 │ 1 2 3 4
31+ 28 │ 1 ?
32+ 29 │ 22 ?
33+ 30 │ 333 ?
34+ 31 │ 4444 ?
35+ 32 │ 55555 ?
36+ 33 │ 666666 ?
37+ 34 │ 7777777 ?
38+ 35 │ 88888888 ?
39+ 36 ~ │ */
40+───────┴────────────────────────────────────────────────────────────────────────
tests/snapshots/output/tabs_8.snapshot.txtnew file+40
@@ -0,0 +1,40 @@
1+───────┬────────────────────────────────────────────────────────────────────────
2+ │ File: sample.rs
3+───────┼────────────────────────────────────────────────────────────────────────
4+ 1 │ struct Rectangle {
5+ 2 │ width: u32,
6+ 3 │ height: u32,
7+ 4 │ }
8+ 5 │
9+ 6 _ │ fn main() {
10+ 7 │ let rect1 = Rectangle { width: 30, height: 50 };
11+ 8 │
12+ 9 │ println!(
13+ 10 ~ │ "The perimeter of the rectangle is {} pixels.",
14+ 11 ~ │ perimeter(&rect1)
15+ 12 │ );
16+ 13 + │ println!(r#"This line contains invalid utf8: "�����"#;
17+ 14 │ }
18+ 15 │
19+ 16 │ fn area(rectangle: &Rectangle) -> u32 {
20+ 17 │ rectangle.width * rectangle.height
21+ 18 │ }
22+ 19 │
23+ 20 + │ fn perimeter(rectangle: &Rectangle) -> u32 {
24+ 21 + │ (rectangle.width + rectangle.height) * 2
25+ 22 + │ }
26+ 23 + │
27+ 24 │ // Tab alignment:
28+ 25 │ /*
29+ 26 │ Indent
30+ 27 │ 1 2 3 4
31+ 28 │ 1 ?
32+ 29 │ 22 ?
33+ 30 │ 333 ?
34+ 31 │ 4444 ?
35+ 32 │ 55555 ?
36+ 33 │ 666666 ?
37+ 34 │ 7777777 ?
38+ 35 │ 88888888 ?
39+ 36 ~ │ */
40+───────┴────────────────────────────────────────────────────────────────────────
tests/snapshots/output/tabs_8_wrapped.snapshot.txtnew file+40
@@ -0,0 +1,40 @@
1+───────┬────────────────────────────────────────────────────────────────────────
2+ │ File: sample.rs
3+───────┼────────────────────────────────────────────────────────────────────────
4+ 1 │ struct Rectangle {
5+ 2 │ width: u32,
6+ 3 │ height: u32,
7+ 4 │ }
8+ 5 │
9+ 6 _ │ fn main() {
10+ 7 │ let rect1 = Rectangle { width: 30, height: 50 };
11+ 8 │
12+ 9 │ println!(
13+ 10 ~ │ "The perimeter of the rectangle is {} pixels.",
14+ 11 ~ │ perimeter(&rect1)
15+ 12 │ );
16+ 13 + │ println!(r#"This line contains invalid utf8: "�����"#;
17+ 14 │ }
18+ 15 │
19+ 16 │ fn area(rectangle: &Rectangle) -> u32 {
20+ 17 │ rectangle.width * rectangle.height
21+ 18 │ }
22+ 19 │
23+ 20 + │ fn perimeter(rectangle: &Rectangle) -> u32 {
24+ 21 + │ (rectangle.width + rectangle.height) * 2
25+ 22 + │ }
26+ 23 + │
27+ 24 │ // Tab alignment:
28+ 25 │ /*
29+ 26 │ Indent
30+ 27 │ 1 2 3 4
31+ 28 │ 1 ?
32+ 29 │ 22 ?
33+ 30 │ 333 ?
34+ 31 │ 4444 ?
35+ 32 │ 55555 ?
36+ 33 │ 666666 ?
37+ 34 │ 7777777 ?
38+ 35 │ 88888888 ?
39+ 36 ~ │ */
40+───────┴────────────────────────────────────────────────────────────────────────
tests/snapshots/output/changes,grid,header,numbers.snapshot.txt → tests/snapshots/output/tabs_passthrough.snapshot.txtrenamed+15−1
@@ -19,8 +19,22 @@
1919 16 │ fn area(rectangle: &Rectangle) -> u32 {
2020 17 │ rectangle.width * rectangle.height
2121 18 │ }
22− 19 + │
22+ 19 │
2323 20 + │ fn perimeter(rectangle: &Rectangle) -> u32 {
2424 21 + │ (rectangle.width + rectangle.height) * 2
2525 22 + │ }
26+ 23 + │
27+ 24 │ // Tab alignment:
28+ 25 │ /*
29+ 26 │ Indent
30+ 27 │ 1 2 3 4
31+ 28 │ 1 ?
32+ 29 │ 22 ?
33+ 30 │ 333 ?
34+ 31 │ 4444 ?
35+ 32 │ 55555 ?
36+ 33 │ 666666 ?
37+ 34 │ 7777777 ?
38+ 35 │ 88888888 ?
39+ 36 ~ │ */
2640───────┴────────────────────────────────────────────────────────────────────────
tests/snapshots/output/tabs_passthrough_wrapped.snapshot.txtnew file+40
@@ -0,0 +1,40 @@
1+───────┬────────────────────────────────────────────────────────────────────────
2+ │ File: sample.rs
3+───────┼────────────────────────────────────────────────────────────────────────
4+ 1 │ struct Rectangle {
5+ 2 │ width: u32,
6+ 3 │ height: u32,
7+ 4 │ }
8+ 5 │
9+ 6 _ │ fn main() {
10+ 7 │ let rect1 = Rectangle { width: 30, height: 50 };
11+ 8 │
12+ 9 │ println!(
13+ 10 ~ │ "The perimeter of the rectangle is {} pixels.",
14+ 11 ~ │ perimeter(&rect1)
15+ 12 │ );
16+ 13 + │ println!(r#"This line contains invalid utf8: "�����"#;
17+ 14 │ }
18+ 15 │
19+ 16 │ fn area(rectangle: &Rectangle) -> u32 {
20+ 17 │ rectangle.width * rectangle.height
21+ 18 │ }
22+ 19 │
23+ 20 + │ fn perimeter(rectangle: &Rectangle) -> u32 {
24+ 21 + │ (rectangle.width + rectangle.height) * 2
25+ 22 + │ }
26+ 23 + │
27+ 24 │ // Tab alignment:
28+ 25 │ /*
29+ 26 │ Indent
30+ 27 │ 1 2 3 4
31+ 28 │ 1 ?
32+ 29 │ 22 ?
33+ 30 │ 333 ?
34+ 31 │ 4444 ?
35+ 32 │ 55555 ?
36+ 33 │ 666666 ?
37+ 34 │ 7777777 ?
38+ 35 │ 88888888 ?
39+ 36 ~ │ */
40+───────┴────────────────────────────────────────────────────────────────────────
tests/snapshots/sample.modified.rs+14
@@ -20,3 +20,17 @@ fn area(rectangle: &Rectangle) -> u32 {
2020fn perimeter(rectangle: &Rectangle) -> u32 {
2121 (rectangle.width + rectangle.height) * 2
2222}
23+
24+// Tab alignment:
25+/*
26+ Indent
27+ 1 2 3 4
28+1 ?
29+22 ?
30+333 ?
31+4444 ?
32+55555 ?
33+666666 ?
34+7777777 ?
35+88888888 ?
36+*/
tests/snapshots/sample.rs+14
@@ -16,3 +16,17 @@ fn main() {
1616fn area(rectangle: &Rectangle) -> u32 {
1717 rectangle.width * rectangle.height
1818}
19+
20+// Tab alignment:
21+/*
22+ Indent
23+ 1 2 3 4
24+1 ?
25+22 ?
26+333 ?
27+4444 ?
28+55555 ?
29+666666 ?
30+7777777 ?
31+88888888 ?
32+*/
tests/tester.rs+6−2
@@ -38,13 +38,17 @@ impl BatTester {
3838 BatTester { temp_dir, exe }
3939 }
4040
41− pub fn test_snapshot(&self, style: &str) {
41+ pub fn test_snapshot(&self, name: &str, style: &str, tab_width: u32, wrap: bool) {
4242 let output = Command::new(&self.exe)
4343 .current_dir(self.temp_dir.path())
4444 .args(&[
4545 "sample.rs",
46+ "--paging=never",
47+ "--color=never",
4648 "--decorations=always",
4749 "--terminal-width=80",
50+ &format!("--wrap={}", if wrap { "character" } else { "never" }),
51+ &format!("--tabs={}", tab_width),
4852 &format!("--style={}", style),
4953 ]).output()
5054 .expect("bat failed");
@@ -55,7 +59,7 @@ impl BatTester {
5559 .replace("tests/snapshots/", "");
5660
5761 let mut expected = String::new();
58− let mut file = File::open(format!("tests/snapshots/output/{}.snapshot.txt", style))
62+ let mut file = File::open(format!("tests/snapshots/output/{}.snapshot.txt", name))
5963 .expect("snapshot file missing");
6064 file.read_to_string(&mut expected)
6165 .expect("could not read snapshot file");
tests/tests.rs+25−19
@@ -3,33 +3,39 @@ mod tester;
33use tester::BatTester;
44
55macro_rules! snapshot_tests {
6− ($($test_name: ident: $style: expr,)*) => {
6+ ($($test_name: ident: $style: expr => [wrap: $wrap:expr, tabs: $tabs:expr],)*) => {
77 $(
88 #[test]
99 fn $test_name() {
1010 let bat_tester = BatTester::new();
11− bat_tester.test_snapshot($style);
11+ bat_tester.test_snapshot(stringify!($test_name), $style, $tabs, $wrap);
1212 }
1313 )*
1414 };
1515}
1616
1717snapshot_tests! {
18− changes: "changes",
19− grid: "grid",
20− header: "header",
21− numbers: "numbers",
22− changes_grid: "changes,grid",
23− changes_header: "changes,header",
24− changes_numbers: "changes,numbers",
25− grid_header: "grid,header",
26− grid_numbers: "grid,numbers",
27− header_numbers: "header,numbers",
28− changes_grid_header: "changes,grid,header",
29− changes_grid_numbers: "changes,grid,numbers",
30− changes_header_numbers: "changes,header,numbers",
31− grid_header_numbers: "grid,header,numbers",
32− changes_grid_header_numbers: "changes,grid,header,numbers",
33− full: "full",
34− plain: "plain",
18+ changes: "changes" => [wrap: false, tabs: 8],
19+ grid: "grid" => [wrap: false, tabs: 8],
20+ header: "header" => [wrap: false, tabs: 8],
21+ numbers: "numbers" => [wrap: false, tabs: 8],
22+ changes_grid: "changes,grid" => [wrap: false, tabs: 8],
23+ changes_header: "changes,header" => [wrap: false, tabs: 8],
24+ changes_numbers: "changes,numbers" => [wrap: false, tabs: 8],
25+ grid_header: "grid,header" => [wrap: false, tabs: 8],
26+ grid_numbers: "grid,numbers" => [wrap: false, tabs: 8],
27+ header_numbers: "header,numbers" => [wrap: false, tabs: 8],
28+ changes_grid_header: "changes,grid,header" => [wrap: false, tabs: 8],
29+ changes_grid_numbers: "changes,grid,numbers" => [wrap: false, tabs: 8],
30+ changes_header_numbers: "changes,header,numbers" => [wrap: false, tabs: 8],
31+ grid_header_numbers: "grid,header,numbers" => [wrap: false, tabs: 8],
32+ changes_grid_header_numbers: "changes,grid,header,numbers" => [wrap: false, tabs: 8],
33+ full: "full" => [wrap: false, tabs: 8],
34+ plain: "plain" => [wrap: false, tabs: 0],
35+ tabs_passthrough_wrapped: "full" => [wrap: true, tabs: 0],
36+ tabs_4_wrapped: "full" => [wrap: true, tabs: 4],
37+ tabs_8_wrapped: "full" => [wrap: true, tabs: 8],
38+ tabs_passthrough: "full" => [wrap: false, tabs: 0],
39+ tabs_4: "full" => [wrap: false, tabs: 4],
40+ tabs_8: "full" => [wrap: false, tabs: 8],
3541}