123456789101112131415161718192021222324252627282930313233open!Coreopen!ImportmoduleOutput=StringmoduleInput=Stringtype'errt=|Human_friendly_string:[`String_contains_newline]t|Escaped_string:Nothing.ttletof_human_friendly_string=Human_friendly_stringletof_escaped_string=Escaped_stringletencode(typeerr)(t:errt)(string:string):(_,err)Result.t=matchtwith|Human_friendly_string->ifString.existsstring~f:(Char.equal'\n')thenError`String_contains_newlineelseOkstring|Escaped_string->Ok(String.escapedstring);;letdecode(typeerr)(t:errt)output_from_fzf_binary=matchtwith|Human_friendly_string->Okoutput_from_fzf_binary|Escaped_string->(matchScanf.unescapedoutput_from_fzf_binarywith|unescaped->Okunescaped|exception_->leterr=Error.create_s[%message"string was not encoded with [String.escaped]"]inError(`Decoded_with_inconsistent_codecerr));;