mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-05-19 03:20:21 -07:00
X.Prompt: Document printComplList, rename
This commit is contained in:
parent
5f58fb5cd1
commit
26c4fb0f2d
@ -4,6 +4,7 @@
|
|||||||
{-# LANGUAGE ExistentialQuantification #-}
|
{-# LANGUAGE ExistentialQuantification #-}
|
||||||
{-# LANGUAGE CPP #-}
|
{-# LANGUAGE CPP #-}
|
||||||
{-# LANGUAGE NamedFieldPuns #-}
|
{-# LANGUAGE NamedFieldPuns #-}
|
||||||
|
{-# LANGUAGE PatternGuards #-}
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
-- |
|
-- |
|
||||||
-- Module : XMonad.Prompt
|
-- Module : XMonad.Prompt
|
||||||
@ -1581,51 +1582,59 @@ getComplWinDim compl = do
|
|||||||
|
|
||||||
-- | Draw the completion window.
|
-- | Draw the completion window.
|
||||||
drawComplWin :: Window -> [String] -> XP ()
|
drawComplWin :: Window -> [String] -> XP ()
|
||||||
drawComplWin w compl = do
|
drawComplWin w entries = do
|
||||||
XPS{ config, color, dpy, gcon } <- get
|
XPS{ config, color, dpy, gcon } <- get
|
||||||
let scr = defaultScreenOfDisplay dpy
|
let scr = defaultScreenOfDisplay dpy
|
||||||
bw = promptBorderWidth config
|
bw = promptBorderWidth config
|
||||||
Just bgcolor <- io $ initColor dpy (bgNormal color)
|
Just bgcolor <- io $ initColor dpy (bgNormal color)
|
||||||
Just borderC <- io $ initColor dpy (border color)
|
Just borderC <- io $ initColor dpy (border color)
|
||||||
ComplWindowDim{ cwWidth, cwRowHeight, cwCols, cwRows } <- getComplWinDim compl
|
cwd@ComplWindowDim{ cwWidth, cwRowHeight } <- getComplWinDim entries
|
||||||
|
|
||||||
p <- io $ createPixmap dpy w cwWidth cwRowHeight (defaultDepthOfScreen scr)
|
p <- io $ createPixmap dpy w cwWidth cwRowHeight (defaultDepthOfScreen scr)
|
||||||
io $ fillDrawable dpy p gcon borderC bgcolor (fi bw) cwWidth cwRowHeight
|
io $ fillDrawable dpy p gcon borderC bgcolor (fi bw) cwWidth cwRowHeight
|
||||||
let ac = chunksOf (length cwRows) (take (length cwCols * length cwRows) compl)
|
printComplEntries dpy p gcon (fgNormal color) (bgNormal color) entries cwd
|
||||||
|
|
||||||
printComplList dpy p gcon (fgNormal color) (bgNormal color) cwCols cwRows ac
|
|
||||||
--lift $ spawn $ "xmessage " ++ " ac: " ++ show ac ++ " xx: " ++ show xx ++ " length xx: " ++ show (length xx) ++ " yy: " ++ show (length yy)
|
--lift $ spawn $ "xmessage " ++ " ac: " ++ show ac ++ " xx: " ++ show xx ++ " length xx: " ++ show (length xx) ++ " yy: " ++ show (length yy)
|
||||||
io $ copyArea dpy p w gcon 0 0 cwWidth cwRowHeight 0 0
|
io $ copyArea dpy p w gcon 0 0 cwWidth cwRowHeight 0 0
|
||||||
io $ freePixmap dpy p
|
io $ freePixmap dpy p
|
||||||
|
|
||||||
-- Finds the column and row indexes in which a string appears.
|
-- | Print all of the completion entries.
|
||||||
-- if the string is not in the matrix, the indexes default to (0,0)
|
printComplEntries
|
||||||
findComplIndex :: String -> [[String]] -> (Int,Int)
|
:: Display
|
||||||
findComplIndex x xss = let
|
-> Drawable
|
||||||
colIndex = fromMaybe 0 $ findIndex (\cols -> x `elem` cols) xss
|
-> GC
|
||||||
rowIndex = fromMaybe 0 $ elemIndex x $ (!!) xss colIndex
|
-> String -- ^ Default foreground color
|
||||||
in (colIndex,rowIndex)
|
-> String -- ^ Default background color
|
||||||
|
-> [String] -- ^ Entries to be printed...
|
||||||
|
-> ComplWindowDim -- ^ ...into a window of this size
|
||||||
|
-> XP ()
|
||||||
|
printComplEntries dpy drw gc fc bc entries ComplWindowDim{ cwCols, cwRows } = do
|
||||||
|
st@XPS{ color, complIndex, config = XPC{ alwaysHighlight } } <- get
|
||||||
|
let printItemAt :: Position -> Position -> String -> XP ()
|
||||||
|
printItemAt x y item =
|
||||||
|
printStringXMF dpy drw (fontS st) gc fgCol bgCol x y item
|
||||||
|
where
|
||||||
|
(fgCol, bgCol)
|
||||||
|
| -- default to the first item, the one in (0, 0)
|
||||||
|
alwaysHighlight, complIndex == findComplIndex item
|
||||||
|
= (fgHighlight color, bgHighlight color)
|
||||||
|
| -- compare item with buffer's value
|
||||||
|
completionToCommand (currentXPMode st) item == commandToComplete (currentXPMode st) (command st)
|
||||||
|
= (fgHighlight color, bgHighlight color)
|
||||||
|
| -- if nothing matches, use default colors
|
||||||
|
otherwise = (fc, bc)
|
||||||
|
zipWithM_ (\x -> zipWithM_ (printItemAt x) cwRows) cwCols complMat
|
||||||
|
where
|
||||||
|
-- | Create the completion matrix to be printed.
|
||||||
|
complMat :: [[String]]
|
||||||
|
= chunksOf (length cwRows) (take (length cwCols * length cwRows) entries)
|
||||||
|
|
||||||
printComplList :: Display -> Drawable -> GC -> String -> String
|
-- | Find the column and row indexes in which a string appears.
|
||||||
-> [Position] -> [Position] -> [[String]] -> XP ()
|
-- If the string is not in the matrix, the indices default to @(0, 0)@.
|
||||||
printComplList d drw gc fc bc xs ys sss =
|
findComplIndex :: String -> (Int, Int)
|
||||||
zipWithM_ (\x ss ->
|
findComplIndex item = (colIndex, rowIndex)
|
||||||
zipWithM_ (\y item -> do
|
where
|
||||||
st <- get
|
colIndex = fromMaybe 0 $ findIndex (\cols -> item `elem` cols) complMat
|
||||||
alwaysHlight <- gets $ alwaysHighlight . config
|
rowIndex = fromMaybe 0 $ elemIndex item =<< complMat !? colIndex
|
||||||
let (f,b)
|
|
||||||
| alwaysHlight -- default to the first item, the one in (0,0)
|
|
||||||
= let (colIndex,rowIndex) = findComplIndex item sss
|
|
||||||
in -- assign some colors
|
|
||||||
if complIndex st == (colIndex,rowIndex)
|
|
||||||
then (fgHighlight $ color st,bgHighlight $ color st)
|
|
||||||
else (fc,bc)
|
|
||||||
| -- compare item with buffer's value
|
|
||||||
completionToCommand (currentXPMode st) item == commandToComplete (currentXPMode st) (command st)
|
|
||||||
= (fgHighlight $ color st,bgHighlight $ color st)
|
|
||||||
| otherwise = (fc,bc)
|
|
||||||
printStringXMF d drw (fontS st) gc f b x y item)
|
|
||||||
ys ss) xs sss
|
|
||||||
|
|
||||||
-- History
|
-- History
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user