Invoke write directly instead of via hPutBuf

Ignore-this: 172072f7a4876e5864c8e54f896bf0b0

darcs-hash:20100114091229-f0a0d-915e8160f8cf596abbae4df8c9d883febeedf509.gz
This commit is contained in:
coreyoconnor 2010-01-14 01:12:29 -08:00
parent ac46ab8f66
commit 4f06259de3
5 changed files with 38 additions and 6 deletions

18
cbits/output_buffer.c Normal file
View File

@ -0,0 +1,18 @@
#define _XOPEN_SOURCE 500
#include <unistd.h>
#include "output_buffer.h"
void stdout_output_buffer ( uint8_t* buffer, size_t buffer_size )
{
while ( buffer_size )
{
const ssize_t r = write( STDOUT_FILENO, (void*) buffer, buffer_size );
buffer_size -= (size_t) r;
buffer += (size_t) r;
}
fdatasync( STDOUT_FILENO );
}

5
cbits/output_buffer.h Normal file
View File

@ -0,0 +1,5 @@
#define _XOPEN_SOURCE 500
#include <unistd.h>
#include <stdint.h>
void stdout_output_buffer ( uint8_t* buffer, size_t buffer_size );

View File

@ -2,6 +2,7 @@
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE FlexibleInstances #-}
{-# OPTIONS_GHC -D_XOPEN_SOURCE=500 #-}
module Graphics.Vty.Terminal.TerminfoBased ( terminal_instance
)
where
@ -22,7 +23,8 @@ import Data.Bits ( (.&.) )
import Data.Maybe ( isJust, isNothing, fromJust )
import Data.Word
import Foreign.C.Types ( CLong )
import Foreign.Ptr
import Foreign.C.Types ( CLong, CSize )
import qualified System.Console.Terminfo as Terminfo
import System.IO
@ -164,12 +166,17 @@ instance Terminal Term where
-- Output the byte buffer of the specified size to the terminal device.
output_byte_buffer _t out_ptr out_byte_count = do
if out_byte_count == 0
then return ()
else hPutBuf stdout out_ptr (fromEnum out_byte_count)
-- flush is required *before* the c_output_byte_buffer call
-- otherwise there may still be data in GHC's internal stdout buffer.
hFlush stdout
if out_byte_count /= 0
then c_output_byte_buffer out_ptr ( toEnum $! fromEnum out_byte_count )
else return ()
foreign import ccall "gwinsz.h c_get_window_size" c_get_window_size :: IO CLong
foreign import ccall unsafe "output_buffer.h stdout_output_buffer" c_output_byte_buffer
:: Ptr Word8 -> CSize -> IO ()
foreign import ccall "gwinsz.h c_get_window_size" c_get_window_size
:: IO CLong
get_window_size :: IO (Int,Int)
get_window_size = do

View File

@ -26,7 +26,7 @@ $(VERIF_TESTS)
$(shell mkdir -p objects )
# TODO: Tests should also be buildable referencing the currently installed vty
GHC_ARGS=--make -i../src -package parallel -package deepseq-1.1.0.0 -hide-package transformers -hide-package monads-fd -hide-package monads-tf -package QuickCheck-2.1.0.2 -ignore-package vty ../cbits/gwinsz.c ../cbits/set_term_timing.c ../cbits/mk_wcwidth.c -O -funbox-strict-fields -Wall -threaded -fno-full-laziness -fspec-constr -odir objects -hidir objects
GHC_ARGS=--make -i../src -package parallel -package deepseq-1.1.0.0 -hide-package transformers -hide-package monads-fd -hide-package monads-tf -package QuickCheck-2.1.0.2 -ignore-package vty ../cbits/gwinsz.c ../cbits/output_buffer.c ../cbits/set_term_timing.c ../cbits/mk_wcwidth.c -O -funbox-strict-fields -Wall -threaded -fno-full-laziness -fspec-constr -odir objects -hidir objects
GHC_PROF_ARGS=-prof -auto-all $(GHC_ARGS)

View File

@ -59,6 +59,8 @@ other-modules: Codec.Binary.UTF8.Width
C-Sources: cbits/gwinsz.c
cbits/set_term_timing.c
cbits/mk_wcwidth.c
cbits/output_buffer.c
Include-Dirs: cbits
hs-source-dirs: src
Extra-Source-Files: test/Makefile