mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-05-19 11:30:22 -07:00
XPrompt: Add showCompletionOnTab option
This patch partially implements http://code.google.com/p/xmonad/issues/detail?id=215 It adds a XPConfig option that, if enabled, hides the completion window until the user presses Tab once. Default behaviour is preserved. TODO: If Tab causes a unique completion, continue to hide the completion window.
This commit is contained in:
parent
a908ff760b
commit
25033caf6e
@ -83,6 +83,7 @@ data XPState =
|
|||||||
, complWin :: Maybe Window
|
, complWin :: Maybe Window
|
||||||
, complWinDim :: Maybe ComplWindowDim
|
, complWinDim :: Maybe ComplWindowDim
|
||||||
, completionFunction :: String -> IO [String]
|
, completionFunction :: String -> IO [String]
|
||||||
|
, showComplWin :: Bool
|
||||||
, gcon :: !GC
|
, gcon :: !GC
|
||||||
, fontS :: !XMonadFont
|
, fontS :: !XMonadFont
|
||||||
, xptype :: !XPType
|
, xptype :: !XPType
|
||||||
@ -105,6 +106,7 @@ data XPConfig =
|
|||||||
, historySize :: !Int -- ^ The number of history entries to be saved
|
, historySize :: !Int -- ^ The number of history entries to be saved
|
||||||
, defaultText :: String -- ^ The text by default in the prompt line
|
, defaultText :: String -- ^ The text by default in the prompt line
|
||||||
, autoComplete :: Maybe Int -- ^ Just x: if only one completion remains, auto-select it,
|
, autoComplete :: Maybe Int -- ^ Just x: if only one completion remains, auto-select it,
|
||||||
|
, showCompletionOnTab :: Bool -- ^ Only show list of completions when Tab was pressed
|
||||||
-- and delay by x microseconds
|
-- and delay by x microseconds
|
||||||
} deriving (Show, Read)
|
} deriving (Show, Read)
|
||||||
|
|
||||||
@ -175,6 +177,7 @@ defaultXPConfig =
|
|||||||
, historySize = 256
|
, historySize = 256
|
||||||
, defaultText = []
|
, defaultText = []
|
||||||
, autoComplete = Nothing
|
, autoComplete = Nothing
|
||||||
|
, showCompletionOnTab = False
|
||||||
}
|
}
|
||||||
|
|
||||||
type ComplFunction = String -> IO [String]
|
type ComplFunction = String -> IO [String]
|
||||||
@ -189,6 +192,7 @@ initState d rw w s compl gc fonts pt h c =
|
|||||||
, complWin = Nothing
|
, complWin = Nothing
|
||||||
, complWinDim = Nothing
|
, complWinDim = Nothing
|
||||||
, completionFunction = compl
|
, completionFunction = compl
|
||||||
|
, showComplWin = not (showCompletionOnTab c)
|
||||||
, gcon = gc
|
, gcon = gc
|
||||||
, fontS = fonts
|
, fontS = fonts
|
||||||
, xptype = XPT pt
|
, xptype = XPT pt
|
||||||
@ -276,6 +280,7 @@ eventLoop action = do
|
|||||||
handle :: KeyStroke -> Event -> XP ()
|
handle :: KeyStroke -> Event -> XP ()
|
||||||
handle k@(ks,_) e@(KeyEvent {ev_event_type = t})
|
handle k@(ks,_) e@(KeyEvent {ev_event_type = t})
|
||||||
| t == keyPress && ks == xK_Tab = do
|
| t == keyPress && ks == xK_Tab = do
|
||||||
|
modify $ \s -> s { showComplWin = True }
|
||||||
c <- getCompletions
|
c <- getCompletions
|
||||||
completionHandle c k e
|
completionHandle c k e
|
||||||
handle ks (KeyEvent {ev_event_type = t, ev_state = m})
|
handle ks (KeyEvent {ev_event_type = t, ev_state = m})
|
||||||
@ -636,7 +641,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 /= [] )
|
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
|
||||||
@ -816,4 +821,4 @@ historyCompletion = \x -> liftM (filter $ isInfixOf x) readHistoryIO
|
|||||||
-- 'getHistory' is uselessly of the type "XP [String]".
|
-- 'getHistory' is uselessly of the type "XP [String]".
|
||||||
readHistoryIO :: IO [String]
|
readHistoryIO :: IO [String]
|
||||||
readHistoryIO = do (hist,_) <- readHistory
|
readHistoryIO = do (hist,_) <- readHistory
|
||||||
return $ map command_history hist
|
return $ map command_history hist
|
||||||
|
Loading…
x
Reference in New Issue
Block a user