format code

This commit is contained in:
2026-03-29 13:38:58 +08:00
parent 55719f3444
commit fc4cac00d5
+28 -27
View File
@@ -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 </dev/tty"])
"" :: IO (Either SomeException (ExitCode, String, String))
"" ::
IO (Either SomeException (ExitCode, String, String))
pure $ do
(exitCode, stdoutText, _) <- either (const Nothing) Just result
case exitCode of
@@ -580,10 +579,11 @@ startPreviewServer config watchSettings serverStatusRef
forkIO $
do
result <-
(try $
Warp.runSettings settings $
staticApp $
previewSettings config (destinationDirectory config)) ::
( try $
Warp.runSettings settings $
staticApp $
previewSettings config (destinationDirectory config)
) ::
IO (Either SomeException ())
case result of
Left err -> 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