forked from GitHub/gf-core
GF Shell: turn set_encoding into a common command
Implemented in GF.Command.CommonCommands instead of GF.Interactive & GF.Interactive2.
This commit is contained in:
@@ -7,6 +7,8 @@ import GF.Command.CommandInfo
|
|||||||
import qualified Data.Map as Map
|
import qualified Data.Map as Map
|
||||||
import GF.Infra.SIO
|
import GF.Infra.SIO
|
||||||
import GF.Infra.UseIO(writeUTF8File)
|
import GF.Infra.UseIO(writeUTF8File)
|
||||||
|
import GF.Infra.Option(renameEncoding)
|
||||||
|
import GF.System.Console(changeConsoleEncoding)
|
||||||
import GF.System.Process
|
import GF.System.Process
|
||||||
import GF.Command.Abstract --(isOpt,valStrOpts,prOpt)
|
import GF.Command.Abstract --(isOpt,valStrOpts,prOpt)
|
||||||
import GF.Text.Pretty
|
import GF.Text.Pretty
|
||||||
@@ -135,7 +137,14 @@ commonCommands = Map.fromList [
|
|||||||
examples = [
|
examples = [
|
||||||
mkEx "se cp1251 -- set encoding to cp1521",
|
mkEx "se cp1251 -- set encoding to cp1521",
|
||||||
mkEx "se utf8 -- set encoding to utf8 (default)"
|
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 {
|
("sp", emptyCommandInfo {
|
||||||
longname = "system_pipe",
|
longname = "system_pipe",
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ import qualified GF.System.Signal as IO(runInterruptibly)
|
|||||||
#ifdef SERVER_MODE
|
#ifdef SERVER_MODE
|
||||||
import GF.Server(server)
|
import GF.Server(server)
|
||||||
#endif
|
#endif
|
||||||
import GF.System.Console(changeConsoleEncoding)
|
|
||||||
|
|
||||||
import GF.Command.Messages(welcome)
|
import GF.Command.Messages(welcome)
|
||||||
|
|
||||||
@@ -130,7 +129,6 @@ execute1 opts gfenv0 s0 =
|
|||||||
"dt":ws -> define_tree ws
|
"dt":ws -> define_tree ws
|
||||||
"ph":_ -> print_history
|
"ph":_ -> print_history
|
||||||
"r" :_ -> reload_last
|
"r" :_ -> reload_last
|
||||||
"se":ws -> set_encoding ws
|
|
||||||
-- ordinary commands, working on CommandEnv
|
-- ordinary commands, working on CommandEnv
|
||||||
_ -> do interpretCommandLine env s0
|
_ -> do interpretCommandLine env s0
|
||||||
continue gfenv
|
continue gfenv
|
||||||
@@ -210,12 +208,6 @@ execute1 opts gfenv0 s0 =
|
|||||||
putStrLn $ "no import in history"
|
putStrLn $ "no import in history"
|
||||||
continue gfenv
|
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)
|
printException e = maybe (print e) (putStrLn . ioErrorText) (fromException e)
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ import qualified GF.System.Signal as IO(runInterruptibly)
|
|||||||
import GF.Server(server)
|
import GF.Server(server)
|
||||||
#endif
|
#endif
|
||||||
-}
|
-}
|
||||||
import GF.System.Console(changeConsoleEncoding)
|
|
||||||
|
|
||||||
import GF.Command.Messages(welcome)
|
import GF.Command.Messages(welcome)
|
||||||
|
|
||||||
@@ -131,7 +130,6 @@ execute1 opts gfenv0 s0 =
|
|||||||
"dt":ws -> define_tree ws
|
"dt":ws -> define_tree ws
|
||||||
"ph":_ -> print_history
|
"ph":_ -> print_history
|
||||||
"r" :_ -> reload_last
|
"r" :_ -> reload_last
|
||||||
"se":ws -> set_encoding ws
|
|
||||||
-- ordinary commands, working on CommandEnv
|
-- ordinary commands, working on CommandEnv
|
||||||
_ -> do interpretCommandLine env s0
|
_ -> do interpretCommandLine env s0
|
||||||
continue gfenv
|
continue gfenv
|
||||||
@@ -214,12 +212,6 @@ execute1 opts gfenv0 s0 =
|
|||||||
putStrLn $ "no import in history"
|
putStrLn $ "no import in history"
|
||||||
continue gfenv
|
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)
|
printException e = maybe (print e) (putStrLn . ioErrorText) (fromException e)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user