diff --git a/Program.fs b/Program.fs index ba2d3b8..aa57834 100644 --- a/Program.fs +++ b/Program.fs @@ -99,10 +99,11 @@ let main(args: string[]) = let _ = Thread.CurrentThread.TrySetApartmentState(ApartmentState.STA) AppDomain.CurrentDomain.UnhandledException.Add(fun exArgs -> - let filename = Path.Combine(config.configdir, sprintf "fvim-crash-%s.txt" (DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"))) + let datetime = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + let filename = Path.Combine(config.configdir, $"fvim-crash-{datetime}.txt") use dumpfile = new StreamWriter(filename) - dumpfile.WriteLine(sprintf "Unhandled exception: (terminating:%A)" exArgs.IsTerminating) - dumpfile.WriteLine(exArgs.ExceptionObject.ToString()) + dumpfile.WriteLine($"Unhandled exception: (terminating:%A{exArgs.IsTerminating})") + dumpfile.WriteLine($"{exArgs.ExceptionObject}") ) System.Console.OutputEncoding <- System.Text.Encoding.Unicode diff --git a/ViewModels/CompletionItemViewModel.fs b/ViewModels/CompletionItemViewModel.fs index 6333a5f..57615d5 100644 --- a/ViewModels/CompletionItemViewModel.fs +++ b/ViewModels/CompletionItemViewModel.fs @@ -102,7 +102,7 @@ module CompletionItemHelper = Map.map (fun k name -> if name = "Unknown" then null else - let fname = sprintf "avares://FVim/Assets/intellisense/%s_16x.png" name + let fname = $"avares://FVim/Assets/intellisense/{name}_16x.png" (*trace "CompleteItem" "loading intellisense icon %s" fname*) new Bitmap(assets.Open(new System.Uri(fname)))) diff --git a/ViewModels/CrashReportViewModel.fs b/ViewModels/CrashReportViewModel.fs index 34cb076..4734249 100644 --- a/ViewModels/CrashReportViewModel.fs +++ b/ViewModels/CrashReportViewModel.fs @@ -6,9 +6,9 @@ open Avalonia.Media type CrashReportViewModel(ex: exn, code: int, msgs: ResizeArray) = inherit ViewModelBase() member __.MainMessage = - sprintf "Exit code: %d\n" code + - sprintf "Exception message: %s\n" ex.Message + - join msgs + $"""Exit code: {code} +Exception message: {ex.Message} +{join msgs}""" member __.StackTrace = ex.StackTrace member __.TipMessage = diff --git a/ViewModels/FrameViewModel.fs b/ViewModels/FrameViewModel.fs index 0d7c710..889fe6f 100644 --- a/ViewModels/FrameViewModel.fs +++ b/ViewModels/FrameViewModel.fs @@ -58,7 +58,7 @@ type FrameViewModel(cfg: config.ConfigObject.Workspace option, ?_maingrid: GridV let toggleFullScreen() = if mainGrid.IsFocused then this.Fullscreen <- not this.Fullscreen - trace (sprintf "FrameVM #%d" mainGrid.GridId) "ToggleFullScreen %A" this.Fullscreen + trace $"FrameVM #{mainGrid.GridId}" "ToggleFullScreen %A" this.Fullscreen let updateBackgroundImage() = try @@ -69,7 +69,7 @@ type FrameViewModel(cfg: config.ConfigObject.Workspace option, ?_maingrid: GridV path.[2..]) else path - trace (sprintf "FrameVM #%d" mainGrid.GridId) "%s" path + trace $"FrameVM #{mainGrid.GridId}" "%s" path let new_img = new Bitmap(path) ignore <| this.RaiseAndSetIfChanged(&m_bgimg_src, new_img, "BackgroundImage") ignore <| this.RaiseAndSetIfChanged(&m_bgimg_w, m_bgimg_src.Size.Width, "BackgroundImageW") diff --git a/ViewModels/GridViewModel.fs b/ViewModels/GridViewModel.fs index 2e1402f..781c3c4 100644 --- a/ViewModels/GridViewModel.fs +++ b/ViewModels/GridViewModel.fs @@ -21,7 +21,7 @@ open Avalonia.Interactivity module private GridViewModelHelper = let inline trace id fmt = - FVim.log.trace (sprintf "editorvm #%d" id) fmt + FVim.log.trace $"editorvm #{id}" fmt open GridViewModelHelper diff --git a/Views/Grid.xaml.fs b/Views/Grid.xaml.fs index 7639f48..b5ac780 100644 --- a/Views/Grid.xaml.fs +++ b/Views/Grid.xaml.fs @@ -264,7 +264,7 @@ type Grid() as this = let drawDebug(dc: IDrawingContextImpl) = let txt = Media.FormattedText() - txt.Text <- sprintf "Grid #%d, Z=%d" grid_vm.GridId this.ZIndex + txt.Text <- $"Grid #{grid_vm.GridId}, Z={this.ZIndex}" txt.Typeface <- Media.Typeface("Iosevka Slab") dc.DrawText(Media.Brushes.Tan, Point(10.0, 10.0), txt.PlatformImpl) diff --git a/daemon.fs b/daemon.fs index a8fc01f..7b95b1d 100644 --- a/daemon.fs +++ b/daemon.fs @@ -56,7 +56,7 @@ let pipeaddr x = then @"\\.\pipe\" + x else pipeaddrUnix x -let pipename = sprintf "fvr_%s" +let pipename (x:'a) = $"fvr_{x}" let defaultDaemonName = pipename "main" @@ -71,7 +71,7 @@ let attachSession id svrpipe = let newSession nvim stderrenc args svrpipe = let myid = sessionId - let pname = pipename (string myid) + let pname = pipename myid let paddr = pipeaddr pname let args = "--headless" :: "--listen" :: paddr :: args let proc = newProcess nvim args stderrenc @@ -105,7 +105,7 @@ let attachFirstSession svrpipe = let serveSession (session: Session) = task { - let pname = pipename (string session.id) + let pname = pipename session.id use client = new NamedPipeClientStream(".", pname, IO.Pipes.PipeDirection.InOut, IO.Pipes.PipeOptions.Asynchronous, TokenImpersonationLevel.Impersonation) do! client.ConnectAsync() trace "Connected to NeoVim server at %s" pname diff --git a/def.fs b/def.fs index 09700e6..849f4d3 100644 --- a/def.fs +++ b/def.fs @@ -136,7 +136,7 @@ type Rune = override x.ToString() = match x with | SingleChar c -> c.ToString() - | SurrogatePair(c1, c2) -> sprintf "%c%c" c1 c2 + | SurrogatePair(c1, c2) -> $"{c1}{c2}" | Composed str -> String.Join("", str) override x.GetHashCode() = match x with @@ -432,7 +432,7 @@ type RedrawCommand = type EventParseException(data: obj) = inherit exn() member __.Input = data - override __.Message = sprintf "Could not parse the neovim message: %A" data + override __.Message = $"Could not parse the neovim message: %A{data}" /// Matches ObjArray against the [|string; p1; p2; ... |] form let (|C|_|) (x:obj) = diff --git a/getopt.fs b/getopt.fs index a0cc528..a20224b 100644 --- a/getopt.fs +++ b/getopt.fs @@ -139,7 +139,7 @@ let parseOptions (args: string[]) = | None, None -> let prog, args, r = if wsl then - "wsl", ["bash"; "-l"; "-c"; sprintf "nvim --embed %s" (args |> escapeArgs |> join)], true + "wsl", ["bash"; "-l"; "-c"; $"nvim --embed {args |> escapeArgs |> join}"], true elif ssh.IsSome then "ssh", [ssh.Value; nvim; "--embed"] @ argsL, true else diff --git a/input.fs b/input.fs index dfe630f..89f0c8e 100644 --- a/input.fs +++ b/input.fs @@ -383,7 +383,7 @@ let rec ModifiersPrefix (x: InputEvent) = let a = if m.HasFlag(KeyModifiers.Alt) then "A-" else "" let d = if m.HasFlag(KeyModifiers.Meta) then "D-" else "" let s = if m.HasFlag(KeyModifiers.Shift) then "S-" else "" - (sprintf "%s%s%s%s" c a d s).TrimEnd('-') + $"{c}{a}{d}{s}".TrimEnd('-') | TextInput _ -> "" | _ -> "" @@ -401,10 +401,10 @@ let onInput (nvim: Nvim) (input: IObservable) = ev.Handled <- true let pref = ModifiersPrefix x match x,pref with - | (Special sp), "" -> Some(sprintf "<%s>" sp) - | (Special sp), pref -> Some(sprintf "<%s-%s>" pref sp) + | (Special sp), "" -> Some($"<{sp}>") + | (Special sp), pref -> Some($"<{pref}-{sp}>") | (Normal n), "" -> Some n - | (Normal n), pref -> Some(sprintf "<%s-%s>" pref n) + | (Normal n), pref -> Some($"<{pref}-{n}>") | x -> #if DEBUG trace "rejected: %A" x diff --git a/log.fs b/log.fs index 9b8845f..8cac903 100644 --- a/log.fs +++ b/log.fs @@ -8,10 +8,10 @@ open System.Collections.Generic let mutable private _filter = fun _ -> true let private _logsSource = Event() -let private _logsPub = _logsSource.Publish |> Observable.map (fun (a,b) -> sprintf "%s: %s" a b) +let private _logsPub = _logsSource.Publish |> Observable.map (fun (a,b) -> $"{a}: {b}") let private _logsESource = Event() -let private _logsEPub = _logsESource.Publish |> Observable.map (fun (a,b) -> sprintf "error: %s: %s" a b) +let private _logsEPub = _logsESource.Publish |> Observable.map (fun (a,b) -> $"error: {a}: {b}") let private _logsSink = Observable.merge _logsPub _logsEPub |> Observable.filter(fun x -> _filter x) @@ -45,7 +45,7 @@ let init { logToStdout = logToStdout; logToFile = logToFile; logPatterns = logPa | _ -> "fvim" if logToFile then _n_logsSink <- _n_logsSink + 1 - let logname = sprintf "%s-%s.log" fprefix ftime + let logname = $"{fprefix}-{ftime}.log" let logToFile = System.IO.Path.Combine(config.configdir, logname) try System.IO.File.Delete logToFile with _ -> () diff --git a/model.fs b/model.fs index d428d44..a512d5f 100644 --- a/model.fs +++ b/model.fs @@ -328,7 +328,7 @@ let Detach() = let private UpdateUICapabilities() = let opts = hashmap[] states.PopulateUIOptions opts - trace "UpdateUICapabilities: %A" <| String.Join(", ", Seq.map (fun (KeyValue(k, v)) -> sprintf "%s=%b" k v) opts) + trace "UpdateUICapabilities: %A" <| String.Join(", ", Seq.map (fun (KeyValue(k, v)) -> $"{k}={v}") opts) backgroundTask { do! init.Task for KeyValue(k, v) in opts do diff --git a/neovim.fs b/neovim.fs index 83d96f2..9e5386a 100644 --- a/neovim.fs +++ b/neovim.fs @@ -359,7 +359,7 @@ type Nvim() as nvim = | 1 -> "1" | _ -> "+" - nvim.command(sprintf "command! -nargs=%s %s %s" nargs name cmd) + nvim.command $"command! -nargs={nargs} {name} {cmd}" member __.exec (src: string) (output: bool) = nvim.call { method = "nvim_exec"; parameters = mkparams2 src output } diff --git a/shell.fs b/shell.fs index 3158df3..0de35ca 100644 --- a/shell.fs +++ b/shell.fs @@ -60,7 +60,7 @@ let private win32RegisterFileAssociation() = let HKCR = Registry.ClassesRoot let HKLM = Registry.LocalMachine let exe = Path.Combine(FVimDir, "FVim.exe") - let fvicon = sprintf "%s,0" exe + let fvicon = $"{exe},0" let setupShell(key: RegistryKey) (ico: string) = @@ -81,7 +81,7 @@ let private win32RegisterFileAssociation() = _edit.SetValue("", "Open with FVim") _edit.SetValue("Icon", fvicon) use command = _edit.CreateSubKey("command") - command.SetValue("", sprintf "\"%s\" \"%%1\"" exe) + command.SetValue("", $"\{exe}\" \"%%1\"") // https://docs.microsoft.com/en-us/windows/desktop/shell/app-registration do diff --git a/ui.fs b/ui.fs index 1daa881..a6870bc 100644 --- a/ui.fs +++ b/ui.fs @@ -145,7 +145,7 @@ let DefaultFontEmoji = let private nerd_typeface = let name = if RuntimeInformation.IsOSPlatform(OSPlatform.OSX) then "Iosevka Nerd Font" else "Iosevka" - Typeface(sprintf "resm:fvim.Fonts.nerd.ttf?assembly=FVim#%s" name) + Typeface($"resm:fvim.Fonts.nerd.ttf?assembly=FVim#{name}") let private emoji_typeface = Typeface(DefaultFontEmoji) let private fontcache = System.Collections.Generic.Dictionary()