-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ executable miv | |
, Setting | ||
, Mode | ||
, Command | ||
, Cmdline | ||
, Mapping | ||
, ShowText | ||
, ReadText | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
module Cmdline where | ||
|
||
import Data.Aeson | ||
import qualified Data.Aeson as Aeson | ||
import Data.Hashable | ||
import Data.Text (Text,unpack) | ||
import Prelude hiding (show) | ||
import qualified Prelude as Prelude | ||
|
||
import ReadText | ||
import ShowText | ||
|
||
data Cmdline = CmdlineExCommand | ||
| CmdlineForwardSearch | ||
| CmdlineBackwardSearch | ||
| CmdlineInput | ||
deriving (Eq, Ord) | ||
|
||
instance ShowText Cmdline where | ||
show CmdlineExCommand = ":" | ||
show CmdlineForwardSearch = "/" | ||
show CmdlineBackwardSearch = "?" | ||
show CmdlineInput = "@" | ||
|
||
instance ReadText Cmdline where | ||
read ":" = CmdlineExCommand | ||
read "/" = CmdlineForwardSearch | ||
read "?" = CmdlineBackwardSearch | ||
read "@" = CmdlineInput | ||
read m = error $ "unknown cmdline: " ++ unpack m | ||
|
||
instance Hashable Cmdline where | ||
hashWithSalt a CmdlineExCommand = a `hashWithSalt` (0 :: Int) | ||
hashWithSalt a CmdlineForwardSearch = a `hashWithSalt` (1 :: Int) | ||
hashWithSalt a CmdlineBackwardSearch = a `hashWithSalt` (2 :: Int) | ||
hashWithSalt a CmdlineInput = a `hashWithSalt` (3 :: Int) | ||
|
||
instance FromJSON Cmdline where | ||
parseJSON (Aeson.String str) | ||
| unpack str == ":" = return CmdlineExCommand | ||
| unpack str == "/" = return CmdlineForwardSearch | ||
| unpack str == "?" = return CmdlineBackwardSearch | ||
| unpack str == "@" = return CmdlineInput | ||
parseJSON o = error $ "failed to parse cmdline: " <> Prelude.show o | ||
|
||
cmdlinePattern :: Cmdline -> Text | ||
cmdlinePattern CmdlineExCommand = ":" | ||
cmdlinePattern CmdlineForwardSearch = "/" | ||
cmdlinePattern CmdlineBackwardSearch = "\\?" | ||
cmdlinePattern CmdlineInput = "@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters