Skip to content

Commit

Permalink
Fix image scroll issue for iterm2
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspervdj committed Feb 22, 2025
1 parent d54ce90 commit 346c24f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ patat:

- `backend: iterm2`: uses [iTerm2](https://iterm2.com/)'s special escape
sequence to render the image. This even works with animated GIFs!
Note that it can have issues running under `tmux`.

- `backend: kitty`: uses
[Kitty's icat command](https://sw.kovidgoyal.net/kitty/kittens/icat.html).
Expand Down
16 changes: 10 additions & 6 deletions lib/Patat/Images/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ module Patat.Images.Internal


--------------------------------------------------------------------------------
import Control.Exception (Exception)
import qualified Data.Aeson as A
import Data.Data (Data)
import Data.Typeable (Typeable)
import Control.Exception (Exception)
import qualified Data.Aeson as A
import Data.Data (Data)
import qualified Data.List as L
import Data.Typeable (Typeable)
import Patat.Cleanup
import System.Environment
import qualified Data.List as L
import qualified System.IO as IO

--------------------------------------------------------------------------------
data Config a = Auto | Explicit a deriving (Eq)
Expand Down Expand Up @@ -48,4 +49,7 @@ withEscapeSequence f = do
let inScreen = maybe False ("screen" `L.isPrefixOf`) term
putStr $ if inScreen then "\ESCPtmux;\ESC\ESC]" else "\ESC]"
f
putStrLn $ if inScreen then "\a\ESC\\" else "\a"
putStr $ if inScreen then "\a\ESC\\" else "\a"
-- Make sure we don't print a newline after the image, or it may scroll
-- slightly out of view to the top. We flush instead.
IO.hFlush IO.stdout

0 comments on commit 346c24f

Please sign in to comment.