output.c File Reference

Generic output functions. More...

#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <termios.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/termios.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <unistd.h>
#include <wctype.h>
#include <ncurses.h>
#include <termio.h>
#include <term.h>
#include <signal.h>
#include <fcntl.h>
#include <dirent.h>
#include <time.h>
#include <wchar.h>
#include "fallback.h"
#include "util.h"
#include "wutil.h"
#include "expand.h"
#include "common.h"
#include "output.h"
#include "halloc_util.h"
#include "highlight.h"

Defines

#define COLORS   (sizeof(col)/sizeof(wchar_t *))
 Number of color names in the col array.

Functions

static int writeb_internal (char c)
 Default output method, simply calls write() on stdout.
static void output_destroy ()
 Cleanup function.
void output_set_writer (int(*writer)(char))
 Set the function used for writing in move_cursor, writespace and set_color and all other output functions in this library.
int(*)(char) output_get_writer ()
 Return the current output writer.
void set_color (int c, int c2)
 Sets the fg and bg color.
int writeb (tputs_arg_t b)
 This is for writing process notification messages.
int writembs_internal (char *str)
 Write a char * narrow string to FD 1, needed for the terminfo strings.
int writech (wint_t ch)
 Write a wide character using the output method specified using output_set_writer().
void writestr (const wchar_t *str)
 Write a wide character string to FD 1.
void writestr_ellipsis (const wchar_t *str, int max_width)
 Write a wide character string to FD 1.
int write_escaped_str (const wchar_t *str, int max_len)
 Escape and write a string to fd 1.
int output_color_code (const wchar_t *val)
 Return the internal color code representing the specified color.
void output_set_term (wchar_t *term)
 Set the terminal name.
wchar_t * output_get_term ()
 Return the terminal name.

Variables

static wchar_t * col []
 Names of different colors.
static int col_idx []
 Mapping from color name (the 'col' array) to color index as used in ANSI color terminals, and also the fish_color_* constants defined in highlight.h.
static size_t writestr_buff_sz = 0
 Size of writestr_buff.
static char * writestr_buff = 0
 Temp buffer used for converting from wide to narrow strings.
static int(* out )(char c) = &writeb_internal
 The function used for output.
static wchar_t * current_term = 0
 Name of terminal.


Detailed Description

Generic output functions.


Function Documentation

static void output_destroy (  )  [static]

Cleanup function.

Run automatically through halloc

References writestr_buff.

Referenced by writestr().

void output_set_writer ( int(*)(char)  writer  ) 

Set the function used for writing in move_cursor, writespace and set_color and all other output functions in this library.

By default, the write call is used to give completely unbuffered output to stdout.

References CHECK, out, and writer().

Referenced by s_move(), s_set_color(), s_write_char(), s_write_mbs(), and s_write_str().

void set_color ( int  c,
int  c2 
)

Sets the fg and bg color.

May be called as often as you like, since if the new color is the same as the previous, nothing will be written. Negative values for set_color will also be ignored. Since the terminfo string this function emits can potentially cause the screen to flicker, the function takes care to write as little as possible.

Possible values for color are any form the FISH_COLOR_* enum, FISH_COLOR_IGNORE and FISH_COLOR_RESET. FISH_COLOR_IGNORE will leave the color unchanged, and FISH_COLOR_RESET will perform an exit_attribute_mode, even if set_color thinks it is already in FISH_COLOR_NORMAL mode.

In order to set the color to normal, three terminfo strings may have to be written.

  • First a string to set the color, such as set_a_foreground. This is needed because otherwise the previous strings colors might be removed as well.

  • After that we write the exit_attribute_mode string to reset all color attributes.

  • Lastly we may need to write set_a_background or set_a_foreground to set the other half of the color pair to what it should be.

Parameters:
c Foreground color.
c2 Background color.

References FISH_COLOR_BOLD, FISH_COLOR_NORMAL, FISH_COLOR_UNDERLINE, and writembs.

Referenced by reader_interactive_destroy(), reader_readline(), reader_write_title(), s_set_color(), and term_donate().

int writeb ( tputs_arg_t  b  ) 

This is for writing process notification messages.

Has to write to stdout, so clr_eol and such functions will work correctly. Not an issue since this function is only used in interactive mode anyway.

References out.

Referenced by format_job_info(), job_reap(), and writembs_internal().

int writembs_internal ( char *  str  ) 

Write a char * narrow string to FD 1, needed for the terminfo strings.

This is usually just a wrapper aound tputs, using writeb as the sending function. But a weird bug on PPC Linux means that on this platform, write is instead used directly.

References CHECK, and writeb().

void writestr_ellipsis ( const wchar_t *  str,
int  max_width 
)

Write a wide character string to FD 1.

If the string is wider than the specified maximum, truncate and ellipsize it.

References CHECK, ellipsis_char, my_wcswidth(), writech(), and writestr().


Variable Documentation

wchar_t* col[] [static]

Initial value:

{
        L"black",
        L"red",
        L"green",
        L"brown",
        L"yellow",
        L"blue",
        L"magenta",
        L"purple",
        L"cyan",
        L"white"
        L"normal"
}
Names of different colors.

Referenced by output_color_code(), and s_write().

int col_idx[] [static]

Initial value:

{
        0, 
        1,
        2,
        3,
        3,
        4,
        5,
        5,
        6,
        7,
        FISH_COLOR_NORMAL,
}
Mapping from color name (the 'col' array) to color index as used in ANSI color terminals, and also the fish_color_* constants defined in highlight.h.

Non-ANSI terminals will display the wrong colors, since they use a different mapping.

Referenced by output_color_code().


Generated on Sun Mar 8 15:46:55 2009 for fish by  doxygen 1.5.6