Ticket #3204: As user, I want to use own default colors for viewer.
[midnight-commander.git] / src / viewer / plain.c
blob3970f1770c448cb177be87edc995644f8083aa56
1 /*
2 Internal file viewer for the Midnight Commander
3 Function for plain view
5 Copyright (C) 1994-2014
6 Free Software Foundation, Inc.
8 Written by:
9 Miguel de Icaza, 1994, 1995, 1998
10 Janne Kukonlehto, 1994, 1995
11 Jakub Jelinek, 1995
12 Joseph M. Hinkle, 1996
13 Norbert Warmuth, 1997
14 Pavel Machek, 1998
15 Roland Illig <roland.illig@gmx.de>, 2004, 2005
16 Slava Zanko <slavazanko@google.com>, 2009
17 Andrew Borodin <aborodin@vmail.ru>, 2009, 2010, 2013
18 Ilia Maslakov <il.smind@gmail.com>, 2009
20 This file is part of the Midnight Commander.
22 The Midnight Commander is free software: you can redistribute it
23 and/or modify it under the terms of the GNU General Public License as
24 published by the Free Software Foundation, either version 3 of the License,
25 or (at your option) any later version.
27 The Midnight Commander is distributed in the hope that it will be useful,
28 but WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 GNU General Public License for more details.
32 You should have received a copy of the GNU General Public License
33 along with this program. If not, see <http://www.gnu.org/licenses/>.
36 #include <config.h>
38 #include "lib/global.h"
39 #include "lib/tty/tty.h"
40 #include "lib/skin.h"
41 #include "lib/util.h" /* is_printable() */
42 #ifdef HAVE_CHARSET
43 #include "lib/charsets.h"
44 #endif
46 #include "src/setup.h" /* option_tab_spacing */
48 #include "internal.h"
50 /*** global variables ****************************************************************************/
52 /*** file scope macro definitions ****************************************************************/
54 /*** file scope type declarations ****************************************************************/
56 /*** file scope variables ************************************************************************/
58 /*** file scope functions ************************************************************************/
59 /* --------------------------------------------------------------------------------------------- */
61 /* --------------------------------------------------------------------------------------------- */
62 /*** public functions ****************************************************************************/
63 /* --------------------------------------------------------------------------------------------- */
65 void
66 mcview_display_text (mcview_t * view)
68 const screen_dimen left = view->data_area.left;
69 const screen_dimen top = view->data_area.top;
70 const screen_dimen width = view->data_area.width;
71 const screen_dimen height = view->data_area.height;
72 screen_dimen row = 0, col = 0;
73 off_t from;
74 int cw = 1;
75 int c, prev_ch = 0;
76 gboolean last_row = TRUE;
77 struct hexedit_change_node *curr = view->change_list;
79 mcview_display_clean (view);
80 mcview_display_ruler (view);
82 /* Find the first displayable changed byte */
83 from = view->dpy_start;
84 while ((curr != NULL) && (curr->offset < from))
85 curr = curr->next;
87 while (TRUE)
89 tty_setcolor (VIEW_NORMAL_COLOR);
91 if (row >= height)
92 break;
94 #ifdef HAVE_CHARSET
95 if (view->utf8)
97 gboolean read_res = TRUE;
99 c = mcview_get_utf (view, from, &cw, &read_res);
100 if (!read_res)
101 break;
103 else
104 #endif
105 if (!mcview_get_byte (view, from, &c))
106 break;
108 last_row = FALSE;
109 from++;
110 if (cw > 1)
111 from += cw - 1;
113 if (c != '\n' && prev_ch == '\r')
115 if (++row >= height)
116 break;
118 col = 0;
119 /* tty_print_anychar ('\n'); */
122 prev_ch = c;
123 if (c == '\r')
124 continue;
126 if (c == '\n')
128 col = 0;
129 row++;
130 continue;
133 if (col >= width && view->text_wrap_mode)
135 col = 0;
136 if (++row >= height)
137 break;
140 if (c == '\t')
142 col += (option_tab_spacing - col % option_tab_spacing);
143 if (view->text_wrap_mode && col >= width && width != 0)
145 row += col / width;
146 col %= width;
148 continue;
151 if (view->search_start <= from && from < view->search_end)
152 tty_setcolor (SELECTED_COLOR);
154 if (((off_t) col >= view->dpy_text_column)
155 && ((off_t) col - view->dpy_text_column < (off_t) width))
157 widget_move (view, top + row, left + ((off_t) col - view->dpy_text_column));
158 #ifdef HAVE_CHARSET
159 if (mc_global.utf8_display)
161 if (!view->utf8)
162 c = convert_from_8bit_to_utf_c ((unsigned char) c, view->converter);
163 if (!g_unichar_isprint (c))
164 c = '.';
166 else if (view->utf8)
167 c = convert_from_utf_to_current_c (c, view->converter);
168 else
169 #endif
171 #ifdef HAVE_CHARSET
172 c = convert_to_display_c (c);
173 #endif
174 if (!is_printable (c))
175 c = '.';
178 tty_print_anychar (c);
181 col++;
183 #ifdef HAVE_CHARSET
184 if (view->utf8)
186 if (g_unichar_iswide (c))
187 col++;
188 else if (g_unichar_iszerowidth (c))
189 col--;
191 #endif
194 view->dpy_end = from;
195 if (mcview_show_eof != NULL && mcview_show_eof[0] != '\0')
197 if (last_row && mcview_get_byte (view, from - 1, &c))
198 if (c != '\n')
199 row--;
200 while (++row < height)
202 widget_move (view, top + row, left);
203 tty_print_string (mcview_show_eof);
208 /* --------------------------------------------------------------------------------------------- */