on master help sign in
Output: add setDisplayBounds field and implementation for TerminfoBased backend
commit6a9c90da0e093cec1d4903924eb0f6a33be489cb authorJonathan Daugherty <cygnus@foobox.com> dateWed 15 Jul 2020, 13:49 (6 years ago) parent5922c53
5 files changed+24
cbits/gwinsz.c+9 cbits/gwinsz.h+1 src/Graphics/Vty/Output/Interface.hs+2 src/Graphics/Vty/Output/Mock.hs+1 src/Graphics/Vty/Output/TerminfoBased.hs+11
cbits/gwinsz.c+9
@@ -7,3 +7,12 @@ unsigned long vty_c_get_window_size(int fd) {
77 else
88 return 0x190050;
99}
10+
11+void vty_c_set_window_size(int fd, unsigned long val) {
12+ struct winsize w;
13+ if (ioctl(fd, TIOCGWINSZ, &w) >= 0) {
14+ w.ws_row = val >> 16;
15+ w.ws_col = val & 0xFFFF;
16+ ioctl(fd, TIOCSWINSZ, &w);
17+ }
18+}
cbits/gwinsz.h+1
@@ -1 +1,2 @@
11unsigned long vty_c_get_window_size(void);
2+unsigned long vty_c_set_window_size(int fd, unsigned long val);
src/Graphics/Vty/Output/Interface.hs+2
@@ -73,6 +73,8 @@ data Output = Output
7373 -- | Return the display to the state before `reserveDisplay` If no
7474 -- previous state then set the display state to the initial state.
7575 , releaseDisplay :: IO ()
76+ -- | Sets the current display bounds (width, height).
77+ , setDisplayBounds :: (Int, Int) -> IO ()
7678 -- | Returns the current display bounds.
7779 , displayBounds :: IO DisplayRegion
7880 -- | Output the bytestring to the terminal device.
src/Graphics/Vty/Output/Mock.hs+1
@@ -48,6 +48,7 @@ mockTerminal r = liftIO $ do
4848 , releaseDisplay = return ()
4949 , ringTerminalBell = return ()
5050 , supportsBell = return False
51+ , setDisplayBounds = const $ return ()
5152 , displayBounds = return r
5253 , outputByteBuffer = \bytes -> do
5354 putStrLn $ "mock outputByteBuffer of " ++ show (BS.length bytes) ++ " bytes"
src/Graphics/Vty/Output/TerminfoBased.hs+11
@@ -10,10 +10,12 @@
1010-- Copyright Corey O'Connor (coreyoconnor@gmail.com)
1111module Graphics.Vty.Output.TerminfoBased
1212 ( reserveTerminal
13+ , setWindowSize
1314 )
1415where
1516
1617import Control.Monad (when)
18+import Data.Bits (shiftL)
1719import qualified Data.ByteString as BS
1820import Data.ByteString.Internal (toForeignPtr)
1921import Data.Terminfo.Parse
@@ -174,6 +176,8 @@ reserveTerminal termName outFd = do
174176 , releaseDisplay = do
175177 maybeSendCap rmcup []
176178 maybeSendCap cnorm []
179+ , setDisplayBounds = \(w, h) ->
180+ setWindowSize outFd (w, h)
177181 , displayBounds = do
178182 rawSize <- getWindowSize outFd
179183 case rawSize of
@@ -244,6 +248,13 @@ getWindowSize fd = do
244248 (a,b) <- (`divMod` 65536) `fmap` c_getWindowSize fd
245249 return (fromIntegral b, fromIntegral a)
246250
251+foreign import ccall "gwinsz.h vty_c_set_window_size" c_setWindowSize :: Fd -> CLong -> IO ()
252+
253+setWindowSize :: Fd -> (Int, Int) -> IO ()
254+setWindowSize fd (w, h) = do
255+ let val = (h `shiftL` 16) + w
256+ c_setWindowSize fd $ fromIntegral val
257+
247258terminfoDisplayContext :: Output -> TerminfoCaps -> DisplayRegion -> IO DisplayContext
248259terminfoDisplayContext tActual terminfoCaps r = return dc
249260 where dc = DisplayContext