@@ -150,7 +150,7 @@ import qualified Data.Text.IO
150150import qualified Data.Char as Char
151151import qualified Data.List as List
152152
153- import System.Exit (exitFailure )
153+ import qualified System.Exit (ExitCode ( .. ) )
154154
155155import Prelude hiding (lookup )
156156import qualified Data.ByteString as BS
@@ -510,67 +510,21 @@ formatHaskellValue label v =
510510
511511hindentPrintLabelled :: Show a => Text -> a -> IO a
512512hindentPrintLabelled label v = do
513- let
514- input = Text.Show.Unicode. ushow v
515-
516- -- if Prelude.length input > 10000
517- -- then
518- -- atomicPutStrLn $ "❌SKIPPED display, value show > 10,000 chars, here's a clip:\n" <> Prelude.take 1000 input
519- -- else do
520-
521- pathM <- Dir. findExecutable " hindent"
522- case pathM of
523- Just _ -> do
524- (exit, stdout, stderr) <- System.Process. readProcessWithExitCode " hindent" [" --line-length" ," 150" ] input
525- if Prelude. length stderr > 0
526- then
527- atomicPutStrLn $
528- " \n 🔶 "
529- <> T. unpack label
530- <> " \n ->"
531- <> stderr
532- <> " \n 📥 for input: \n "
533- <> input
534-
535- else
536- atomicPutStrLn $
537- " \n 🔶 "
538- <> T. unpack label
539- <> " \n ->"
540- <> stdout
541- Nothing -> do
542- debug_ " hindent missing, formatting without"
543- atomicPutStrLn $ show v
544-
513+ let input = Text.Show.Unicode. ushow v
514+ formatted <- hindent_ input
515+ atomicPutStrLn $
516+ " \n 🔶 "
517+ <> T. unpack label
518+ <> " \n ->"
519+ <> T. unpack formatted
545520 pure v
546521
547522
548523hindentPrint :: Show a => a -> IO a
549524hindentPrint v = do
550- let
551- input = Text.Show.Unicode. ushow v
552-
553- pathM <- Dir. findExecutable " hindent"
554- case pathM of
555- Just _ -> do
556- (exit, stdout, stderr) <- System.Process. readProcessWithExitCode " hindent" [" --line-length" ," 150" ] input
557- if Prelude. length stderr > 0
558- then
559- atomicPutStrLn $
560- " \n errors: \n "
561- <> stderr
562- <> " \n 📥 for input: \n "
563- <> input
564- <> " \n with output: \n "
565- <> stdout
566-
567- else
568- atomicPutStrLn stdout
569-
570- Nothing -> do
571- debug_ " hindent missing, formatting without"
572- atomicPutStrLn $ show v
573-
525+ let input = Text.Show.Unicode. ushow v
526+ formatted <- hindent_ input
527+ Ext.Common. atomicPutStrLn_ formatted
574528 pure v
575529
576530
@@ -581,15 +535,33 @@ hindent v =
581535
582536hindent_ :: String -> IO Text
583537hindent_ s = do
584- -- pure $ T.pack s
585- (exit, stdout, stderr) <-
586- System.Process. readProcessWithExitCode " hindent" [" --line-length" ," 150" ] s
587- `catchError` (\ err -> pure (error " no exit code on failure" , s, " hindent failed" ))
588- if Prelude. length stderr > 0
589- then
590- pure $ T. pack stderr
591- else
592- pure $ T. pack stdout
538+ pathM <- Dir. findExecutable " hindent"
539+ case pathM of
540+ Just _ -> do
541+ (exit, stdout, stderr) <-
542+ System.Process. readProcessWithExitCode " hindent" [" --line-length" ," 150" ] s
543+ `catchError` (\ err -> pure (error " no exit code on failure" , s, " hindent failed on input" ))
544+
545+ if exit /= System.Exit. ExitSuccess
546+ then
547+ pure $ T. pack stderr
548+ else
549+ if Prelude. length stderr > 0
550+ then
551+ pure $ T. pack $
552+ " \n errors: \n "
553+ <> stderr
554+ <> " \n 📥 for input: \n "
555+ <> s
556+ <> " \n with output: \n "
557+ <> stdout
558+
559+ else
560+ pure $ T. pack stdout
561+
562+ Nothing -> do
563+ debug_ " 🔥 hindent missing, returning without formatting"
564+ pure $ T. pack s
593565
594566
595567hindentFormatValue :: Show a => a -> Text
0 commit comments