mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-08-01 20:51:52 -07:00
X.P.Unicode: BS -> String to support Unicode descriptions
Switch the underlying UnicodeData data type from the current ByteString implementation to String. This is in order to facilitate descriptions Unicode descriptions of the Unicode characters themselves. We chose String instead of Text because it does not incur an extra dependency. Fixes: https://github.com/xmonad/xmonad-contrib/issues/733
This commit is contained in:
@@ -112,6 +112,11 @@
|
|||||||
- Added the ability to specify alphabetic (`#A`, `#B`, and `#C`)
|
- Added the ability to specify alphabetic (`#A`, `#B`, and `#C`)
|
||||||
[priorities] at the end of the input note.
|
[priorities] at the end of the input note.
|
||||||
|
|
||||||
|
* `XMonad.Prompt.Unicode`
|
||||||
|
|
||||||
|
- Fixed the display of non-ASCII characters in the description of Unicode
|
||||||
|
characters
|
||||||
|
|
||||||
* `XMonad.Prompt`
|
* `XMonad.Prompt`
|
||||||
|
|
||||||
- Added `transposeChars` to interchange the characters around the
|
- Added `transposeChars` to interchange the characters around the
|
||||||
|
@@ -23,12 +23,12 @@ module XMonad.Prompt.Unicode (
|
|||||||
mkUnicodePrompt
|
mkUnicodePrompt
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
import Codec.Binary.UTF8.String (decodeString)
|
||||||
import qualified Data.ByteString.Char8 as BS
|
import qualified Data.ByteString.Char8 as BS
|
||||||
import Numeric
|
import Numeric
|
||||||
import System.IO
|
import System.IO
|
||||||
import System.IO.Error
|
import System.IO.Error
|
||||||
import Text.Printf
|
import Text.Printf
|
||||||
import Control.Arrow (second)
|
|
||||||
|
|
||||||
import XMonad
|
import XMonad
|
||||||
import XMonad.Prelude
|
import XMonad.Prelude
|
||||||
@@ -42,7 +42,7 @@ instance XPrompt Unicode where
|
|||||||
commandToComplete Unicode s = s
|
commandToComplete Unicode s = s
|
||||||
nextCompletion Unicode = getNextCompletion
|
nextCompletion Unicode = getNextCompletion
|
||||||
|
|
||||||
newtype UnicodeData = UnicodeData { getUnicodeData :: [(Char, BS.ByteString)] }
|
newtype UnicodeData = UnicodeData { getUnicodeData :: [(Char, String)] }
|
||||||
deriving (Read, Show)
|
deriving (Read, Show)
|
||||||
|
|
||||||
instance ExtensionClass UnicodeData where
|
instance ExtensionClass UnicodeData where
|
||||||
@@ -79,23 +79,24 @@ populateEntries unicodeDataFilename = do
|
|||||||
hPutStrLn stderr "Do you have unicode-data installed?"
|
hPutStrLn stderr "Do you have unicode-data installed?"
|
||||||
return False
|
return False
|
||||||
Right dat -> do
|
Right dat -> do
|
||||||
XS.put . UnicodeData . sortOn (BS.length . snd) $ parseUnicodeData dat
|
XS.put . UnicodeData . sortOn (length . snd) $ parseUnicodeData dat
|
||||||
return True
|
return True
|
||||||
else return True
|
else return True
|
||||||
|
|
||||||
parseUnicodeData :: BS.ByteString -> [(Char, BS.ByteString)]
|
parseUnicodeData :: BS.ByteString -> [(Char, String)]
|
||||||
parseUnicodeData = mapMaybe parseLine . BS.lines
|
parseUnicodeData = mapMaybe parseLine . BS.lines
|
||||||
where parseLine l = do
|
where parseLine l = do
|
||||||
field1 : field2 : _ <- return $ BS.split ';' l
|
field1 : field2 : _ <- return $ BS.split ';' l
|
||||||
[(c,"")] <- return . readHex $ BS.unpack field1
|
[(c,"")] <- return . readHex $ BS.unpack field1
|
||||||
return (chr c, field2)
|
desc <- return . decodeString $ BS.unpack field2
|
||||||
|
return (chr c, desc)
|
||||||
|
|
||||||
type Predicate = String -> String -> Bool
|
type Predicate = String -> String -> Bool
|
||||||
|
|
||||||
searchUnicode :: [(Char, BS.ByteString)] -> Predicate -> String -> [(Char, String)]
|
searchUnicode :: [(Char, String)] -> Predicate -> String -> [(Char, String)]
|
||||||
searchUnicode entries p s = map (second BS.unpack) $ filter go entries
|
searchUnicode entries p s = filter go entries
|
||||||
where w = filter (all isAscii) . filter ((> 1) . length) . words $ map toUpper s
|
where w = filter ((> 1) . length) . words $ map toUpper s
|
||||||
go (_, d) = all (`p` BS.unpack d) w
|
go (_, d) = all (`p` d) w
|
||||||
|
|
||||||
mkUnicodePrompt :: String -> [String] -> String -> XPConfig -> X ()
|
mkUnicodePrompt :: String -> [String] -> String -> XPConfig -> X ()
|
||||||
mkUnicodePrompt prog args unicodeDataFilename xpCfg =
|
mkUnicodePrompt prog args unicodeDataFilename xpCfg =
|
||||||
@@ -107,7 +108,7 @@ mkUnicodePrompt prog args unicodeDataFilename xpCfg =
|
|||||||
(unicodeCompl entries $ searchPredicate xpCfg)
|
(unicodeCompl entries $ searchPredicate xpCfg)
|
||||||
paste
|
paste
|
||||||
where
|
where
|
||||||
unicodeCompl :: [(Char, BS.ByteString)] -> Predicate -> String -> IO [String]
|
unicodeCompl :: [(Char, String)] -> Predicate -> String -> IO [String]
|
||||||
unicodeCompl _ _ "" = return []
|
unicodeCompl _ _ "" = return []
|
||||||
unicodeCompl entries p s = do
|
unicodeCompl entries p s = do
|
||||||
let m = searchUnicode entries p s
|
let m = searchUnicode entries p s
|
||||||
|
Reference in New Issue
Block a user