Skip to content

Commit

Permalink
move argument organization to getopt to allow custom processing for wsl
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatao Li committed Aug 13, 2019
1 parent d108f3f commit 56604a9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
40 changes: 28 additions & 12 deletions getopt.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ type Options =
args: string list
program: string
stderrenc: System.Text.Encoding
preArgs: string list
server: ServerOptions
}

Expand Down Expand Up @@ -61,15 +60,6 @@ let parseOptions (args: string[]) =
if wsl && ssh.IsSome then
failwith "--wsl and --ssh cannot be used together."

let prog = if wsl then "wsl" elif ssh.IsSome then "ssh" else nvim
let preargs = if wsl then ["bash"; "-l"; "-c"; "nvim"] elif ssh.IsSome then [ssh.Value; nvim] else []
let enc = if wsl then System.Text.Encoding.Unicode else System.Text.Encoding.UTF8

let intent =
if setup then Setup
elif runDaemon then Daemon(port, pipe)
else Start

if terminal then
let set x = "+\"set " + x + "\""
// fvim --wsl -u NORC +terminal +"set noshowmode" +"set laststatus=0" +"set noruler" +"set noshowcmd"
Expand All @@ -85,6 +75,33 @@ let parseOptions (args: string[]) =
| None -> "+terminal"
|> args.Add

let prog =
if wsl then
"wsl"
elif ssh.IsSome then
"ssh"
else
nvim

let args =
if wsl then
["bash"; "-l"; "-c"; sprintf "nvim --embed %s" (args |> escapeArgs |> join)]
elif ssh.IsSome then
[ssh.Value; nvim; "--embed"] @ (List.ofSeq args)
else
["--embed"] @ (List.ofSeq args)

let enc =
if wsl then
System.Text.Encoding.Unicode
else
System.Text.Encoding.UTF8

let intent =
if setup then Setup
elif runDaemon then Daemon(port, pipe)
else Start

let serveropts =
if tryDaemon then
TryDaemon
Expand All @@ -100,9 +117,8 @@ let parseOptions (args: string[]) =
logToFile = trace_to_file
logPatterns = trace_patterns
program = prog
args = List.ofSeq args
args = args
server = serveropts
preArgs = preargs
stderrenc = enc
intent = intent
}
Expand Down
7 changes: 4 additions & 3 deletions neovim/neovim.process.fs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ type Nvim() =
| Some events -> events
| None -> failwith "events"

member private this.createIO ({ args = args; server = serveropts; program = prog; preArgs = preargs; stderrenc = enc } as opts) =
member private this.createIO ({ args = args; server = serveropts; program = prog; stderrenc = enc } as opts) =
match serveropts with
| StartNew ->
let args = "--embed" :: args
let psi = ProcessStartInfo(prog, (join << escapeArgs) (preargs @ args))
let args = args |> escapeArgs |> join
let psi = ProcessStartInfo(prog, args)
psi.CreateNoWindow <- true
psi.ErrorDialog <- false
psi.RedirectStandardError <- true
Expand All @@ -62,6 +62,7 @@ type Nvim() =
psi.WindowStyle <- ProcessWindowStyle.Hidden
psi.WorkingDirectory <- Environment.CurrentDirectory

trace "Starting process. Program: %s; Arguments: %s" prog args
StartProcess <| Process.Start(psi)
| Tcp ipe ->
let sock = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
Expand Down

0 comments on commit 56604a9

Please sign in to comment.