This repository was archived by the owner on Feb 28, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 526
/
Copy pathpanel.c
5450 lines (4395 loc) · 149 KB
/
panel.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Panel managing.
Copyright (C) 1994-2025
Free Software Foundation, Inc.
Written by:
Miguel de Icaza, 1995
Timur Bakeyev, 1997, 1999
Slava Zanko <slavazanko@gmail.com>, 2013
Andrew Borodin <aborodin@vmail.ru>, 2013-2023
This file is part of the Midnight Commander.
The Midnight Commander is free software: you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version.
The Midnight Commander is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** \file panel.c
* \brief Source: panel managin module
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lib/global.h"
#include "lib/tty/tty.h"
#include "lib/tty/key.h" // XCTRL and ALT macros
#include "lib/skin.h"
#include "lib/strutil.h"
#include "lib/mcconfig.h"
#include "lib/vfs/vfs.h"
#include "lib/unixcompat.h"
#include "lib/search.h"
#include "lib/timefmt.h" // file_date()
#include "lib/util.h"
#include "lib/widget.h"
#ifdef HAVE_CHARSET
# include "lib/charsets.h" // get_codepage_id ()
#endif
#include "lib/event.h"
#include "src/setup.h" // For loading/saving panel options
#include "src/execute.h"
#ifdef HAVE_CHARSET
# include "src/selcodepage.h" // select_charset (), SELECT_CHARSET_NO_TRANSLATE
#endif
#include "src/keymap.h" // global_keymap_t
#include "src/history.h"
#ifdef ENABLE_SUBSHELL
# include "src/subshell/subshell.h" // subshell_chdir()
#endif
#include "src/usermenu.h"
#include "dir.h"
#include "boxes.h"
#include "tree.h"
#include "ext.h" // regexp_command
#include "layout.h" // Most layout variables are here
#include "cmd.h"
#include "command.h" // cmdline
#include "filemanager.h"
#include "mountlist.h" // my_statfs
#include "cd.h" // cd_error_message()
#include "panel.h"
/*** global variables ****************************************************************************/
/* The hook list for the select file function */
hook_t *select_file_hook = NULL;
mc_fhl_t *mc_filehighlight = NULL;
/*** file scope macro definitions ****************************************************************/
typedef enum
{
FATTR_NORMAL = 0,
FATTR_CURRENT,
FATTR_MARKED,
FATTR_MARKED_CURRENT,
FATTR_STATUS
} file_attr_t;
#define DEFAULT_USER_FORMAT "half type name | size | perm"
/* select/unselect dialog results */
#define SELECT_RESET ((mc_search_t *) (-1))
#define SELECT_ERROR ((mc_search_t *) (-2))
/* mouse position relative to file list */
#define MOUSE_UPPER_FILE_LIST (-1)
#define MOUSE_BELOW_FILE_LIST (-2)
#define MOUSE_AFTER_LAST_FILE (-3)
/*** file scope type declarations ****************************************************************/
typedef enum
{
MARK_DONT_MOVE = 0,
MARK_DOWN = 1,
MARK_FORCE_DOWN = 2,
MARK_FORCE_UP = 3
} mark_act_t;
/*
* This describes a format item. The parse_display_format routine parses
* the user specified format and creates a linked list of format_item_t structures.
*/
typedef struct format_item_t
{
int requested_field_len;
int field_len;
align_crt_t just_mode;
gboolean expand;
const char *(*string_fn) (const file_entry_t *fe, int len);
char *title;
const char *id;
} format_item_t;
/* File name scroll states */
typedef enum
{
FILENAME_NOSCROLL = 1,
FILENAME_SCROLL_LEFT = 2,
FILENAME_SCROLL_RIGHT = 4
} filename_scroll_flag_t;
/*** forward declarations (file scope functions) *************************************************/
static const char *string_file_name (const file_entry_t *fe, int len);
static const char *string_file_size (const file_entry_t *fe, int len);
static const char *string_file_size_brief (const file_entry_t *fe, int len);
static const char *string_file_type (const file_entry_t *fe, int len);
static const char *string_file_mtime (const file_entry_t *fe, int len);
static const char *string_file_atime (const file_entry_t *fe, int len);
static const char *string_file_ctime (const file_entry_t *fe, int len);
static const char *string_file_permission (const file_entry_t *fe, int len);
static const char *string_file_perm_octal (const file_entry_t *fe, int len);
static const char *string_file_nlinks (const file_entry_t *fe, int len);
static const char *string_inode (const file_entry_t *fe, int len);
static const char *string_file_nuid (const file_entry_t *fe, int len);
static const char *string_file_ngid (const file_entry_t *fe, int len);
static const char *string_file_owner (const file_entry_t *fe, int len);
static const char *string_file_group (const file_entry_t *fe, int len);
static const char *string_marked (const file_entry_t *fe, int len);
static const char *string_space (const file_entry_t *fe, int len);
static const char *string_dot (const file_entry_t *fe, int len);
/*** file scope variables ************************************************************************/
static panel_field_t panel_fields[] = {
{ "unsorted", 12, TRUE, J_LEFT_FIT,
// TRANSLATORS: one single character to represent 'unsorted' sort mode
// TRANSLATORS: no need to translate 'sort', it's just a context prefix
N_ ("sort|u"), N_ ("&Unsorted"), TRUE, FALSE, string_file_name, (GCompareFunc) unsorted },
{ "name", 12, TRUE, J_LEFT_FIT,
// TRANSLATORS: one single character to represent 'name' sort mode
// TRANSLATORS: no need to translate 'sort', it's just a context prefix
N_ ("sort|n"), N_ ("&Name"), TRUE, TRUE, string_file_name, (GCompareFunc) sort_name },
{ "version", 12, TRUE, J_LEFT_FIT,
// TRANSLATORS: one single character to represent 'version' sort mode
// TRANSLATORS: no need to translate 'sort', it's just a context prefix
N_ ("sort|v"), N_ ("&Version"), TRUE, FALSE, string_file_name, (GCompareFunc) sort_vers },
{ "extension", 12, TRUE, J_LEFT_FIT,
// TRANSLATORS: one single character to represent 'extension' sort mode
// TRANSLATORS: no need to translate 'sort', it's just a context prefix
N_ ("sort|e"), N_ ("E&xtension"), TRUE, FALSE,
string_file_name, // TODO: string_file_ext
(GCompareFunc) sort_ext },
{ "size", 7, FALSE, J_RIGHT,
// TRANSLATORS: one single character to represent 'size' sort mode
// TRANSLATORS: no need to translate 'sort', it's just a context prefix
N_ ("sort|s"), N_ ("&Size"), TRUE, TRUE, string_file_size, (GCompareFunc) sort_size },
{ "bsize", 7, FALSE, J_RIGHT, "", N_ ("Block Size"), FALSE, FALSE, string_file_size_brief,
(GCompareFunc) sort_size },
{ "type", 1, FALSE, J_LEFT, "", "", FALSE, TRUE, string_file_type, NULL },
{ "mtime", 12, FALSE, J_RIGHT,
// TRANSLATORS: one single character to represent 'Modify time' sort mode
// TRANSLATORS: no need to translate 'sort', it's just a context prefix
N_ ("sort|m"), N_ ("&Modify time"), TRUE, TRUE, string_file_mtime, (GCompareFunc) sort_time },
{ "atime", 12, FALSE, J_RIGHT,
// TRANSLATORS: one single character to represent 'Access time' sort mode
// TRANSLATORS: no need to translate 'sort', it's just a context prefix
N_ ("sort|a"), N_ ("&Access time"), TRUE, TRUE, string_file_atime,
(GCompareFunc) sort_atime },
{ "ctime", 12, FALSE, J_RIGHT,
// TRANSLATORS: one single character to represent 'Change time' sort mode
// TRANSLATORS: no need to translate 'sort', it's just a context prefix
N_ ("sort|h"), N_ ("C&hange time"), TRUE, TRUE, string_file_ctime,
(GCompareFunc) sort_ctime },
{ "perm", 10, FALSE, J_LEFT, "", N_ ("Permission"), FALSE, TRUE, string_file_permission, NULL },
{ "mode", 6, FALSE, J_RIGHT, "", N_ ("Perm"), FALSE, TRUE, string_file_perm_octal, NULL },
{ "nlink", 2, FALSE, J_RIGHT, "", N_ ("Nl"), FALSE, TRUE, string_file_nlinks, NULL },
{ "inode", 5, FALSE, J_RIGHT,
// TRANSLATORS: one single character to represent 'inode' sort mode
// TRANSLATORS: no need to translate 'sort', it's just a context prefix
N_ ("sort|i"), N_ ("&Inode"), TRUE, TRUE, string_inode, (GCompareFunc) sort_inode },
{ "nuid", 5, FALSE, J_RIGHT, "", N_ ("UID"), FALSE, FALSE, string_file_nuid, NULL },
{ "ngid", 5, FALSE, J_RIGHT, "", N_ ("GID"), FALSE, FALSE, string_file_ngid, NULL },
{ "owner", 8, FALSE, J_LEFT_FIT, "", N_ ("Owner"), FALSE, TRUE, string_file_owner, NULL },
{ "group", 8, FALSE, J_LEFT_FIT, "", N_ ("Group"), FALSE, TRUE, string_file_group, NULL },
{ "mark", 1, FALSE, J_RIGHT, "", " ", FALSE, TRUE, string_marked, NULL },
{ "|", 1, FALSE, J_RIGHT, "", " ", FALSE, TRUE, NULL, NULL },
{ "space", 1, FALSE, J_RIGHT, "", " ", FALSE, TRUE, string_space, NULL },
{ "dot", 1, FALSE, J_RIGHT, "", " ", FALSE, FALSE, string_dot, NULL },
{ NULL, 0, FALSE, J_RIGHT, NULL, NULL, FALSE, FALSE, NULL, NULL },
};
static char *panel_sort_up_char = NULL;
static char *panel_sort_down_char = NULL;
static int panel_sort_up_indicator_width = 0;
static int panel_sort_down_indicator_width = 0;
static char *panel_hiddenfiles_show_char = NULL;
static char *panel_hiddenfiles_hide_char = NULL;
static char *panel_history_prev_item_char = NULL;
static char *panel_history_next_item_char = NULL;
static char *panel_history_show_list_char = NULL;
static char *panel_filename_scroll_left_char = NULL;
static char *panel_filename_scroll_right_char = NULL;
/* Panel that selection started */
static WPanel *mouse_mark_panel = NULL;
static gboolean mouse_marking = FALSE;
static int state_mark = 0;
static GString *string_file_name_buffer;
/* --------------------------------------------------------------------------------------------- */
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
static panelized_descr_t *
panelized_descr_new (void)
{
panelized_descr_t *p;
p = g_new0 (panelized_descr_t, 1);
p->list.len = -1;
return p;
}
/* --------------------------------------------------------------------------------------------- */
static void
panelized_descr_free (panelized_descr_t *p)
{
if (p != NULL)
{
dir_list_free_list (&p->list);
vfs_path_free (p->root_vpath, TRUE);
g_free (p);
}
}
/* --------------------------------------------------------------------------------------------- */
static void
set_colors (const WPanel *panel)
{
(void) panel;
tty_set_normal_attrs ();
tty_setcolor (NORMAL_COLOR);
}
/* --------------------------------------------------------------------------------------------- */
/** Delete format_item_t object */
static void
format_item_free (format_item_t *format)
{
g_free (format->title);
g_free (format);
}
/* --------------------------------------------------------------------------------------------- */
/** Extract the number of available lines in a panel */
static int
panel_lines (const WPanel *p)
{
// 3 lines are: top frame, column header, button frame
return (CONST_WIDGET (p)->rect.lines - 3 - (panels_options.show_mini_info ? 2 : 0));
}
/* --------------------------------------------------------------------------------------------- */
/** This code relies on the default justification!!! */
static void
add_permission_string (const char *dest, int width, file_entry_t *fe, file_attr_t attr, int color,
gboolean is_octal)
{
int i, r, l;
l = get_user_permissions (&fe->st);
if (is_octal)
{
// Place of the access bit in octal mode
l = width + l - 3;
r = l + 1;
}
else
{
// The same to the triplet in string mode
l = l * 3 + 1;
r = l + 3;
}
for (i = 0; i < width; i++)
{
if (i >= l && i < r)
{
if (attr == FATTR_CURRENT || attr == FATTR_MARKED_CURRENT)
tty_setcolor (MARKED_SELECTED_COLOR);
else
tty_setcolor (MARKED_COLOR);
}
else if (color >= 0)
tty_setcolor (color);
else
tty_lowlevel_setcolor (-color);
tty_print_char (dest[i]);
}
}
/* --------------------------------------------------------------------------------------------- */
/** String representations of various file attributes name */
static const char *
string_file_name (const file_entry_t *fe, int len)
{
(void) len;
mc_g_string_copy (string_file_name_buffer, fe->fname);
return string_file_name_buffer->str;
}
/* --------------------------------------------------------------------------------------------- */
static unsigned int
ilog10 (dev_t n)
{
unsigned int digits = 0;
do
{
digits++;
n /= 10;
}
while (n != 0);
return digits;
}
/* --------------------------------------------------------------------------------------------- */
static void
format_device_number (char *buf, size_t bufsize, dev_t dev)
{
dev_t major_dev, minor_dev;
unsigned int major_digits, minor_digits;
major_dev = major (dev);
major_digits = ilog10 (major_dev);
minor_dev = minor (dev);
minor_digits = ilog10 (minor_dev);
g_assert (bufsize >= 1);
if (major_digits + 1 + minor_digits + 1 <= bufsize)
g_snprintf (buf, bufsize, "%lu,%lu", (unsigned long) major_dev, (unsigned long) minor_dev);
else
g_strlcpy (buf, _ ("[dev]"), bufsize);
}
/* --------------------------------------------------------------------------------------------- */
/** size */
static const char *
string_file_size (const file_entry_t *fe, int len)
{
static char buffer[BUF_TINY];
// Don't ever show size of ".." since we don't calculate it
if (DIR_IS_DOTDOT (fe->fname->str))
return _ ("UP--DIR");
#ifdef HAVE_STRUCT_STAT_ST_RDEV
if (S_ISBLK (fe->st.st_mode) || S_ISCHR (fe->st.st_mode))
format_device_number (buffer, len + 1, fe->st.st_rdev);
else
#endif
size_trunc_len (buffer, (unsigned int) len, fe->st.st_size, 0, panels_options.kilobyte_si);
return buffer;
}
/* --------------------------------------------------------------------------------------------- */
/** bsize */
static const char *
string_file_size_brief (const file_entry_t *fe, int len)
{
if (S_ISLNK (fe->st.st_mode) && !link_isdir (fe))
return _ ("SYMLINK");
if ((S_ISDIR (fe->st.st_mode) || link_isdir (fe)) && !DIR_IS_DOTDOT (fe->fname->str))
return _ ("SUB-DIR");
return string_file_size (fe, len);
}
/* --------------------------------------------------------------------------------------------- */
/** This functions return a string representation of a file entry type */
static const char *
string_file_type (const file_entry_t *fe, int len)
{
static char buffer[2];
(void) len;
if (S_ISDIR (fe->st.st_mode))
buffer[0] = PATH_SEP;
else if (S_ISLNK (fe->st.st_mode))
{
if (link_isdir (fe))
buffer[0] = '~';
else if (fe->f.stale_link != 0)
buffer[0] = '!';
else
buffer[0] = '@';
}
else if (S_ISCHR (fe->st.st_mode))
buffer[0] = '-';
else if (S_ISSOCK (fe->st.st_mode))
buffer[0] = '=';
else if (S_ISDOOR (fe->st.st_mode))
buffer[0] = '>';
else if (S_ISBLK (fe->st.st_mode))
buffer[0] = '+';
else if (S_ISFIFO (fe->st.st_mode))
buffer[0] = '|';
else if (S_ISNAM (fe->st.st_mode))
buffer[0] = '#';
else if (!S_ISREG (fe->st.st_mode))
buffer[0] = '?'; // non-regular of unknown kind
else if (is_exe (fe->st.st_mode))
buffer[0] = '*';
else
buffer[0] = ' ';
buffer[1] = '\0';
return buffer;
}
/* --------------------------------------------------------------------------------------------- */
/** mtime */
static const char *
string_file_mtime (const file_entry_t *fe, int len)
{
(void) len;
return file_date (fe->st.st_mtime);
}
/* --------------------------------------------------------------------------------------------- */
/** atime */
static const char *
string_file_atime (const file_entry_t *fe, int len)
{
(void) len;
return file_date (fe->st.st_atime);
}
/* --------------------------------------------------------------------------------------------- */
/** ctime */
static const char *
string_file_ctime (const file_entry_t *fe, int len)
{
(void) len;
return file_date (fe->st.st_ctime);
}
/* --------------------------------------------------------------------------------------------- */
/** perm */
static const char *
string_file_permission (const file_entry_t *fe, int len)
{
(void) len;
return string_perm (fe->st.st_mode);
}
/* --------------------------------------------------------------------------------------------- */
/** mode */
static const char *
string_file_perm_octal (const file_entry_t *fe, int len)
{
static char buffer[10];
(void) len;
g_snprintf (buffer, sizeof (buffer), "0%06lo", (unsigned long) fe->st.st_mode);
return buffer;
}
/* --------------------------------------------------------------------------------------------- */
/** nlink */
static const char *
string_file_nlinks (const file_entry_t *fe, int len)
{
static char buffer[BUF_TINY];
(void) len;
g_snprintf (buffer, sizeof (buffer), "%16d", (int) fe->st.st_nlink);
return buffer;
}
/* --------------------------------------------------------------------------------------------- */
/** inode */
static const char *
string_inode (const file_entry_t *fe, int len)
{
static char buffer[10];
(void) len;
g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->st.st_ino);
return buffer;
}
/* --------------------------------------------------------------------------------------------- */
/** nuid */
static const char *
string_file_nuid (const file_entry_t *fe, int len)
{
static char buffer[10];
(void) len;
g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->st.st_uid);
return buffer;
}
/* --------------------------------------------------------------------------------------------- */
/** ngid */
static const char *
string_file_ngid (const file_entry_t *fe, int len)
{
static char buffer[10];
(void) len;
g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->st.st_gid);
return buffer;
}
/* --------------------------------------------------------------------------------------------- */
/** owner */
static const char *
string_file_owner (const file_entry_t *fe, int len)
{
(void) len;
return get_owner (fe->st.st_uid);
}
/* --------------------------------------------------------------------------------------------- */
/** group */
static const char *
string_file_group (const file_entry_t *fe, int len)
{
(void) len;
return get_group (fe->st.st_gid);
}
/* --------------------------------------------------------------------------------------------- */
/** mark */
static const char *
string_marked (const file_entry_t *fe, int len)
{
(void) len;
return fe->f.marked != 0 ? "*" : " ";
}
/* --------------------------------------------------------------------------------------------- */
/** space */
static const char *
string_space (const file_entry_t *fe, int len)
{
(void) fe;
(void) len;
return " ";
}
/* --------------------------------------------------------------------------------------------- */
/** dot */
static const char *
string_dot (const file_entry_t *fe, int len)
{
(void) fe;
(void) len;
return ".";
}
/* --------------------------------------------------------------------------------------------- */
static int
file_compute_color (const file_attr_t attr, file_entry_t *fe)
{
switch (attr)
{
case FATTR_CURRENT:
return (SELECTED_COLOR);
case FATTR_MARKED:
return (MARKED_COLOR);
case FATTR_MARKED_CURRENT:
return (MARKED_SELECTED_COLOR);
case FATTR_STATUS:
return (NORMAL_COLOR);
case FATTR_NORMAL:
default:
if (!panels_options.filetype_mode)
return (NORMAL_COLOR);
}
return mc_fhl_get_color (mc_filehighlight, fe);
}
/* --------------------------------------------------------------------------------------------- */
/** Returns the number of items in the given panel */
static int
panel_items (const WPanel *p)
{
return panel_lines (p) * p->list_cols;
}
/* --------------------------------------------------------------------------------------------- */
/** Formats the file number file_index of panel in the buffer dest */
static filename_scroll_flag_t
format_file (WPanel *panel, int file_index, int width, file_attr_t attr, gboolean isstatus,
int *field_length)
{
int color = NORMAL_COLOR;
int length = 0;
GSList *format, *home;
file_entry_t *fe = NULL;
filename_scroll_flag_t res = FILENAME_NOSCROLL;
*field_length = 0;
if (panel->dir.len != 0 && file_index < panel->dir.len)
{
fe = &panel->dir.list[file_index];
color = file_compute_color (attr, fe);
}
home = isstatus ? panel->status_format : panel->format;
for (format = home; format != NULL && length != width; format = g_slist_next (format))
{
format_item_t *fi = (format_item_t *) format->data;
if (fi->string_fn != NULL)
{
const char *txt = " ";
int len, perm = 0;
const char *prepared_text;
int name_offset = 0;
if (fe != NULL)
txt = fi->string_fn (fe, fi->field_len);
len = fi->field_len;
if (len + length > width)
len = width - length;
if (len <= 0)
break;
if (!isstatus && panel->content_shift > -1 && strcmp (fi->id, "name") == 0)
{
int str_len;
int i;
*field_length = len + 1;
str_len = str_length (txt);
i = MAX (0, str_len - len);
panel->max_shift = MAX (panel->max_shift, i);
i = MIN (panel->content_shift, i);
if (i > -1)
{
name_offset = str_offset_to_pos (txt, i);
if (str_len > len)
{
res = FILENAME_SCROLL_LEFT;
if (str_length (txt + name_offset) > len)
res |= FILENAME_SCROLL_RIGHT;
}
}
}
if (panels_options.permission_mode)
{
if (strcmp (fi->id, "perm") == 0)
perm = 1;
else if (strcmp (fi->id, "mode") == 0)
perm = 2;
}
if (color >= 0)
tty_setcolor (color);
else
tty_lowlevel_setcolor (-color);
if (!isstatus && panel->content_shift > -1)
prepared_text = str_fit_to_term (txt + name_offset, len, HIDE_FIT (fi->just_mode));
else
prepared_text = str_fit_to_term (txt, len, fi->just_mode);
if (perm != 0 && fe != NULL)
add_permission_string (prepared_text, fi->field_len, fe, attr, color, perm != 1);
else
tty_print_string (prepared_text);
length += len;
}
else
{
if (attr == FATTR_CURRENT || attr == FATTR_MARKED_CURRENT)
tty_setcolor (SELECTED_COLOR);
else
tty_setcolor (NORMAL_COLOR);
tty_print_one_vline (TRUE);
length++;
}
}
if (length < width)
{
int y, x;
tty_getyx (&y, &x);
tty_draw_hline (y, x, ' ', width - length);
}
return res;
}
/* --------------------------------------------------------------------------------------------- */
static void
repaint_file (WPanel *panel, int file_index, file_attr_t attr)
{
Widget *w = WIDGET (panel);
int nth_column = 0;
int width;
int offset = 0;
filename_scroll_flag_t ret_frm;
int ypos = 0;
gboolean panel_is_split;
int fln = 0;
panel_is_split = panel->list_cols > 1;
width = w->rect.cols - 2;
if (panel_is_split)
{
nth_column = (file_index - panel->top) / panel_lines (panel);
width /= panel->list_cols;
offset = width * nth_column;
if (nth_column + 1 >= panel->list_cols)
width = w->rect.cols - offset - 2;
}
// Nothing to paint
if (width <= 0)
return;
ypos = file_index - panel->top;
if (panel_is_split)
ypos %= panel_lines (panel);
ypos += 2; // top frame and header
widget_gotoyx (w, ypos, offset + 1);
ret_frm = format_file (panel, file_index, width, attr, FALSE, &fln);
if (panel_is_split && nth_column + 1 < panel->list_cols)
{
tty_setcolor (NORMAL_COLOR);
tty_print_one_vline (TRUE);
}
if (ret_frm != FILENAME_NOSCROLL)
{
if (!panel_is_split && fln > 0)
{
if (panel->list_format != list_long)
width = fln;
else
{
offset = width - fln + 1;
width = fln - 1;
}
}
widget_gotoyx (w, ypos, offset);
tty_setcolor (NORMAL_COLOR);
tty_print_string (panel_filename_scroll_left_char);
if ((ret_frm & FILENAME_SCROLL_RIGHT) != 0)
{
offset += width;
if (nth_column + 1 >= panel->list_cols)
offset++;
widget_gotoyx (w, ypos, offset);
tty_setcolor (NORMAL_COLOR);
tty_print_string (panel_filename_scroll_right_char);
}
}
}
/* --------------------------------------------------------------------------------------------- */
static void
repaint_status (WPanel *panel)
{
int width;
width = WIDGET (panel)->rect.cols - 2;
if (width > 0)
{
int fln = 0;
(void) format_file (panel, panel->current, width, FATTR_STATUS, TRUE, &fln);
}
}
/* --------------------------------------------------------------------------------------------- */
static void
display_mini_info (WPanel *panel)
{
Widget *w = WIDGET (panel);
const file_entry_t *fe;
if (!panels_options.show_mini_info)
return;
widget_gotoyx (w, panel_lines (panel) + 3, 1);
if (panel->quick_search.active)
{
tty_setcolor (INPUT_COLOR);
tty_print_char ('/');
tty_print_string (
str_fit_to_term (panel->quick_search.buffer->str, w->rect.cols - 3, J_LEFT));
return;
}
// Status resolves links and show them
set_colors (panel);
fe = panel_current_entry (panel);
if (fe == NULL)
// NULL is in case of filter that doesn't match anything
repaint_status (panel);
else if (S_ISLNK (fe->st.st_mode))
{
char link_target[MC_MAXPATHLEN];
vfs_path_t *lc_link_vpath;
int len;
lc_link_vpath = vfs_path_append_new (panel->cwd_vpath, fe->fname->str, (char *) NULL);
len = mc_readlink (lc_link_vpath, link_target, MC_MAXPATHLEN - 1);
vfs_path_free (lc_link_vpath, TRUE);
if (len > 0)
{
link_target[len] = 0;
tty_print_string ("-> ");
tty_print_string (str_fit_to_term (link_target, w->rect.cols - 5, J_LEFT_FIT));
}
else
tty_print_string (str_fit_to_term (_ ("<readlink failed>"), w->rect.cols - 2, J_LEFT));
}
else if (DIR_IS_DOTDOT (fe->fname->str))
{
/* FIXME:
* while loading directory (dir_list_load() and dir_list_reload()),
* the actual stat info about ".." directory isn't got;
* so just don't display incorrect info about ".." directory */
tty_print_string (str_fit_to_term (_ ("UP--DIR"), w->rect.cols - 2, J_LEFT));
}
else
// Default behavior
repaint_status (panel);
}
/* --------------------------------------------------------------------------------------------- */
static void
paint_dir (WPanel *panel)
{
int i;
int items; // Number of items
items = panel_items (panel);
// reset max len of filename because we have the new max length for the new file list
panel->max_shift = -1;
for (i = 0; i < items; i++)
{
file_attr_t attr = FATTR_NORMAL; // Color value of the line
int n;
gboolean marked;
n = i + panel->top;
marked = (panel->dir.list[n].f.marked != 0);
if (n < panel->dir.len)
{
if (panel->current == n && panel->active)
attr = marked ? FATTR_MARKED_CURRENT : FATTR_CURRENT;
else if (marked)
attr = FATTR_MARKED;
}
repaint_file (panel, n, attr);
}
tty_set_normal_attrs ();
}
/* --------------------------------------------------------------------------------------------- */
static void
display_total_marked_size (const WPanel *panel, int y, int x, gboolean size_only)
{
const Widget *w = CONST_WIDGET (panel);
char buffer[BUF_SMALL], b_bytes[BUF_SMALL];
const char *buf;
int cols;
if (panel->marked <= 0)