From fc4cac00d56ab64225f0c41cc2fb1dd3c9f28dfc Mon Sep 17 00:00:00 2001 From: Yu Cong Date: Sun, 29 Mar 2026 13:38:58 +0800 Subject: [PATCH] format code --- src/site.hs | 55 +++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/src/site.hs b/src/site.hs index 818db7f..8c80a0b 100644 --- a/src/site.hs +++ b/src/site.hs @@ -4,7 +4,6 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE StandaloneKindSignatures #-} -{-# LANGUAGE ViewPatterns #-} import ChaoDoc import Control.Concurrent (forkIO, threadDelay) @@ -23,6 +22,7 @@ import Data.Time.Format (defaultTimeLocale, formatTime) import Data.Time.LocalTime (getZonedTime) import Hakyll import Hakyll.Core.Runtime (RunMode (RunModeNormal)) +import Network.Wai.Application.Static (staticApp) import qualified Network.Wai.Handler.Warp as Warp import qualified Paths_hakysidian as Paths import System.Directory @@ -31,19 +31,18 @@ import System.Directory doesFileExist, getCurrentDirectory, getModificationTime, - listDirectory + listDirectory, ) import System.Environment (getArgs, getExecutablePath, lookupEnv) import System.Exit (ExitCode (..), die, exitSuccess, exitWith) import System.FilePath -import Network.Wai.Application.Static (staticApp) import System.IO ( BufferMode (NoBuffering), hFlush, hGetBuffering, hIsTerminalDevice, hSetBuffering, - stdout + stdout, ) import System.Process (CreateProcess (cwd), proc, readCreateProcessWithExitCode) import Text.Pandoc (HTMLMathMethod (MathML), WriterOptions (..), compileTemplate) @@ -232,8 +231,8 @@ validateProject projectRoot = do unless (null missing) $ die $ unlines $ - "hakysidian is missing required project inputs:" : - map (" - " ++) missing + "hakysidian is missing required project inputs:" + : map (" - " ++) missing initialDashboardState :: DashboardState initialDashboardState = @@ -294,14 +293,16 @@ withWatchTui action = do then do originalBuffering <- hGetBuffering stdout bracket_ - (do + ( do hSetBuffering stdout NoBuffering putStr "\ESC[?1049h\ESC[2J\ESC[H\ESC[?25l" - hFlush stdout) - (do + hFlush stdout + ) + ( do putStr "\ESC[0m\ESC[?25h\ESC[?1049l" hFlush stdout - hSetBuffering stdout originalBuffering) + hSetBuffering stdout originalBuffering + ) action else action @@ -351,7 +352,7 @@ renderWatchDashboard renderStateRef projectRoot config watchSettings serverStatu dashboardTitleRow :: Int -> String -> String -> String dashboardTitleRow width leftText rightText = - dashboardFramedRow width (leftText ++ spacer ++ clippedRight) + dashboardRow width (leftText ++ spacer ++ clippedRight) where usableWidth = max 1 (width - 4) rightWidth = min (usableWidth `div` 3) (length rightText) @@ -366,10 +367,7 @@ dashboardTitleRow width leftText rightText = | otherwise = replicate (max 1 (usableWidth - length clippedLeft - length clippedRight)) ' ' dashboardRow :: Int -> String -> String -dashboardRow width = dashboardFramedRow width - -dashboardFramedRow :: Int -> String -> String -dashboardFramedRow width content = +dashboardRow width content = "| " ++ padRight usableWidth (ellipsize usableWidth content) ++ " |" where usableWidth = max 1 (width - 4) @@ -405,8 +403,8 @@ getTerminalSize = do case sttySize of Just terminalSize -> pure terminalSize Nothing -> do - rows <- maybe 24 id . (>>= readMaybe) <$> lookupEnv "LINES" - cols <- maybe 80 id . (>>= readMaybe) <$> lookupEnv "COLUMNS" + rows <- fromMaybe 24 . (>>= readMaybe) <$> lookupEnv "LINES" + cols <- fromMaybe 80 . (>>= readMaybe) <$> lookupEnv "COLUMNS" pure (TerminalSize rows cols) queryTerminalSize :: IO (Maybe TerminalSize) @@ -415,7 +413,8 @@ queryTerminalSize = do try $ readCreateProcessWithExitCode (proc "sh" ["-c", "stty size writeIORef serverStatusRef (ServerFailed (show err)) @@ -592,9 +592,10 @@ startPreviewServer config watchSettings serverStatusRef where settings = Warp.setBeforeMainLoop (writeIORef serverStatusRef ServerRunning) $ - Warp.setPort (watchPort watchSettings) $ - Warp.setHost (fromString (watchHost watchSettings)) $ - Warp.defaultSettings + Warp.setPort (watchPort watchSettings) $ + Warp.setHost + (fromString (watchHost watchSettings)) + Warp.defaultSettings snapshotInputs :: FilePath -> IO FileSnapshot snapshotInputs projectRoot = do @@ -625,8 +626,8 @@ trackedFilesIn root = do if exists then do entries <- listDirectory root - fmap concat $ - traverse + fmap concat + <$> traverse ( \name -> do let path = root name isDir <- doesDirectoryExist path