mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-05-19 11:30:22 -07:00
minor hlint cleanup of Prompt and XMonad.Prompt.* sub-modules
This commit is contained in:
parent
104cc6ba25
commit
097d7367bb
@ -171,12 +171,12 @@ class XPrompt t where
|
|||||||
-- string presently in the command line and the list of
|
-- string presently in the command line and the list of
|
||||||
-- completion.
|
-- completion.
|
||||||
nextCompletion :: t -> String -> [String] -> String
|
nextCompletion :: t -> String -> [String] -> String
|
||||||
nextCompletion t c l = getNextOfLastWord t c l
|
nextCompletion = getNextOfLastWord
|
||||||
|
|
||||||
-- | This method is used to generate the string to be passed to
|
-- | This method is used to generate the string to be passed to
|
||||||
-- the completion function.
|
-- the completion function.
|
||||||
commandToComplete :: t -> String -> String
|
commandToComplete :: t -> String -> String
|
||||||
commandToComplete _ c = getLastWord c
|
commandToComplete _ = getLastWord
|
||||||
|
|
||||||
-- | This method is used to process each completion in order to
|
-- | This method is used to process each completion in order to
|
||||||
-- generate the string that will be compared with the command
|
-- generate the string that will be compared with the command
|
||||||
@ -259,7 +259,7 @@ mkXPromptWithReturn t conf compl action = do
|
|||||||
let d = display c
|
let d = display c
|
||||||
rw = theRoot c
|
rw = theRoot c
|
||||||
s <- gets $ screenRect . W.screenDetail . W.current . windowset
|
s <- gets $ screenRect . W.screenDetail . W.current . windowset
|
||||||
hist <- liftIO $ readHistory
|
hist <- liftIO readHistory
|
||||||
w <- liftIO $ createWin d rw conf s
|
w <- liftIO $ createWin d rw conf s
|
||||||
liftIO $ selectInput d w $ exposureMask .|. keyPressMask
|
liftIO $ selectInput d w $ exposureMask .|. keyPressMask
|
||||||
gc <- liftIO $ createGC d w
|
gc <- liftIO $ createGC d w
|
||||||
@ -489,8 +489,7 @@ startOfLine =
|
|||||||
|
|
||||||
-- | Flush the command string and reset the offset
|
-- | Flush the command string and reset the offset
|
||||||
flushString :: XP ()
|
flushString :: XP ()
|
||||||
flushString = do
|
flushString = modify $ \s -> setCommand "" $ s { offset = 0}
|
||||||
modify $ \s -> setCommand "" $ s { offset = 0}
|
|
||||||
|
|
||||||
-- | Insert a character at the cursor position
|
-- | Insert a character at the cursor position
|
||||||
insertString :: String -> XP ()
|
insertString :: String -> XP ()
|
||||||
@ -503,7 +502,7 @@ insertString str =
|
|||||||
|
|
||||||
-- | Insert the current X selection string at the cursor position.
|
-- | Insert the current X selection string at the cursor position.
|
||||||
pasteString :: XP ()
|
pasteString :: XP ()
|
||||||
pasteString = join $ io $ liftM insertString $ getSelection
|
pasteString = join $ io $ liftM insertString getSelection
|
||||||
|
|
||||||
-- | Copy the currently entered string into the X selection.
|
-- | Copy the currently entered string into the X selection.
|
||||||
copyString :: XP ()
|
copyString :: XP ()
|
||||||
@ -538,8 +537,8 @@ moveWord d = do
|
|||||||
' ':x -> 1 + lenToS x
|
' ':x -> 1 + lenToS x
|
||||||
x -> lenToS x
|
x -> lenToS x
|
||||||
newoff = case d of
|
newoff = case d of
|
||||||
Prev -> o - (ln reverse f )
|
Prev -> o - ln reverse f
|
||||||
Next -> o + (ln id ss)
|
Next -> o + ln id ss
|
||||||
modify $ \s -> s { offset = newoff }
|
modify $ \s -> s { offset = newoff }
|
||||||
|
|
||||||
moveHistory :: (W.Stack String -> W.Stack String) -> XP ()
|
moveHistory :: (W.Stack String -> W.Stack String) -> XP ()
|
||||||
@ -626,7 +625,7 @@ printPrompt drw = do
|
|||||||
getCompletions :: XP [String]
|
getCompletions :: XP [String]
|
||||||
getCompletions = do
|
getCompletions = do
|
||||||
s <- get
|
s <- get
|
||||||
io $ (completionFunction s) (commandToComplete (xptype s) (command s))
|
io $ completionFunction s (commandToComplete (xptype s) (command s))
|
||||||
`catch` \_ -> return []
|
`catch` \_ -> return []
|
||||||
|
|
||||||
setComplWin :: Window -> ComplWindowDim -> XP ()
|
setComplWin :: Window -> ComplWindowDim -> XP ()
|
||||||
@ -666,9 +665,9 @@ getComplWinDim compl = do
|
|||||||
|
|
||||||
tws <- mapM (textWidthXMF (dpy st) fs) compl
|
tws <- mapM (textWidthXMF (dpy st) fs) compl
|
||||||
let max_compl_len = fromIntegral ((fi ht `div` 2) + maximum tws)
|
let max_compl_len = fromIntegral ((fi ht `div` 2) + maximum tws)
|
||||||
columns = max 1 $ wh `div` (fi max_compl_len)
|
columns = max 1 $ wh `div` fi max_compl_len
|
||||||
rem_height = rect_height scr - ht
|
rem_height = rect_height scr - ht
|
||||||
(rows,r) = (length compl) `divMod` fi columns
|
(rows,r) = length compl `divMod` fi columns
|
||||||
needed_rows = max 1 (rows + if r == 0 then 0 else 1)
|
needed_rows = max 1 (rows + if r == 0 then 0 else 1)
|
||||||
actual_max_number_of_rows = rem_height `div` ht
|
actual_max_number_of_rows = rem_height `div` ht
|
||||||
actual_rows = min actual_max_number_of_rows (fi needed_rows)
|
actual_rows = min actual_max_number_of_rows (fi needed_rows)
|
||||||
@ -700,7 +699,7 @@ drawComplWin w compl = do
|
|||||||
p <- io $ createPixmap d w wh ht
|
p <- io $ createPixmap d w wh ht
|
||||||
(defaultDepthOfScreen scr)
|
(defaultDepthOfScreen scr)
|
||||||
io $ fillDrawable d p gc border bgcolor (fi bw) wh ht
|
io $ fillDrawable d p gc border bgcolor (fi bw) wh ht
|
||||||
let ac = splitInSubListsAt (length yy) (take ((length xx) * (length yy)) compl)
|
let ac = splitInSubListsAt (length yy) (take (length xx * length yy) compl)
|
||||||
printComplList d p gc (fgColor c) (bgColor c) xx yy ac
|
printComplList d p gc (fgColor c) (bgColor c) xx yy ac
|
||||||
io $ copyArea d p w gc 0 0 wh ht 0 0
|
io $ copyArea d p w gc 0 0 wh ht 0 0
|
||||||
io $ freePixmap d p
|
io $ freePixmap d p
|
||||||
@ -712,7 +711,7 @@ redrawComplWin compl = do
|
|||||||
let recreate = do destroyComplWin
|
let recreate = do destroyComplWin
|
||||||
w <- createComplWin nwi
|
w <- createComplWin nwi
|
||||||
drawComplWin w compl
|
drawComplWin w compl
|
||||||
if (compl /= [] && showComplWin st)
|
if compl /= [] && showComplWin st
|
||||||
then case complWin st of
|
then case complWin st of
|
||||||
Just w -> case complWinDim st of
|
Just w -> case complWinDim st of
|
||||||
Just wi -> if nwi == wi -- complWinDim did not change
|
Just wi -> if nwi == wi -- complWinDim did not change
|
||||||
|
@ -61,6 +61,4 @@ appendFilePrompt c fn = mkXPrompt (AppendFile fn)
|
|||||||
|
|
||||||
-- | Append a string to a file.
|
-- | Append a string to a file.
|
||||||
doAppend :: FilePath -> String -> X ()
|
doAppend :: FilePath -> String -> X ()
|
||||||
doAppend fn s = io $ bracket (openFile fn AppendMode)
|
doAppend fn = io . bracket (openFile fn AppendMode) hClose . flip hPutStrLn
|
||||||
hClose
|
|
||||||
(flip hPutStrLn s)
|
|
||||||
|
@ -31,7 +31,7 @@ instance XPrompt Dir where
|
|||||||
showXPrompt (Dir x) = x
|
showXPrompt (Dir x) = x
|
||||||
|
|
||||||
directoryPrompt :: XPConfig -> String -> (String -> X ()) -> X ()
|
directoryPrompt :: XPConfig -> String -> (String -> X ()) -> X ()
|
||||||
directoryPrompt c prom job = mkXPrompt (Dir prom) c getDirCompl job
|
directoryPrompt c prom = mkXPrompt (Dir prom) c getDirCompl
|
||||||
|
|
||||||
getDirCompl :: String -> IO [String]
|
getDirCompl :: String -> IO [String]
|
||||||
getDirCompl s = (filter notboring . lines) `fmap`
|
getDirCompl s = (filter notboring . lines) `fmap`
|
||||||
|
@ -25,7 +25,7 @@ import XMonad.Prompt.Shell
|
|||||||
import XMonad.Actions.WindowGo (runOrRaise)
|
import XMonad.Actions.WindowGo (runOrRaise)
|
||||||
import XMonad.Util.Run (runProcessWithInput)
|
import XMonad.Util.Run (runProcessWithInput)
|
||||||
|
|
||||||
import Control.Monad (liftM2)
|
import Control.Monad (liftM, liftM2)
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import System.Directory (doesDirectoryExist, doesFileExist, executable, getPermissions)
|
import System.Directory (doesDirectoryExist, doesFileExist, executable, getPermissions)
|
||||||
|
|
||||||
@ -47,15 +47,15 @@ instance XPrompt RunOrRaisePrompt where
|
|||||||
showXPrompt RRP = "Run or Raise: "
|
showXPrompt RRP = "Run or Raise: "
|
||||||
|
|
||||||
runOrRaisePrompt :: XPConfig -> X ()
|
runOrRaisePrompt :: XPConfig -> X ()
|
||||||
runOrRaisePrompt c = do cmds <- io $ getCommands
|
runOrRaisePrompt c = do cmds <- io getCommands
|
||||||
mkXPrompt RRP c (getShellCompl cmds) open
|
mkXPrompt RRP c (getShellCompl cmds) open
|
||||||
open :: String -> X ()
|
open :: String -> X ()
|
||||||
open path = (io $ isNormalFile path) >>= \b ->
|
open path = io (isNormalFile path) >>= \b ->
|
||||||
if b
|
if b
|
||||||
then spawn $ "xdg-open \"" ++ path ++ "\""
|
then spawn $ "xdg-open \"" ++ path ++ "\""
|
||||||
else uncurry runOrRaise . getTarget $ path
|
else uncurry runOrRaise . getTarget $ path
|
||||||
where
|
where
|
||||||
isNormalFile f = exists f >>= \e -> if e then (notExecutable f) else return False
|
isNormalFile f = exists f >>= \e -> if e then notExecutable f else return False
|
||||||
exists f = fmap or $ sequence [doesFileExist f,doesDirectoryExist f]
|
exists f = fmap or $ sequence [doesFileExist f,doesDirectoryExist f]
|
||||||
notExecutable = fmap (not . executable) . getPermissions
|
notExecutable = fmap (not . executable) . getPermissions
|
||||||
getTarget x = (x,isApp x)
|
getTarget x = (x,isApp x)
|
||||||
@ -66,12 +66,12 @@ isApp "thunderbird" = className =? "Thunderbird-bin" <||> className =? "Thunderb
|
|||||||
isApp x = liftM2 (==) pid $ pidof x
|
isApp x = liftM2 (==) pid $ pidof x
|
||||||
|
|
||||||
pidof :: String -> Query Int
|
pidof :: String -> Query Int
|
||||||
pidof x = io $ (runProcessWithInput "pidof" [x] [] >>= readIO) `catch` (\_ -> return $ 0)
|
pidof x = io $ (runProcessWithInput "pidof" [x] [] >>= readIO) `catch` (\_ -> return 0)
|
||||||
|
|
||||||
pid :: Query Int
|
pid :: Query Int
|
||||||
pid = ask >>= (\w -> liftX $ withDisplay $ \d -> getPID d w)
|
pid = ask >>= (\w -> liftX $ withDisplay $ \d -> getPID d w)
|
||||||
where getPID d w = getAtom "_NET_WM_PID" >>= \a -> io $
|
where getPID d w = getAtom "_NET_WM_PID" >>= \a -> io $
|
||||||
getWindowProperty32 d a w >>= return . getPID'
|
liftM getPID' (getWindowProperty32 d a w)
|
||||||
getPID' (Just (x:_)) = fromIntegral x
|
getPID' (Just (x:_)) = fromIntegral x
|
||||||
getPID' (Just []) = -1
|
getPID' (Just []) = -1
|
||||||
getPID' (Nothing) = -1
|
getPID' (Nothing) = -1
|
||||||
|
@ -57,7 +57,7 @@ instance XPrompt Shell where
|
|||||||
|
|
||||||
shellPrompt :: XPConfig -> X ()
|
shellPrompt :: XPConfig -> X ()
|
||||||
shellPrompt c = do
|
shellPrompt c = do
|
||||||
cmds <- io $ getCommands
|
cmds <- io getCommands
|
||||||
mkXPrompt Shell c (getShellCompl cmds) (spawn . encodeOutput)
|
mkXPrompt Shell c (getShellCompl cmds) (spawn . encodeOutput)
|
||||||
|
|
||||||
-- | See safe and unsafeSpawn. prompt is an alias for safePrompt;
|
-- | See safe and unsafeSpawn. prompt is an alias for safePrompt;
|
||||||
|
@ -54,11 +54,11 @@ instance XPrompt Ssh where
|
|||||||
|
|
||||||
sshPrompt :: XPConfig -> X ()
|
sshPrompt :: XPConfig -> X ()
|
||||||
sshPrompt c = do
|
sshPrompt c = do
|
||||||
sc <- io $ sshComplList
|
sc <- io sshComplList
|
||||||
mkXPrompt Ssh c (mkComplFunFromList sc) ssh
|
mkXPrompt Ssh c (mkComplFunFromList sc) ssh
|
||||||
|
|
||||||
ssh :: String -> X ()
|
ssh :: String -> X ()
|
||||||
ssh s = runInTerm "" ("ssh " ++ s)
|
ssh = runInTerm "" . ("ssh " ++ )
|
||||||
|
|
||||||
sshComplList :: IO [String]
|
sshComplList :: IO [String]
|
||||||
sshComplList = uniqSort `fmap` liftM2 (++) sshComplListLocal sshComplListGlobal
|
sshComplList = uniqSort `fmap` liftM2 (++) sshComplListLocal sshComplListGlobal
|
||||||
|
@ -68,9 +68,9 @@ instance XPrompt WindowPrompt where
|
|||||||
nextCompletion _ = getNextCompletion
|
nextCompletion _ = getNextCompletion
|
||||||
|
|
||||||
windowPromptGoto, windowPromptBring, windowPromptBringCopy :: XPConfig -> X ()
|
windowPromptGoto, windowPromptBring, windowPromptBringCopy :: XPConfig -> X ()
|
||||||
windowPromptGoto c = doPrompt Goto c
|
windowPromptGoto = doPrompt Goto
|
||||||
windowPromptBring c = doPrompt Bring c
|
windowPromptBring = doPrompt Bring
|
||||||
windowPromptBringCopy c = doPrompt BringCopy c
|
windowPromptBringCopy = doPrompt BringCopy
|
||||||
|
|
||||||
-- | Pops open a prompt with window titles. Choose one, and you will be
|
-- | Pops open a prompt with window titles. Choose one, and you will be
|
||||||
-- taken to the corresponding workspace.
|
-- taken to the corresponding workspace.
|
||||||
@ -94,4 +94,4 @@ doPrompt t c = do
|
|||||||
|
|
||||||
-- | Brings a copy of the specified window into the current workspace.
|
-- | Brings a copy of the specified window into the current workspace.
|
||||||
bringCopyWindow :: Window -> WindowSet -> WindowSet
|
bringCopyWindow :: Window -> WindowSet -> WindowSet
|
||||||
bringCopyWindow w ws = copyWindow w (W.currentTag $ ws) ws
|
bringCopyWindow w ws = copyWindow w (W.currentTag ws) ws
|
||||||
|
Loading…
x
Reference in New Issue
Block a user