Skip to content

Commit

Permalink
do not throw if /dev/tty cannot be opened
Browse files Browse the repository at this point in the history
note that Neovim loads the syntax engine without tty emulation just fine
  • Loading branch information
lyokha committed May 5, 2024
1 parent 78c8196 commit 623edb6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
5 changes: 5 additions & 0 deletions pandoc/haskell/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### 0.3.1.0

- Do not throw if */dev/tty* cannot be opened. Note that Neovim loads the syntax
engine without *tty* emulation just fine.

### 0.3.0.0

- Support for packages *base* < *4.8* and *pandoc-types* < *1.20* was
Expand Down
2 changes: 1 addition & 1 deletion pandoc/haskell/pandoc-vimhl.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: pandoc-vimhl
version: 0.3.0.0
version: 0.3.1.0
synopsis: Pandoc filter for native Vim code highlighting
description: Pandoc filter for native Vim code highlighting
in HTML and PDF documents. Requires Vim (or Neovim) and plugin
Expand Down
19 changes: 17 additions & 2 deletions pandoc/haskell/vimhl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,24 @@ vimHl (Just fm@(Format fmt)) (CodeBlock (_, cls@(ft : _), namevals) contents)
,vimhlcmd ++ "' -c 'w!", dst ++ "' -c 'qa!'"
,src
]
{- Vim must think that it was launched from a terminal,
- otherwise it won't load its usual environment and the
- syntax engine! Using WriteMode for stdin prevents Vim
- from getting unresponsive on Ctrl-C interrupts while
- still doing well its task (Vim checks that input is a
- terminal using isatty(), however it does not check the
- mode of the handle). Note that Neovim loads the syntax
- engine just fine. -}
hin <- (Just <$> openFile "/dev/tty" WriteMode)
`catchIOError` const (return Nothing)
hout <- openFile "/dev/null" WriteMode
(_, _, _, handle) <- createProcess (shell vimcmd)
{std_out = UseHandle hout}
(_, _, _, handle) <- createProcess $
maybe (shell vimcmd) {std_out = UseHandle hout}
(\hin' -> (shell vimcmd)
{std_in = UseHandle hin'
,std_out = UseHandle hout
}
) hin
r <- waitForProcess handle
unless (r == ExitSuccess) $ exitWith r
T.readFile dst
Expand Down

0 comments on commit 623edb6

Please sign in to comment.