on master help sign in
Merge remote-tracking branch 'upstream/master' into bat_style
63d32bcsharkdp
.gitmodules+3
@@ -88,3 +88,6 @@
88[submodule "assets/syntaxes/Crystal"]
88[submodule "assets/syntaxes/Crystal"]
89 path = assets/syntaxes/Crystal
89 path = assets/syntaxes/Crystal
90 url = https://github.com/crystal-lang-tools/sublime-crystal.git
90 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:
23 - TARGET=arm-unknown-linux-gnueabihf
23 - TARGET=arm-unknown-linux-gnueabihf
24 - CC_arm_unknown_linux_gnueabihf=/usr/bin/arm-linux-gnueabihf-gcc-4.8
24 - CC_arm_unknown_linux_gnueabihf=/usr/bin/arm-linux-gnueabihf-gcc-4.8
25 - CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc-4.8
25 - 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+
27 # Minimum Rust supported channel.
33 # Minimum Rust supported channel.
28 - os: linux
34 - os: linux
29 rust: 1.26.0
35 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() {
19
19
20 if [[ $TARGET == "arm-unknown-linux-gnueabihf" ]]; then
20 if [[ $TARGET == "arm-unknown-linux-gnueabihf" ]]; then
21 gcc_prefix="arm-linux-gnueabihf-"
21 gcc_prefix="arm-linux-gnueabihf-"
22+ elif [[ $TARGET == "aarch64-unknown-linux-gnu" ]]; then
23+ gcc_prefix="aarch64-linux-gnu-"
22 else
24 else
23 gcc_prefix=""
25 gcc_prefix=""
24 fi
26 fi
@@ -49,13 +51,24 @@ make_deb() {
49 local version
51 local version
50 local dpkgname
52 local dpkgname
51 local conflictname
53 local conflictname
54+ local gcc_prefix
52
55
53 case $TARGET in
56 case $TARGET in
54 x86_64*)
57 x86_64*)
55 architecture=amd64
58 architecture=amd64
59+ gcc_prefix=""
56 ;;
60 ;;
57 i686*)
61 i686*)
58 architecture=i386
62 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-"
59 ;;
72 ;;
60 *)
73 *)
61 echo "make_deb: skipping target '${TARGET}'" >&2
74 echo "make_deb: skipping target '${TARGET}'" >&2
@@ -75,7 +88,7 @@ make_deb() {
75
88
76 # copy the main binary
89 # copy the main binary
77 install -Dm755 "target/$TARGET/release/$PROJECT_NAME" "$tempdir/usr/bin/$PROJECT_NAME"
90 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"
79
92
80 # manpage
93 # manpage
81 install -Dm644 "doc/$PROJECT_NAME.1" "$tempdir/usr/share/man/man1/$PROJECT_NAME.1"
94 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
27 libc6-armhf-cross \
27 libc6-armhf-cross \
28 libc6-dev-armhf-cross
28 libc6-dev-armhf-cross
29fi
29fi
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
6cargo build --target "$TARGET" --verbose
6cargo build --target "$TARGET" --verbose
7
7
8# We cannot run arm executables on linux
8# 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
10 cargo test --target "$TARGET" --verbose
10 cargo test --target "$TARGET" --verbose
11
11
12 # Run 'bat' on its own source code and the README
12 # Run 'bat' on its own source code and the README
src/app.rs+218−185
@@ -17,7 +17,7 @@ use errors::*;
17use line_range::LineRange;
17use line_range::LineRange;
18use style::{OutputComponent, OutputComponents, OutputWrap};
18use style::{OutputComponent, OutputComponents, OutputWrap};
19
19
20−#[derive(Debug, Clone, Copy)]
20+#[derive(Debug, Clone, Copy, PartialEq)]
21pub enum PagingMode {
21pub enum PagingMode {
22 Always,
22 Always,
23 QuitIfOneScreen,
23 QuitIfOneScreen,
@@ -42,6 +42,10 @@ pub struct Config<'a> {
42 /// The character width of the terminal
42 /// The character width of the terminal
43 pub term_width: usize,
43 pub term_width: usize,
44
44
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+
45 /// Whether or not to simply loop through all input (`cat` mode)
49 /// Whether or not to simply loop through all input (`cat` mode)
46 pub loop_through: bool,
50 pub loop_through: bool,
47
51
@@ -131,7 +135,7 @@ impl App {
131 to read from standard input.",
135 to read from standard input.",
132 ).multiple(true)
136 ).multiple(true)
133 .empty_values(false),
137 .empty_values(false),
134− )
138+ )
135 .arg(
139 .arg(
136 Arg::with_name("language")
140 Arg::with_name("language")
137 .short("l")
141 .short("l")
@@ -145,196 +149,210 @@ impl App {
145 language names and file extensions."
149 language names and file extensions."
146 ).takes_value(true),
150 ).takes_value(true),
147 ).arg(
151 ).arg(
148− Arg::with_name("list-languages")
152+ Arg::with_name("list-languages")
149− .long("list-languages")
153+ .long("list-languages")
150− .conflicts_with("list-themes")
154+ .conflicts_with("list-themes")
151− .help("Display all supported languages.")
155+ .help("Display all supported languages.")
152− .long_help("Display a list of supported languages for syntax highlighting."),
156+ .long_help("Display a list of supported languages for syntax highlighting."),
153− ).arg(
157+ ).arg(
154− Arg::with_name("theme")
158+ Arg::with_name("theme")
155− .long("theme")
159+ .long("theme")
156− .overrides_with("theme")
160+ .overrides_with("theme")
157− .takes_value(true)
161+ .takes_value(true)
158− .help("Set the color theme for syntax highlighting.")
162+ .help("Set the color theme for syntax highlighting.")
159− .long_help(
163+ .long_help(
160− "Set the theme for syntax highlighting. Use '--list-themes' to \
164+ "Set the theme for syntax highlighting. Use '--list-themes' to \
161 see all available themes. To set a default theme, export the \
165 see all available themes. To set a default theme, export the \
162 BAT_THEME environment variable (e.g.: export \
166 BAT_THEME environment variable (e.g.: export \
163 BAT_THEME=\"TwoDark\").",
167 BAT_THEME=\"TwoDark\").",
164− ),
168+ ),
165− ).arg(
169+ ).arg(
166− Arg::with_name("list-themes")
170+ Arg::with_name("list-themes")
167− .long("list-themes")
171+ .long("list-themes")
168− .help("Display all supported highlighting themes.")
172+ .help("Display all supported highlighting themes.")
169− .long_help("Display a list of supported themes for syntax highlighting."),
173+ .long_help("Display a list of supported themes for syntax highlighting."),
170− ).arg(
174+ ).arg(
171− Arg::with_name("style")
175+ Arg::with_name("style")
172− .long("style")
176+ .long("style")
173− .value_name("style-components")
177+ .value_name("style-components")
174− .use_delimiter(true)
178+ .use_delimiter(true)
175− .takes_value(true)
179+ .takes_value(true)
176− .possible_values(&[
180+ .possible_values(&[
177− "auto", "full", "plain", "changes", "header", "grid", "numbers",
181+ "auto", "full", "plain", "changes", "header", "grid", "numbers",
178− ])
182+ ])
179− .help("Comma-separated list of style elements to display.")
183+ .help("Comma-separated list of style elements to display.")
180− .long_help(
184+ .long_help(
181− "Configure which elements (line numbers, file headers, grid \
185+ "Configure which elements (line numbers, file headers, grid \
182 borders, Git modifications, ..) to display in addition to the \
186 borders, Git modifications, ..) to display in addition to the \
183 file contents. The argument is a comma-separated list of \
187 file contents. The argument is a comma-separated list of \
184 components to display (e.g. 'numbers,changes,grid') or a \
188 components to display (e.g. 'numbers,changes,grid') or a \
185 pre-defined style ('full'). To set a default theme, export the \
189 pre-defined style ('full'). To set a default theme, export the \
186 BAT_STYLE environment variable (e.g.: export BAT_STYLE=\"numbers\").",
190 BAT_STYLE environment variable (e.g.: export BAT_STYLE=\"numbers\").",
187− ),
191+ ),
188− ).arg(
192+ ).arg(
189− Arg::with_name("plain")
193+ Arg::with_name("plain")
190− .overrides_with("plain")
194+ .overrides_with("plain")
191− .short("p")
195+ .short("p")
192− .long("plain")
196+ .long("plain")
193− .conflicts_with("style")
197+ .conflicts_with("style")
194− .conflicts_with("number")
198+ .conflicts_with("number")
195− .help("Show plain style (alias for '--style=plain').")
199+ .help("Show plain style (alias for '--style=plain').")
196− .long_help(
200+ .long_help(
197− "Only show plain style, no decorations. This is an alias for \
201+ "Only show plain style, no decorations. This is an alias for \
198 '--style=plain'",
202 '--style=plain'",
199− ),
203+ ),
200− ).arg(
204+ ).arg(
201− Arg::with_name("number")
205+ Arg::with_name("number")
202− .long("number")
206+ .long("number")
203− .overrides_with("number")
207+ .overrides_with("number")
204− .short("n")
208+ .short("n")
205− .conflicts_with("style")
209+ .conflicts_with("style")
206− .help("Show line numbers (alias for '--style=numbers').")
210+ .help("Show line numbers (alias for '--style=numbers').")
207− .long_help(
211+ .long_help(
208− "Only show line numbers, no other decorations. This is an alias for \
212+ "Only show line numbers, no other decorations. This is an alias for \
209 '--style=numbers'",
213 '--style=numbers'",
210− ),
214+ ),
211− ).arg(
215+ ).arg(
212− Arg::with_name("line-range")
216+ Arg::with_name("line-range")
213− .long("line-range")
217+ .long("line-range")
214− .overrides_with("line-range")
218+ .overrides_with("line-range")
215− .takes_value(true)
219+ .takes_value(true)
216− .value_name("N:M")
220+ .value_name("N:M")
217− .help("Only print the lines from N to M.")
221+ .help("Only print the lines from N to M.")
218− .long_help(
222+ .long_help(
219− "Only print the specified range of lines for each file. \
223+ "Only print the specified range of lines for each file. \
220 For example:\n \
224 For example:\n \
221 '--line-range 30:40' prints lines 30 to 40\n \
225 '--line-range 30:40' prints lines 30 to 40\n \
222 '--line-range :40' prints lines 1 to 40\n \
226 '--line-range :40' prints lines 1 to 40\n \
223 '--line-range 40:' prints lines 40 to the end of the file",
227 '--line-range 40:' prints lines 40 to the end of the file",
224− ),
228+ ),
225− ).arg(
229+ ).arg(
226− Arg::with_name("color")
230+ Arg::with_name("color")
227− .long("color")
231+ .long("color")
228− .overrides_with("color")
232+ .overrides_with("color")
229− .takes_value(true)
233+ .takes_value(true)
230− .value_name("when")
234+ .value_name("when")
231− .possible_values(&["auto", "never", "always"])
235+ .possible_values(&["auto", "never", "always"])
232− .default_value("auto")
236+ .default_value("auto")
233− .help("When to use colors.")
237+ .help("When to use colors.")
234− .long_help("Specify when to use colored output. The automatic mode \
238+ .long_help("Specify when to use colored output. The automatic mode \
235 only enables colors if an interactive terminal is detected."),
239 only enables colors if an interactive terminal is detected."),
236− ).arg(
240+ ).arg(
237− Arg::with_name("decorations")
241+ Arg::with_name("decorations")
238− .long("decorations")
242+ .long("decorations")
239− .overrides_with("decorations")
243+ .overrides_with("decorations")
240− .takes_value(true)
244+ .takes_value(true)
241− .value_name("when")
245+ .value_name("when")
242− .possible_values(&["auto", "never", "always"])
246+ .possible_values(&["auto", "never", "always"])
243− .default_value("auto")
247+ .default_value("auto")
244− .help("When to show the decorations specified by '--style'.")
248+ .help("When to show the decorations specified by '--style'.")
245− .long_help("Specify when to use the decorations that have been specified \
249+ .long_help("Specify when to use the decorations that have been specified \
246 via '--style'. The automatic mode only enables decorations if \
250 via '--style'. The automatic mode only enables decorations if \
247 an interactive terminal is detected."),
251 an interactive terminal is detected."),
248− ).arg(
252+ ).arg(
249− Arg::with_name("paging")
253+ Arg::with_name("paging")
250− .long("paging")
254+ .long("paging")
251− .overrides_with("paging")
255+ .overrides_with("paging")
252− .takes_value(true)
256+ .takes_value(true)
253− .value_name("when")
257+ .value_name("when")
254− .possible_values(&["auto", "never", "always"])
258+ .possible_values(&["auto", "never", "always"])
255− .default_value("auto")
259+ .default_value("auto")
256− .help("Specify when to use the pager.")
260+ .help("Specify when to use the pager.")
257− .long_help("Specify when to use the pager. To control which pager \
261+ .long_help("Specify when to use the pager. To control which pager \
258 is used, set the PAGER or BAT_PAGER environment \
262 is used, set the PAGER or BAT_PAGER environment \
259 variables (the latter takes precedence). The default \
263 variables (the latter takes precedence). The default \
260 pager is 'less'. To disable the pager permanently, set \
264 pager is 'less'. To disable the pager permanently, set \
261 BAT_PAGER to an empty string."),
265 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),
262 ).arg(
332 ).arg(
263− Arg::with_name("wrap")
333+ Arg::with_name("source")
264− .long("wrap")
334+ .long("source")
265− .overrides_with("wrap")
335+ .requires("init")
266 .takes_value(true)
336 .takes_value(true)
267− .value_name("mode")
337+ .value_name("dir")
268− .possible_values(&["auto", "never", "character"])
338+ .help("Use a different directory to load syntaxes and themes from."),
269− .default_value("auto")
270− .help("Specify the text-wrapping mode.")
271− .long_help("Specify the text-wrapping mode."),
272 ).arg(
339 ).arg(
273− Arg::with_name("unbuffered")
340+ Arg::with_name("target")
274− .short("u")
341+ .long("target")
275− .hidden_short_help(true)
342+ .requires("init")
276− .long_help(
343+ .takes_value(true)
277− "This option exists for POSIX-compliance reasons ('u' is for \
344+ .value_name("dir")
278− 'unbuffered'). The output is always unbuffered - this option \
345+ .help(
279− is simply ignored.",
346+ "Use a different directory to store the cached syntax and theme set.",
280 ),
347 ),
281 ).arg(
348 ).arg(
282− Arg::with_name("terminal-width")
349+ Arg::with_name("blank")
283− .long("terminal-width")
350+ .long("blank")
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")
351+ .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 \
352+ .help("Create completely new syntax and theme sets \
335 (instead of appending to the default sets).")
353 (instead of appending to the default sets).")
336− ),
354+ ),
337− ).help_message("Print this help message.")
355+ ).help_message("Print this help message.")
338 .version_message("Show version information.")
356 .version_message("Show version information.")
339 .get_matches()
357 .get_matches()
340 }
358 }
@@ -343,6 +361,27 @@ impl App {
343 let files = self.files();
361 let files = self.files();
344 let output_components = self.output_components()?;
362 let output_components = self.output_components()?;
345
363
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+
346 Ok(Config {
385 Ok(Config {
347 true_color: is_truecolor_terminal(),
386 true_color: is_truecolor_terminal(),
348 language: self.matches.value_of("language"),
387 language: self.matches.value_of("language"),
@@ -366,26 +405,7 @@ impl App {
366 Some("never") => false,
405 Some("never") => false,
367 Some("auto") | _ => self.interactive_output,
406 Some("auto") | _ => self.interactive_output,
368 },
407 },
369− paging_mode: match self.matches.value_of("paging") {
408+ paging_mode,
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− },
389 term_width: self
409 term_width: self
390 .matches
410 .matches
391 .value_of("terminal-width")
411 .value_of("terminal-width")
@@ -395,6 +415,19 @@ impl App {
395 || self.matches.value_of("color") == Some("always")
415 || self.matches.value_of("color") == Some("always")
396 || self.matches.value_of("decorations") == Some("always")),
416 || self.matches.value_of("decorations") == Some("always")),
397 files,
417 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+ ),
398 theme: self
431 theme: self
399 .matches
432 .matches
400 .value_of("theme")
433 .value_of("theme")
src/main.rs+1
@@ -24,6 +24,7 @@ mod decorations;
24mod diff;
24mod diff;
25mod line_range;
25mod line_range;
26mod output;
26mod output;
27+mod preprocessor;
27mod printer;
28mod printer;
28mod style;
29mod style;
29mod terminal;
30mod 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
16use diff::get_git_diff;
16use diff::get_git_diff;
17use diff::LineChanges;
17use diff::LineChanges;
18use errors::*;
18use errors::*;
19+use preprocessor::expand;
19use style::OutputWrap;
20use style::OutputWrap;
20use terminal::{as_terminal_escaped, to_ansi_color};
21use terminal::{as_terminal_escaped, to_ansi_color};
21
22
@@ -113,9 +114,13 @@ impl<'a> InteractivePrinter<'a> {
113 }
114 }
114
115
115 // Get the Git modifications
116 // Get the Git modifications
117+ let line_changes = if config.output_components.changes() {
116− let line_changes = match file {
118+ match file {
117− InputFile::Ordinary(filename) => get_git_diff(filename),
119+ InputFile::Ordinary(filename) => get_git_diff(filename),
118− _ => None,
120+ _ => None,
121+ }
122+ } else {
123+ None
119 };
124 };
120
125
121 // Determine the type of syntax for highlighting
126 // Determine the type of syntax for highlighting
@@ -148,6 +153,14 @@ impl<'a> InteractivePrinter<'a> {
148
153
149 Ok(())
154 Ok(())
150 }
155 }
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+ }
151}
164}
152
165
153impl<'a> Printer for InteractivePrinter<'a> {
166impl<'a> Printer for InteractivePrinter<'a> {
@@ -200,7 +213,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
200 line_number: usize,
213 line_number: usize,
201 line_buffer: &[u8],
214 line_buffer: &[u8],
202 ) -> Result<()> {
215 ) -> Result<()> {
203− let line = String::from_utf8_lossy(&line_buffer);
216+ let line = String::from_utf8_lossy(&line_buffer).to_string();
204 let regions = self.highlighter.highlight(line.as_ref());
217 let regions = self.highlighter.highlight(line.as_ref());
205
218
206 if out_of_range {
219 if out_of_range {
@@ -209,6 +222,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
209
222
210 let mut cursor: usize = 0;
223 let mut cursor: usize = 0;
211 let mut cursor_max: usize = self.config.term_width;
224 let mut cursor_max: usize = self.config.term_width;
225+ let mut cursor_total: usize = 0;
212 let mut panel_wrap: Option<String> = None;
226 let mut panel_wrap: Option<String> = None;
213
227
214 // Line decorations.
228 // Line decorations.
@@ -230,19 +244,18 @@ impl<'a> Printer for InteractivePrinter<'a> {
230 let true_color = self.config.true_color;
244 let true_color = self.config.true_color;
231 let colored_output = self.config.colored_output;
245 let colored_output = self.config.colored_output;
232
246
233− write!(
234− handle,
235− "{}",
236− regions
247+ for &(style, region) in regions.iter() {
237− .iter()
248+ let text = &*self.preprocess(region, &mut cursor_total);
249+ write!(
250+ handle,
251+ "{}",
238− .map(|&(style, text)| as_terminal_escaped(
252+ as_terminal_escaped(style, &*text, true_color, colored_output,)
239− style,
253+ )?;
240− text,
254+ }
241− true_color,
255+
242− colored_output,
256+ if line.bytes().next_back() != Some(b'\n') {
243− )).collect::<Vec<_>>()
257+ write!(handle, "\n")?;
244− .join("")
258+ }
245− )?;
246 } else {
259 } else {
247 for &(style, region) in regions.iter() {
260 for &(style, region) in regions.iter() {
248 let mut ansi_iterator = AnsiCodeIterator::new(region);
261 let mut ansi_iterator = AnsiCodeIterator::new(region);
@@ -265,7 +278,11 @@ impl<'a> Printer for InteractivePrinter<'a> {
265
278
266 // Regular text.
279 // Regular text.
267 (text, false) => {
280 (text, false) => {
281+ let text = self.preprocess(
268− let text = text.trim_right_matches(|c| c == '\r' || c == '\n');
282+ text.trim_right_matches(|c| c == '\r' || c == '\n'),
283+ &mut cursor_total,
284+ );
285+
269 let mut chars = text.chars();
286 let mut chars = text.chars();
270 let mut remaining = text.chars().count();
287 let mut remaining = text.chars().count();
271
288
tests/snapshots/generate_snapshots.py+27−6
@@ -1,43 +1,64 @@
1#!/usr/bin/env python3
1#!/usr/bin/env python3
2+
2import itertools
3import itertools
3import subprocess
4import subprocess
4import pathlib
5import pathlib
5import shutil
6import shutil
6
7
8+
7def generate_snapshots():
9def generate_snapshots():
8 single_styles = ["changes", "grid", "header", "numbers"]
10 single_styles = ["changes", "grid", "header", "numbers"]
9 collective_styles = ["full", "plain"]
11 collective_styles = ["full", "plain"]
10
12
11 for num in range(len(single_styles)):
13 for num in range(len(single_styles)):
12 for grouped in itertools.combinations(single_styles, num + 1):
14 for grouped in itertools.combinations(single_styles, num + 1):
13− generate_snapshot(",".join(grouped))
15+ generate_style_snapshot(",".join(grouped))
14
16
15 for style in collective_styles:
17 for style in collective_styles:
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):
16− generate_snapshot(style)
29+ generate_snapshot(style.replace(",", "_"), "--style={}".format(style))
30+
17
31
18−def generate_snapshot(option):
32+def generate_snapshot(name, arguments):
33+ command = "cargo run -- --paging=never --color=never --decorations=always "
19− command = "../../target/debug/bat --style={0} sample.rs > output/{0}.snapshot.txt".format(
34+ command += "{args} sample.rs > output/{name}.snapshot.txt".format(
20− option
35+ name=name,
36+ args=arguments
21 )
37 )
22− print("generating snapshot for {}".format(option))
38+ print("generating snapshot for {}".format(name))
23 subprocess.call(command, shell=True)
39 subprocess.call(command, shell=True)
24
40
41+
25def build_bat():
42def build_bat():
26 print("building bat")
43 print("building bat")
27 subprocess.call("cargo build", cwd="../..", shell=True)
44 subprocess.call("cargo build", cwd="../..", shell=True)
28
45
46+
29def prepare_output_dir():
47def prepare_output_dir():
30 shutil.rmtree("output", ignore_errors=True)
48 shutil.rmtree("output", ignore_errors=True)
31 pathlib.Path("output").mkdir()
49 pathlib.Path("output").mkdir()
32
50
51+
33def modify_sample_file():
52def modify_sample_file():
34 print("modifying sample.rs to show changes")
53 print("modifying sample.rs to show changes")
35 shutil.copyfile("sample.modified.rs", "sample.rs")
54 shutil.copyfile("sample.modified.rs", "sample.rs")
36
55
56+
37def undo_sample_file_modification():
57def undo_sample_file_modification():
38 print("undoing sample.rs modifications")
58 print("undoing sample.rs modifications")
39 subprocess.call("git checkout -- sample.rs", shell=True)
59 subprocess.call("git checkout -- sample.rs", shell=True)
40
60
61+
41build_bat()
62build_bat()
42prepare_output_dir()
63prepare_output_dir()
43modify_sample_file()
64modify_sample_file()
tests/snapshots/output/changes.snapshot.txt+15−1
@@ -16,7 +16,21 @@ _ fn main() {
16 fn area(rectangle: &Rectangle) -> u32 {
16 fn area(rectangle: &Rectangle) -> u32 {
17 rectangle.width * rectangle.height
17 rectangle.width * rectangle.height
18 }
18 }
19−+
19+
20+ fn perimeter(rectangle: &Rectangle) -> u32 {
20+ fn perimeter(rectangle: &Rectangle) -> u32 {
21+ (rectangle.width + rectangle.height) * 2
21+ (rectangle.width + rectangle.height) * 2
22+ }
22+ }
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() {
16 │ fn area(rectangle: &Rectangle) -> u32 {
16 │ fn area(rectangle: &Rectangle) -> u32 {
17 │ rectangle.width * rectangle.height
17 │ rectangle.width * rectangle.height
18 │ }
18 │ }
19−+ │
19+ │
20+ │ fn perimeter(rectangle: &Rectangle) -> u32 {
20+ │ fn perimeter(rectangle: &Rectangle) -> u32 {
21+ │ (rectangle.width + rectangle.height) * 2
21+ │ (rectangle.width + rectangle.height) * 2
22+ │ }
22+ │ }
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+~ │ */
23──┴─────────────────────────────────────────────────────────────────────────────
37──┴─────────────────────────────────────────────────────────────────────────────
tests/snapshots/output/changes,grid,header.snapshot.txt → tests/snapshots/output/changes_grid_header.snapshot.txtrenamed+15−1
@@ -19,8 +19,22 @@ _ │ fn main() {
19 │ fn area(rectangle: &Rectangle) -> u32 {
19 │ fn area(rectangle: &Rectangle) -> u32 {
20 │ rectangle.width * rectangle.height
20 │ rectangle.width * rectangle.height
21 │ }
21 │ }
22−+ │
22+ │
23+ │ fn perimeter(rectangle: &Rectangle) -> u32 {
23+ │ fn perimeter(rectangle: &Rectangle) -> u32 {
24+ │ (rectangle.width + rectangle.height) * 2
24+ │ (rectangle.width + rectangle.height) * 2
25+ │ }
25+ │ }
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+~ │ */
26──┴─────────────────────────────────────────────────────────────────────────────
40──┴─────────────────────────────────────────────────────────────────────────────
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 @@
16 16 │ fn area(rectangle: &Rectangle) -> u32 {
16 16 │ fn area(rectangle: &Rectangle) -> u32 {
17 17 │ rectangle.width * rectangle.height
17 17 │ rectangle.width * rectangle.height
18 18 │ }
18 18 │ }
19− 19 + │
19+ 19 │
20 20 + │ fn perimeter(rectangle: &Rectangle) -> u32 {
20 20 + │ fn perimeter(rectangle: &Rectangle) -> u32 {
21 21 + │ (rectangle.width + rectangle.height) * 2
21 21 + │ (rectangle.width + rectangle.height) * 2
22 22 + │ }
22 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 ~ │ */
23───────┴────────────────────────────────────────────────────────────────────────
37───────┴────────────────────────────────────────────────────────────────────────
tests/snapshots/output/changes,header.snapshot.txt → tests/snapshots/output/changes_header.snapshot.txtrenamed+15−1
@@ -17,7 +17,21 @@ _ fn main() {
17 fn area(rectangle: &Rectangle) -> u32 {
17 fn area(rectangle: &Rectangle) -> u32 {
18 rectangle.width * rectangle.height
18 rectangle.width * rectangle.height
19 }
19 }
20−+
20+
21+ fn perimeter(rectangle: &Rectangle) -> u32 {
21+ fn perimeter(rectangle: &Rectangle) -> u32 {
22+ (rectangle.width + rectangle.height) * 2
22+ (rectangle.width + rectangle.height) * 2
23+ }
23+ }
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 @@
17 16 fn area(rectangle: &Rectangle) -> u32 {
17 16 fn area(rectangle: &Rectangle) -> u32 {
18 17 rectangle.width * rectangle.height
18 17 rectangle.width * rectangle.height
19 18 }
19 18 }
20− 19 +
20+ 19
21 20 + fn perimeter(rectangle: &Rectangle) -> u32 {
21 20 + fn perimeter(rectangle: &Rectangle) -> u32 {
22 21 + (rectangle.width + rectangle.height) * 2
22 21 + (rectangle.width + rectangle.height) * 2
23 22 + }
23 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 @@
16 16 fn area(rectangle: &Rectangle) -> u32 {
16 16 fn area(rectangle: &Rectangle) -> u32 {
17 17 rectangle.width * rectangle.height
17 17 rectangle.width * rectangle.height
18 18 }
18 18 }
19− 19 +
19+ 19
20 20 + fn perimeter(rectangle: &Rectangle) -> u32 {
20 20 + fn perimeter(rectangle: &Rectangle) -> u32 {
21 21 + (rectangle.width + rectangle.height) * 2
21 21 + (rectangle.width + rectangle.height) * 2
22 22 + }
22 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 @@
19 16 │ fn area(rectangle: &Rectangle) -> u32 {
19 16 │ fn area(rectangle: &Rectangle) -> u32 {
20 17 │ rectangle.width * rectangle.height
20 17 │ rectangle.width * rectangle.height
21 18 │ }
21 18 │ }
22− 19 + │
22+ 19 │
23 20 + │ fn perimeter(rectangle: &Rectangle) -> u32 {
23 20 + │ fn perimeter(rectangle: &Rectangle) -> u32 {
24 21 + │ (rectangle.width + rectangle.height) * 2
24 21 + │ (rectangle.width + rectangle.height) * 2
25 22 + │ }
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 ~ │ */
26───────┴────────────────────────────────────────────────────────────────────────
40───────┴────────────────────────────────────────────────────────────────────────
tests/snapshots/output/grid.snapshot.txt+14
@@ -20,4 +20,18 @@ fn area(rectangle: &Rectangle) -> u32 {
20fn perimeter(rectangle: &Rectangle) -> u32 {
20fn perimeter(rectangle: &Rectangle) -> u32 {
21 (rectangle.width + rectangle.height) * 2
21 (rectangle.width + rectangle.height) * 2
22}
22}
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+*/
23────────────────────────────────────────────────────────────────────────────────
37────────────────────────────────────────────────────────────────────────────────
tests/snapshots/output/grid,header.snapshot.txt → tests/snapshots/output/grid_header.snapshot.txtrenamed+14
@@ -23,4 +23,18 @@ fn area(rectangle: &Rectangle) -> u32 {
23fn perimeter(rectangle: &Rectangle) -> u32 {
23fn perimeter(rectangle: &Rectangle) -> u32 {
24 (rectangle.width + rectangle.height) * 2
24 (rectangle.width + rectangle.height) * 2
25}
25}
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+*/
26────────────────────────────────────────────────────────────────────────────────
40────────────────────────────────────────────────────────────────────────────────
tests/snapshots/output/grid,header,numbers.snapshot.txt → tests/snapshots/output/grid_header_numbers.snapshot.txtrenamed+14
@@ -23,4 +23,18 @@
23 20 │ fn perimeter(rectangle: &Rectangle) -> u32 {
23 20 │ fn perimeter(rectangle: &Rectangle) -> u32 {
24 21 │ (rectangle.width + rectangle.height) * 2
24 21 │ (rectangle.width + rectangle.height) * 2
25 22 │ }
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 │ */
26─────┴──────────────────────────────────────────────────────────────────────────
40─────┴──────────────────────────────────────────────────────────────────────────
tests/snapshots/output/grid,numbers.snapshot.txt → tests/snapshots/output/grid_numbers.snapshot.txtrenamed+14
@@ -20,4 +20,18 @@
20 20 │ fn perimeter(rectangle: &Rectangle) -> u32 {
20 20 │ fn perimeter(rectangle: &Rectangle) -> u32 {
21 21 │ (rectangle.width + rectangle.height) * 2
21 21 │ (rectangle.width + rectangle.height) * 2
22 22 │ }
22 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 │ */
23─────┴──────────────────────────────────────────────────────────────────────────
37─────┴──────────────────────────────────────────────────────────────────────────
tests/snapshots/output/header.snapshot.txt+14
@@ -21,3 +21,17 @@ fn area(rectangle: &Rectangle) -> u32 {
21fn perimeter(rectangle: &Rectangle) -> u32 {
21fn perimeter(rectangle: &Rectangle) -> u32 {
22 (rectangle.width + rectangle.height) * 2
22 (rectangle.width + rectangle.height) * 2
23}
23}
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 @@
21 20 fn perimeter(rectangle: &Rectangle) -> u32 {
21 20 fn perimeter(rectangle: &Rectangle) -> u32 {
22 21 (rectangle.width + rectangle.height) * 2
22 21 (rectangle.width + rectangle.height) * 2
23 22 }
23 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 @@
20 20 fn perimeter(rectangle: &Rectangle) -> u32 {
20 20 fn perimeter(rectangle: &Rectangle) -> u32 {
21 21 (rectangle.width + rectangle.height) * 2
21 21 (rectangle.width + rectangle.height) * 2
22 22 }
22 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 {
20fn perimeter(rectangle: &Rectangle) -> u32 {
20fn perimeter(rectangle: &Rectangle) -> u32 {
21 (rectangle.width + rectangle.height) * 2
21 (rectangle.width + rectangle.height) * 2
22}
22}
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 @@
19 16 │ fn area(rectangle: &Rectangle) -> u32 {
19 16 │ fn area(rectangle: &Rectangle) -> u32 {
20 17 │ rectangle.width * rectangle.height
20 17 │ rectangle.width * rectangle.height
21 18 │ }
21 18 │ }
22− 19 + │
22+ 19 │
23 20 + │ fn perimeter(rectangle: &Rectangle) -> u32 {
23 20 + │ fn perimeter(rectangle: &Rectangle) -> u32 {
24 21 + │ (rectangle.width + rectangle.height) * 2
24 21 + │ (rectangle.width + rectangle.height) * 2
25 22 + │ }
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 ~ │ */
26───────┴────────────────────────────────────────────────────────────────────────
40───────┴────────────────────────────────────────────────────────────────────────
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 {
20fn perimeter(rectangle: &Rectangle) -> u32 {
20fn perimeter(rectangle: &Rectangle) -> u32 {
21 (rectangle.width + rectangle.height) * 2
21 (rectangle.width + rectangle.height) * 2
22}
22}
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() {
16fn area(rectangle: &Rectangle) -> u32 {
16fn area(rectangle: &Rectangle) -> u32 {
17 rectangle.width * rectangle.height
17 rectangle.width * rectangle.height
18}
18}
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 {
38 BatTester { temp_dir, exe }
38 BatTester { temp_dir, exe }
39 }
39 }
40
40
41− pub fn test_snapshot(&self, style: &str) {
41+ pub fn test_snapshot(&self, name: &str, style: &str, tab_width: u32, wrap: bool) {
42 let output = Command::new(&self.exe)
42 let output = Command::new(&self.exe)
43 .current_dir(self.temp_dir.path())
43 .current_dir(self.temp_dir.path())
44 .args(&[
44 .args(&[
45 "sample.rs",
45 "sample.rs",
46+ "--paging=never",
47+ "--color=never",
46 "--decorations=always",
48 "--decorations=always",
47 "--terminal-width=80",
49 "--terminal-width=80",
50+ &format!("--wrap={}", if wrap { "character" } else { "never" }),
51+ &format!("--tabs={}", tab_width),
48 &format!("--style={}", style),
52 &format!("--style={}", style),
49 ]).output()
53 ]).output()
50 .expect("bat failed");
54 .expect("bat failed");
@@ -55,7 +59,7 @@ impl BatTester {
55 .replace("tests/snapshots/", "");
59 .replace("tests/snapshots/", "");
56
60
57 let mut expected = String::new();
61 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))
59 .expect("snapshot file missing");
63 .expect("snapshot file missing");
60 file.read_to_string(&mut expected)
64 file.read_to_string(&mut expected)
61 .expect("could not read snapshot file");
65 .expect("could not read snapshot file");
tests/tests.rs+25−19
@@ -3,33 +3,39 @@ mod tester;
3use tester::BatTester;
3use tester::BatTester;
4
4
5macro_rules! snapshot_tests {
5macro_rules! snapshot_tests {
6− ($($test_name: ident: $style: expr,)*) => {
6+ ($($test_name: ident: $style: expr => [wrap: $wrap:expr, tabs: $tabs:expr],)*) => {
7 $(
7 $(
8 #[test]
8 #[test]
9 fn $test_name() {
9 fn $test_name() {
10 let bat_tester = BatTester::new();
10 let bat_tester = BatTester::new();
11− bat_tester.test_snapshot($style);
11+ bat_tester.test_snapshot(stringify!($test_name), $style, $tabs, $wrap);
12 }
12 }
13 )*
13 )*
14 };
14 };
15}
15}
16
16
17snapshot_tests! {
17snapshot_tests! {
18− changes: "changes",
18+ changes: "changes" => [wrap: false, tabs: 8],
19− grid: "grid",
19+ grid: "grid" => [wrap: false, tabs: 8],
20− header: "header",
20+ header: "header" => [wrap: false, tabs: 8],
21− numbers: "numbers",
21+ numbers: "numbers" => [wrap: false, tabs: 8],
22− changes_grid: "changes,grid",
22+ changes_grid: "changes,grid" => [wrap: false, tabs: 8],
23− changes_header: "changes,header",
23+ changes_header: "changes,header" => [wrap: false, tabs: 8],
24− changes_numbers: "changes,numbers",
24+ changes_numbers: "changes,numbers" => [wrap: false, tabs: 8],
25− grid_header: "grid,header",
25+ grid_header: "grid,header" => [wrap: false, tabs: 8],
26− grid_numbers: "grid,numbers",
26+ grid_numbers: "grid,numbers" => [wrap: false, tabs: 8],
27− header_numbers: "header,numbers",
27+ header_numbers: "header,numbers" => [wrap: false, tabs: 8],
28− changes_grid_header: "changes,grid,header",
28+ changes_grid_header: "changes,grid,header" => [wrap: false, tabs: 8],
29− changes_grid_numbers: "changes,grid,numbers",
29+ changes_grid_numbers: "changes,grid,numbers" => [wrap: false, tabs: 8],
30− changes_header_numbers: "changes,header,numbers",
30+ changes_header_numbers: "changes,header,numbers" => [wrap: false, tabs: 8],
31− grid_header_numbers: "grid,header,numbers",
31+ grid_header_numbers: "grid,header,numbers" => [wrap: false, tabs: 8],
32− changes_grid_header_numbers: "changes,grid,header,numbers",
32+ changes_grid_header_numbers: "changes,grid,header,numbers" => [wrap: false, tabs: 8],
33− full: "full",
33+ full: "full" => [wrap: false, tabs: 8],
34− plain: "plain",
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],
35}
41}