@@ -38,9 +38,11 @@ import GHC.IO.Exception (IOErrorType(ResourceVanished), IOE
38
38
import Paths_fancydiff (version )
39
39
import Fancydiff.Lib (tryDiffWithSourceHighlight ,
40
40
commitHighlight ,
41
+ getHighlighterByFilename ,
41
42
getHighlighterFunc ,
42
43
getHighlighterFuncByFilename )
43
44
import Fancydiff.Formatting (fshow )
45
+ import qualified Fancydiff.SourceHighlight as SH
44
46
import Fancydiff.AnsiFormatting (ansiFormatting )
45
47
import Fancydiff.HTMLFormatting ( htmlFormatting
46
48
, mkHtmlFormat
@@ -132,6 +134,10 @@ mainOpts opts@Opts{..} = do
132
134
exitFailure
133
135
Right ok -> liftIO $ T. hPutStr outHandle $ fmt ok
134
136
137
+ formatOneHighlighter fmt outHandle highlighter = do
138
+ content <- B. hGetContents stdin
139
+ formatOne fmt content outHandle (getHighlighterFunc highlighter)
140
+
135
141
onCmd _ (Setup onlyAliases isLocal) _ = do
136
142
let git'print params = do
137
143
T. putStrLn $ T. concat $ [" Running: " ] ++ (intersperse " " $ map onParam params)
@@ -167,7 +173,7 @@ mainOpts opts@Opts{..} = do
167
173
content <- B. readFile filepath
168
174
formatOne fmt content outHandle (getHighlighterFuncByFilename (T. pack filepath))
169
175
170
- onCmd fmt (Stdin Nothing ) outHandle = do
176
+ onCmd fmt (Stdin Nothing Nothing ) outHandle = do
171
177
let path = " ."
172
178
withRepository lgFactory path $ do
173
179
let diffStart = B. isPrefixOf " diff "
@@ -183,9 +189,14 @@ mainOpts opts@Opts{..} = do
183
189
liftIO $ T. hPutStr outHandle $ fmt res
184
190
return ()
185
191
186
- onCmd fmt (Stdin (Just highlighter)) outHandle = do
187
- content <- B. hGetContents stdin
188
- formatOne fmt content outHandle (getHighlighterFunc highlighter)
192
+ onCmd fmt (Stdin (Just highlighter) Nothing ) outHandle = do
193
+ formatOneHighlighter fmt outHandle highlighter
194
+
195
+ onCmd fmt (Stdin _ (Just filename)) outHandle = do
196
+ let highlighter = getHighlighterByFilename $ T. pack filename
197
+ case highlighter of
198
+ SH. Generic -> exitFailure
199
+ _ -> formatOneHighlighter fmt outHandle highlighter
189
200
190
201
main :: IO ()
191
202
main = void $ execParser optsParser >>= mainOpts
0 commit comments