chore: close window and buffer more safely

This commit is contained in:
JuanZoran
2023-04-07 19:05:24 +08:00
parent fcde85544a
commit 38b8e20729
7 changed files with 17 additions and 20 deletions

View File

@ -4,19 +4,17 @@ local api, fn = vim.api, vim.fn
local Trans = require 'Trans'
local command = api.nvim_create_user_command
command('Translate', function()
Trans.translate()
end, { desc = ' Translate cursor word' })
command('Translate', function() Trans.translate() end,
{ desc = ' Translate cursor word' })
command('TranslateInput', function()
Trans.translate { mode = 'i' }
end, { desc = ' Translate input word' })
command('TranslateInput', function() Trans.translate { mode = 'i' } end,
{ desc = ' Translate input word' })
command('TransPlay', function()
local util = Trans.util
local str = util.get_str(vim.fn.mode())
if str and str ~= '' and util.is_English(str) then
if str and str ~= '' and util.is_english(str) then
str:play()
end
end, { desc = ' Auto play' })
@ -30,9 +28,9 @@ local f =
system == 'termux' and 'termux-tts-speak %q' or
system == 'linux' and 'echo %q | festival --tts' or
'node' .. Trans.relative_path { 'tts', 'say.js' } .. ' %q'
-- 'powershell -Command "Add-Type AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak([Console]::In.ReadToEnd())" | Out-File -Encoding ASCII %q'
-- or 'node' .. Trans.relative_path { 'tts', 'say.js' } .. ' %q'
-- system == 'win' and 'powershell -Command "Add-Type AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak([Console]::In.ReadToEnd())" | Out-File -Encoding ASCII %q'
-- 'powershell -Command "Add-Type AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak([Console]::In.ReadToEnd())" | Out-File -Encoding ASCII %q'
-- or 'node' .. Trans.relative_path { 'tts', 'say.js' } .. ' %q'
-- system == 'win' and 'powershell -Command "Add-Type AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak([Console]::In.ReadToEnd())" | Out-File -Encoding ASCII %q'
string.play = function(self)
fn.jobstart(f:format(self))