aboutsummaryrefslogtreecommitdiffstats
path: root/XMonad/Prompt.hs
diff options
context:
space:
mode:
authorDevin Mullins <me@twifkak.com>2008-07-04 09:34:15 +0200
committerDevin Mullins <me@twifkak.com>2008-07-04 09:34:15 +0200
commitc32cf9e244a39b759017ee849d1673146e1e9880 (patch)
tree50cab18d3aa3ad5b75f0f8a579b1849ceebe6eab /XMonad/Prompt.hs
parent73166f3b8967b393f3a4c0f158ad999dbba03613 (diff)
downloadXMonadContrib-c32cf9e244a39b759017ee849d1673146e1e9880.tar.gz
XMonadContrib-c32cf9e244a39b759017ee849d1673146e1e9880.tar.xz
XMonadContrib-c32cf9e244a39b759017ee849d1673146e1e9880.zip
add autoComplete option to XMonad.Prompt
Maybe this will get Gwern one step closer to a complete Ratpoison binding. darcs-hash:20080704073415-78224-e0d0f2fe32cd4d30972eb781e51fdfd78822ffbe.gz
Diffstat (limited to '')
-rw-r--r--XMonad/Prompt.hs32
1 files changed, 28 insertions, 4 deletions
diff --git a/XMonad/Prompt.hs b/XMonad/Prompt.hs
index 951dc94..7e3254b 100644
--- a/XMonad/Prompt.hs
+++ b/XMonad/Prompt.hs
@@ -52,6 +52,7 @@ import XMonad.Util.Font
import XMonad.Util.XSelection (getSelection)
import Control.Arrow ((&&&))
+import Control.Concurrent (threadDelay)
import Control.Monad.Reader
import Control.Monad.State
import Control.Applicative ((<$>))
@@ -98,11 +99,13 @@ data XPConfig =
, fgHLight :: String -- ^ Font color of a highlighted completion entry
, bgHLight :: String -- ^ Background color of a highlighted completion entry
, borderColor :: String -- ^ Border color
- , promptBorderWidth :: !Dimension -- ^ Border width
+ , promptBorderWidth :: !Dimension -- ^ Border width
, position :: XPPosition -- ^ Position: 'Top' or 'Bottom'
- , height :: !Dimension -- ^ Window height
- , historySize :: !Int -- ^ The number of history entries to be saved
+ , height :: !Dimension -- ^ Window height
+ , historySize :: !Int -- ^ The number of history entries to be saved
, defaultText :: String -- ^ The text by default in the prompt line
+ , autoComplete :: Maybe Int -- ^ Just x: if only one completion remains, auto-select it,
+ -- and delay by x microseconds
} deriving (Show, Read)
data XPType = forall p . XPrompt p => XPT p
@@ -171,6 +174,7 @@ defaultXPConfig =
, height = 18
, historySize = 256
, defaultText = []
+ , autoComplete = Nothing
}
type ComplFunction = String -> IO [String]
@@ -303,6 +307,25 @@ completionHandle _ ks (KeyEvent {ev_event_type = t, ev_state = m})
-- some other event: go back to main loop
completionHandle _ k e = handle k e
+tryAutoComplete :: XP Bool
+tryAutoComplete = do
+ ac <- gets (autoComplete . config)
+ case ac of
+ Just d -> do cs <- getCompletions
+ case cs of
+ [c] -> runCompleted c d >> return True
+ _ -> return False
+ Nothing -> return False
+ where runCompleted cmd delay = do
+ st <- get
+ let new_command = nextCompletion (xptype st) (command st) [cmd]
+ modify $ \s -> s { command = "autocompleting..." }
+ updateWindows
+ io $ threadDelay delay
+ modify $ \s -> s { command = new_command }
+ historyPush
+ return True
+
-- KeyPresses
data Direction = Prev | Next deriving (Eq,Show,Read)
@@ -343,7 +366,8 @@ keyPressHandle _ (_,s)
| s == "" = eventLoop handle
| otherwise = do insertString (decodeInput s)
updateWindows
- eventLoop handle
+ completed <- tryAutoComplete
+ unless completed $ eventLoop handle
-- KeyPress and State