Skip to content

Commit

Permalink
Removed extraneous deps
Browse files Browse the repository at this point in the history
  • Loading branch information
feature-not-a-bug committed Feb 24, 2025
1 parent c361a56 commit 26ed54b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 20 deletions.
66 changes: 48 additions & 18 deletions lib/Patat/Images/WezTerm.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,32 @@

module Patat.Images.WezTerm
( backend
, Pane
, Size
, camelToSnake
, camelToSnakeCase
, wordsOn
) where


--------------------------------------------------------------------------------
import Codec.Picture
import Control.Exception (throwIO)
import Control.Monad (unless, when)
import qualified Data.Aeson as A
import Data.Aeson.Casing as AC
import qualified Data.ByteString as B
import qualified Data.ByteString.Base64 as B64
import qualified Data.ByteString.Lazy.UTF8 as BLU
import GHC.Generics (Generic)
import Patat.Cleanup (Cleanup)
import qualified Patat.Images.Internal as Internal
import System.Directory
import System.Environment (lookupEnv)
import System.Process
import Codec.Picture (DynamicImage,
Image (imageHeight, imageWidth),
decodeImage, dynamicMap)
import Control.Exception (throwIO)
import Control.Monad (unless, when)
import qualified Data.Aeson as A
import qualified Data.ByteString as B
import qualified Data.ByteString.Base64 as B64
import Data.Char (isUpper, toLower)
import qualified Data.Text.Lazy as TL
import Data.Text.Lazy.Encoding (encodeUtf8)
import GHC.Generics (Generic)
import Patat.Cleanup (Cleanup)
import qualified Patat.Images.Internal as Internal
import System.Directory (findExecutable)
import System.Environment (lookupEnv)
import System.Process (readProcess)


--------------------------------------------------------------------------------
Expand All @@ -42,7 +50,7 @@ data Pane =
} deriving (Show, Generic)

instance A.FromJSON Pane where
parseJSON = A.genericParseJSON $ AC.aesonPrefix AC.snakeCase
parseJSON = A.genericParseJSON $ A.defaultOptions { A.fieldLabelModifier = camelToSnakeCase . drop 4 }


--------------------------------------------------------------------------------
Expand All @@ -52,7 +60,7 @@ data Size =
} deriving (Show, Generic)

instance A.FromJSON Size where
parseJSON = A.genericParseJSON $ AC.aesonPrefix AC.snakeCase
parseJSON = A.genericParseJSON $ A.defaultOptions { A.fieldLabelModifier = camelToSnakeCase . drop 4 }


--------------------------------------------------------------------------------
Expand All @@ -72,7 +80,7 @@ drawImage path = do
content <- B.readFile path

wez <- wezExecutable
resp <- fmap BLU.fromString $ readProcess wez ["cli", "list", "--format", "json"] []
resp <- fmap (encodeUtf8 . TL.pack) $ readProcess wez ["cli", "list", "--format", "json"] []
let panes = (A.decode resp :: Maybe [Pane])

Internal.withEscapeSequence $ do
Expand Down Expand Up @@ -127,6 +135,28 @@ activePaneAspectRatio (Just x) =

--------------------------------------------------------------------------------
defaultAr :: Double
defaultAr = (4 / 3 :: Double) -- Good enough for a VT100
defaultAr = (4 / 3 :: Double) -- Good enough for a VT100


--------------------------------------------------------------------------------
camelToSnake :: String -> String
camelToSnake [] = []
camelToSnake (x:xs)
| isUpper x = '_' : toLower x : camelToSnake xs
| otherwise = x : camelToSnake xs


--------------------------------------------------------------------------------
camelToSnakeCase :: String -> String
camelToSnakeCase s = case camelToSnake s of
('_':rest) -> rest -- Remove any leading spaces
result -> result


--------------------------------------------------------------------------------
wordsOn :: (Char -> Bool) -> String -> [String]
wordsOn t s =
case dropWhile t s of
"" -> []
s' -> w : wordsOn t s''
where (w, s'') = break t s'
2 changes: 0 additions & 2 deletions patat.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ Library

Build-depends:
aeson >= 2.0 && < 2.3,
aeson-casing >= 0.1 && < 0.3,
ansi-terminal >= 0.6 && < 1.1,
ansi-wl-pprint >= 0.6 && < 1.1,
async >= 2.2 && < 2.3,
Expand All @@ -57,7 +56,6 @@ Library
text >= 1.2 && < 2.2,
time >= 1.4 && < 1.13,
unordered-containers >= 0.2 && < 0.3,
utf8-string >= 0.3.1 && < 2.0,
yaml >= 0.8 && < 0.12,
vector >= 0.13 && < 0.14,
wcwidth >= 0.0 && < 0.1,
Expand Down

0 comments on commit 26ed54b

Please sign in to comment.