on master help sign in
more documentation updates

Ignore-this: d43cbeedd6c1d2cad49b693ec8e92767 darcs-hash:20100907045642-f0a0d-d65dc6321ab47fb92e2d89f9e385234b1a45071b.gz

commitc0faeca09a055647933aadc8248049993f02828d authorcoreyoconnor <coreyoconnor@gmail.com> dateMon 6 Sep 2010, 21:56 (16 years ago) parenta3f57da
3 files changed+57−20
src/Graphics/Vty/Inline.hs+35−7 src/Graphics/Vty/Terminal.hs+21−12 src/Graphics/Vty/Terminal/TerminfoBased.hs+1−1
src/Graphics/Vty/Inline.hs+35−7
@@ -1,3 +1,25 @@
1+-- | The inline module provides a limited interface to changing the style of terminal output. The
2+-- intention is for this interface to be used inline with other output systems.
3+--
4+-- The changes specified by the InlineM monad are applied to the terminals display attributes. These
5+-- display attributes effect the display of all following text output to the terminal file
6+-- descriptor.
7+--
8+-- For example, in an IO monad the following code with print the text \"Not styled. \" Followed by the
9+-- text \" Styled! \" drawn over a red background and underlined.
10+--
11+-- @
12+-- t <- terminal_handle
13+-- putStr \"Not styled. \"
14+-- put_attr_change t $ do
15+-- back_color red
16+-- apply_style underline
17+-- putStr \" Styled! \"
18+-- put_attr_change t $ default_all
19+-- putStrLn \"Not styled.\"
20+-- release_terminal t
21+-- @
22+--
123-- Copyright 2009-2010 Corey O'Connor
224{-# LANGUAGE BangPatterns #-}
325module Graphics.Vty.Inline ( module Graphics.Vty.Inline
@@ -20,15 +42,24 @@ import System.IO
2042
2143type InlineM v = State Attr v
2244
45+-- | Set the background color to the provided 'Color'
2346back_color :: Color -> InlineM ()
2447back_color c = modify $ flip mappend ( current_attr `with_back_color` c )
2548
49+-- | Set the foreground color to the provided 'Color'
2650fore_color :: Color -> InlineM ()
2751fore_color c = modify $ flip mappend ( current_attr `with_fore_color` c )
2852
53+-- | Attempt to change the 'Style' of the following text.
54+--
55+-- If the terminal does not support the style change no error is produced. The style can still be
56+-- removed.
2957apply_style :: Style -> InlineM ()
3058apply_style s = modify $ flip mappend ( current_attr `with_style` s )
3159
60+-- | Attempt to remove the specified 'Style' from the display of the following text.
61+--
62+-- This will fail if apply_style for the given style has not been previously called.
3263remove_style :: Style -> InlineM ()
3364remove_style s_mask = modify $ \attr ->
3465 let style' = case attr_style attr of
@@ -37,9 +68,13 @@ remove_style s_mask = modify $ \attr ->
3768 SetTo s -> s .&. complement s_mask
3869 in attr { attr_style = SetTo style' }
3970
71+-- | Reset the display attributes
4072default_all :: InlineM ()
4173default_all = put def_attr
4274
75+-- | Apply the provided display attribute changes to the terminal.
76+--
77+-- This also flushes the 'stdout' handle.
4378put_attr_change :: ( Applicative m, MonadIO m ) => TerminalHandle -> InlineM () -> m ()
4479put_attr_change t c = do
4580 bounds <- display_bounds t
@@ -60,10 +95,3 @@ put_attr_change t c = do
6095 liftIO $ modifyIORef ( state_ref t ) $ \s -> s { known_fattr = Just fattr' }
6196 inline_hack d
6297
63−put_string :: ( Applicative m, MonadIO m ) => TerminalHandle -> String -> m ()
64−put_string t s = do
65− let s_utf8 = UTF8.fromString s
66− liftIO $ hFlush stdout
67− liftIO $ marshall_to_terminal t ( utf8_text_required_bytes s_utf8)
68− ( serialize_utf8_text s_utf8 )
69−
src/Graphics/Vty/Terminal.hs+21−12
@@ -1,17 +1,23 @@
1−-- Copyright 2009-2010 Corey O'Connor
2−-- * Graphics.Vty.Terminal: This instantiates an abtract interface to the terminal interface
3−-- based on the TERM and COLORTERM environment variables.
4−-- * Graphics.Vty.Terminal.Generic: Defines the generic interface all terminals need to implement.
5−-- * Graphics.Vty.Terminal.TerminfoBased: Defines a terminal instance that uses terminfo for all
6−-- control strings.
7−-- - No attempt is made to change the character set to UTF-8 for these terminals. I don't
8−-- know a way to reliably determine if that is required or how to do so.
9−-- * Graphics.Vty.Terminal.XTermColor: This module contains an interface suitable for
10−-- xterm-like terminals. These are the terminals where TERM == xterm. This does use terminfo
11−-- for as many control codes as possible. H: This should derive functionality from the
12−-- TerminfoBased terminal.
1+-- | Generic Terminal interface.
2+--
3+-- Defines the common interface supported by all terminals.
4+--
5+-- See also:
6+--
7+-- 1. Graphics.Vty.Terminal: This instantiates an abtract interface to the terminal interface based
8+-- on the TERM and COLORTERM environment variables.
9+--
10+-- 2. Graphics.Vty.Terminal.Generic: Defines the generic interface all terminals need to implement.
1311--
12+-- 3. Graphics.Vty.Terminal.TerminfoBased: Defines a terminal instance that uses terminfo for all
13+-- control strings. No attempt is made to change the character set to UTF-8 for these terminals.
14+-- I don't know a way to reliably determine if that is required or how to do so.
1415--
16+-- 4. Graphics.Vty.Terminal.XTermColor: This module contains an interface suitable for xterm-like
17+-- terminals. These are the terminals where TERM == xterm. This does use terminfo for as many
18+-- control codes as possible.
19+--
20+-- Copyright 2009-2010 Corey O'Connor
1521{-# LANGUAGE ScopedTypeVariables #-}
1622module Graphics.Vty.Terminal ( module Graphics.Vty.Terminal
1723 , Terminal(..)
@@ -67,6 +73,9 @@ import System.Environment
6773-- environment variables (I think?) this assumes that XTERM_VERSION will never be set for a true
6874-- Terminal.app or iTerm.app session.
6975--
76+--
77+-- The file descriptor used for output will a duplicate of the current stdout file descriptor.
78+--
7079-- todo: add an implementation for windows that does not depend on terminfo. Should be installable
7180-- with only what is provided in the haskell platform.
7281--
src/Graphics/Vty/Terminal/TerminfoBased.hs+1−1
@@ -171,7 +171,7 @@ instance Terminal Term where
171171 ( w, h ) | w < 0 || h < 0 -> fail $ "getwinsize returned < 0 : " ++ show raw_size
172172 | otherwise -> return $ DisplayRegion (toEnum w) (toEnum h)
173173
174− -- Output the byte buffer of the specified size to the terminal device.
174+ -- | Output the byte buffer of the specified size to the terminal device.
175175 output_byte_buffer t out_ptr out_byte_count = do
176176 -- if the out fd is actually the same as stdout's then a
177177 -- flush is required *before* the c_output_byte_buffer call