<commit_before>module XMonadContrib.Dmenu (dmenu, dmenuXinerama, runProcessWithInput) where

import XMonad
import qualified StackSet as W
import System.Process
import System.IO
import Control.Monad
import Control.Monad.State
import Data.Maybe
import qualified Data.Map as M

runProcessWithInput :: FilePath -> [String] -> String -> IO String
runProcessWithInput cmd args input = do
    (pin, pout, perr, ph) <- runInteractiveProcess cmd args Nothing Nothing
    hPutStr pin input
    hClose pin
    output <- hGetContents pout
    when (output==output) $ return ()
    hClose pout
    hClose perr
    waitForProcess ph
    return output
    
dmenuXinerama :: [String] -> X String
dmenuXinerama opts = do
    ws <- gets workspace
    let curscreen = fromIntegral $ fromMaybe 0 (M.lookup (W.current ws) (W.ws2screen ws)) :: Int
    io $ runProcessWithInput "dmenu" ["-xs", show (curscreen+1)] (unlines opts)

dmenu :: [String] -> X String
dmenu opts = io $ runProcessWithInput "dmenu" [] (unlines opts)
<commit_msg>comment: Gave URL to xinerama-enabled dmenu patch<commit_after>module XMonadContrib.Dmenu (dmenu, dmenuXinerama, runProcessWithInput) where

import XMonad
import qualified StackSet as W
import System.Process
import System.IO
import Control.Monad
import Control.Monad.State
import Data.Maybe
import qualified Data.Map as M

runProcessWithInput :: FilePath -> [String] -> String -> IO String
runProcessWithInput cmd args input = do
    (pin, pout, perr, ph) <- runInteractiveProcess cmd args Nothing Nothing
    hPutStr pin input
    hClose pin
    output <- hGetContents pout
    when (output==output) $ return ()
    hClose pout
    hClose perr
    waitForProcess ph
    return output
    
-- Starts dmenu on the current screen. Requires this patch to dmenu:
-- http://www.jcreigh.com/dmenu/dmenu-2.8-xinerama.patch
dmenuXinerama :: [String] -> X String
dmenuXinerama opts = do
    ws <- gets workspace
    let curscreen = fromIntegral $ fromMaybe 0 (M.lookup (W.current ws) (W.ws2screen ws)) :: Int
    io $ runProcessWithInput "dmenu" ["-xs", show (curscreen+1)] (unlines opts)

dmenu :: [String] -> X String
dmenu opts = io $ runProcessWithInput "dmenu" [] (unlines opts)

{'fraction_non_alphanumeric': 0.09277879341864717, 'fraction_numerical': 0.003656307129798903, 'mean_word_length': 3.897091722595078, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6896543', 'n_tokens_mistral': 696, 'n_tokens_neox': 681, 'n_words': 232}