summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2015-08-12 15:00:03 +0000
committerhallgren <hallgren@chalmers.se>2015-08-12 15:00:03 +0000
commitd860a921e061ca21e7af8c1c42f5bbca4bd5c988 (patch)
treea7c0e0c2b3b8678dbf507846797e10695b06204f /src
parentb536b025345c1d144fb6727d41bd96684901bf1f (diff)
GF Shell: turn set_encoding into a common command
Implemented in GF.Command.CommonCommands instead of GF.Interactive & GF.Interactive2.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/GF/Command/CommonCommands.hs11
-rw-r--r--src/compiler/GF/Interactive.hs8
-rw-r--r--src/compiler/GF/Interactive2.hs8
3 files changed, 10 insertions, 17 deletions
diff --git a/src/compiler/GF/Command/CommonCommands.hs b/src/compiler/GF/Command/CommonCommands.hs
index 4099d042f..e835d78d7 100644
--- a/src/compiler/GF/Command/CommonCommands.hs
+++ b/src/compiler/GF/Command/CommonCommands.hs
@@ -7,6 +7,8 @@ import GF.Command.CommandInfo
import qualified Data.Map as Map
import GF.Infra.SIO
import GF.Infra.UseIO(writeUTF8File)
+import GF.Infra.Option(renameEncoding)
+import GF.System.Console(changeConsoleEncoding)
import GF.System.Process
import GF.Command.Abstract --(isOpt,valStrOpts,prOpt)
import GF.Text.Pretty
@@ -135,7 +137,14 @@ commonCommands = Map.fromList [
examples = [
mkEx "se cp1251 -- set encoding to cp1521",
mkEx "se utf8 -- set encoding to utf8 (default)"
- ]
+ ],
+ needsTypeCheck = False,
+ exec = \ _ opts ts ->
+ case words (toString ts) of
+ [c] -> do let cod = renameEncoding c
+ restricted $ changeConsoleEncoding cod
+ return void
+ _ -> return (pipeMessage "se command not parsed")
}),
("sp", emptyCommandInfo {
longname = "system_pipe",
diff --git a/src/compiler/GF/Interactive.hs b/src/compiler/GF/Interactive.hs
index 216c5f1e2..6e8cc6330 100644
--- a/src/compiler/GF/Interactive.hs
+++ b/src/compiler/GF/Interactive.hs
@@ -38,7 +38,6 @@ import qualified GF.System.Signal as IO(runInterruptibly)
#ifdef SERVER_MODE
import GF.Server(server)
#endif
-import GF.System.Console(changeConsoleEncoding)
import GF.Command.Messages(welcome)
@@ -130,7 +129,6 @@ execute1 opts gfenv0 s0 =
"dt":ws -> define_tree ws
"ph":_ -> print_history
"r" :_ -> reload_last
- "se":ws -> set_encoding ws
-- ordinary commands, working on CommandEnv
_ -> do interpretCommandLine env s0
continue gfenv
@@ -210,12 +208,6 @@ execute1 opts gfenv0 s0 =
putStrLn $ "no import in history"
continue gfenv
- set_encoding [c] =
- do let cod = renameEncoding c
- restricted $ changeConsoleEncoding cod
- continue gfenv
- set_encoding _ = putStrLn "se command not parsed" >> continue gfenv
-
printException e = maybe (print e) (putStrLn . ioErrorText) (fromException e)
diff --git a/src/compiler/GF/Interactive2.hs b/src/compiler/GF/Interactive2.hs
index abb4f7ddf..d914c0f8b 100644
--- a/src/compiler/GF/Interactive2.hs
+++ b/src/compiler/GF/Interactive2.hs
@@ -39,7 +39,6 @@ import qualified GF.System.Signal as IO(runInterruptibly)
import GF.Server(server)
#endif
-}
-import GF.System.Console(changeConsoleEncoding)
import GF.Command.Messages(welcome)
@@ -131,7 +130,6 @@ execute1 opts gfenv0 s0 =
"dt":ws -> define_tree ws
"ph":_ -> print_history
"r" :_ -> reload_last
- "se":ws -> set_encoding ws
-- ordinary commands, working on CommandEnv
_ -> do interpretCommandLine env s0
continue gfenv
@@ -214,12 +212,6 @@ execute1 opts gfenv0 s0 =
putStrLn $ "no import in history"
continue gfenv
- set_encoding [c] =
- do let cod = renameEncoding c
- restricted $ changeConsoleEncoding cod
- continue gfenv
- set_encoding _ = putStrLn "se command not parsed" >> continue gfenv
-
printException e = maybe (print e) (putStrLn . ioErrorText) (fromException e)