Ticket #1791: a nice dark skin created by Lee Bigelow.
[kaloumi3.git] / src / viewer / plain.c
blobbd005165977582f27bd59e2c924a3a27eb78e78d
1 /*
2 Internal file viewer for the Midnight Commander
3 Function for plain view
5 Copyright (C) 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003,
6 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
8 Written by: 1994, 1995, 1998 Miguel de Icaza
9 1994, 1995 Janne Kukonlehto
10 1995 Jakub Jelinek
11 1996 Joseph M. Hinkle
12 1997 Norbert Warmuth
13 1998 Pavel Machek
14 2004 Roland Illig <roland.illig@gmx.de>
15 2005 Roland Illig <roland.illig@gmx.de>
16 2009 Slava Zanko <slavazanko@google.com>
17 2009 Andrew Borodin <aborodin@vmail.ru>
18 2009 Ilia Maslakov <il.smind@gmail.com>
19 2010 Andrew Borodin <aborodin@vmail.ru>
21 This file is part of the Midnight Commander.
23 The Midnight Commander is free software; you can redistribute it
24 and/or modify it under the terms of the GNU General Public License as
25 published by the Free Software Foundation; either version 2 of the
26 License, or (at your option) any later version.
28 The Midnight Commander is distributed in the hope that it will be
29 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
30 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31 General Public License for more details.
33 You should have received a copy of the GNU General Public License
34 along with this program; if not, write to the Free Software
35 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
36 MA 02110-1301, USA.
39 #include <config.h>
41 #include "lib/tty/tty.h"
43 #include "lib/skin.h"
45 #include "lib/global.h"
46 #include "src/main.h"
47 #include "src/charsets.h"
48 #include "mcviewer.h" /* mcview_show_eof */
50 #include "internal.h"
52 /*** global variables ****************************************************************************/
54 /*** file scope macro definitions ****************************************************************/
56 /*** file scope type declarations ****************************************************************/
58 /*** file scope variables ************************************************************************/
60 /*** file scope functions ************************************************************************/
62 /*** public functions ****************************************************************************/
64 /* --------------------------------------------------------------------------------------------- */
66 void
67 mcview_display_text (mcview_t * view)
69 const screen_dimen left = view->data_area.left;
70 const screen_dimen top = view->data_area.top;
71 const screen_dimen width = view->data_area.width;
72 const screen_dimen height = view->data_area.height;
73 screen_dimen row = 0, col = 0;
74 off_t from;
75 int cw = 1;
76 int c, prev_ch = 0;
77 gboolean last_row = TRUE;
78 struct hexedit_change_node *curr = view->change_list;
80 mcview_display_clean (view);
81 mcview_display_ruler (view);
83 /* Find the first displayable changed byte */
84 from = view->dpy_start;
85 while ((curr != NULL) && (curr->offset < from))
86 curr = curr->next;
88 while (TRUE)
90 tty_setcolor (NORMAL_COLOR);
92 if (row >= height)
93 break;
95 #ifdef HAVE_CHARSET
96 if (view->utf8)
98 gboolean read_res = TRUE;
100 c = mcview_get_utf (view, from, &cw, &read_res);
101 if (!read_res)
102 break;
104 else
105 #endif
106 if (!mcview_get_byte (view, from, &c))
107 break;
109 last_row = FALSE;
110 from++;
111 if (cw > 1)
112 from += cw - 1;
114 if (c != '\n' && prev_ch == '\r')
116 if (++row >= height)
117 break;
119 col = 0;
120 /* tty_print_anychar ('\n'); */
123 prev_ch = c;
124 if (c == '\r')
125 continue;
127 if (c == '\n')
129 col = 0;
130 row++;
131 continue;
134 if (col >= width && view->text_wrap_mode)
136 col = 0;
137 if (++row >= height)
138 break;
141 if (c == '\t')
143 col += (option_tab_spacing - col % option_tab_spacing);
144 if (view->text_wrap_mode && col >= width && width != 0)
146 row += col / width;
147 col %= width;
149 continue;
152 if (view->search_start <= from && from < view->search_end)
153 tty_setcolor (SELECTED_COLOR);
155 if ((col >= view->dpy_text_column) && (col - view->dpy_text_column < width))
157 widget_move (view, top + row, left + (col - view->dpy_text_column));
158 #ifdef HAVE_CHARSET
159 if (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 c = convert_to_display_c (c);
173 if (!is_printable (c))
174 c = '.';
177 tty_print_anychar (c);
180 col++;
182 #ifdef HAVE_CHARSET
183 if (view->utf8)
185 if (g_unichar_iswide (c))
186 col++;
187 else if (g_unichar_iszerowidth (c))
188 col--;
190 #endif
193 view->dpy_end = from;
194 if (mcview_show_eof != NULL && mcview_show_eof[0] != '\0')
196 if (last_row && mcview_get_byte (view, from - 1, &c))
197 if (c != '\n')
198 row--;
199 while (++row < height)
201 widget_move (view, top + row, left);
202 tty_print_string (mcview_show_eof);
207 /* --------------------------------------------------------------------------------------------- */