diff options
author | 2013-11-19 23:03:53 -0500 | |
---|---|---|
committer | 2013-11-19 23:03:53 -0500 | |
commit | d2a110761100b511cdc0c714f303a9a4dcb3f814 (patch) | |
tree | 5f1957f292d09206004a49998ae724e4736d1340 /core/file_io.lua | |
parent | f75a88a3d3e0d1ecb403bbfa93062bf816c0f2a1 (diff) | |
download | textadept-d2a110761100b511cdc0c714f303a9a4dcb3f814.tar.gz textadept-d2a110761100b511cdc0c714f303a9a4dcb3f814.zip |
Experimental winapi extension for preventing the flashing black box on Windows.
Compile in a stripped version of Steve Donovan's winapi library and override
`io.popen` and `os.execute`.
Diffstat (limited to 'core/file_io.lua')
-rw-r--r-- | core/file_io.lua | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/core/file_io.lua b/core/file_io.lua index 1a017be7..cbd1bed9 100644 --- a/core/file_io.lua +++ b/core/file_io.lua @@ -415,3 +415,31 @@ function io.snapopen(paths, filter, exclude_FILTER, opts) for i = 1, #files do files[i] = files[i]:iconv(_CHARSET, 'UTF-8') end io.open_file(files) end + +-- On Windows, override `io.popen` and `os.execute` to use winapi to prevent the +-- flashing black box. +if WIN32 then + local winapi = require('winapi') + io.popen = function(prog) + local code, output = winapi.execute(prog) + if not code then return code, output end + return { + read = function() return output end, + lines = function() + if not output:find('\r?\n$') then output = output..'\n' end + local pos = 1 + return function() + local s, e, line = output:find('([^\r\n]*)\r?\n', pos) + if not s then return nil end + pos = e + 1 + return line + end + end, + close = function() return true, 'exit', code end + } + end + os.execute = function(prog) + local code = winapi.execute(prog) + if code then return true, 'exit', code end + end +end |