📄 screen.c
字号:
/* Panel managing.
Copyright (C) 1994, 1995 Miguel de Icaza.
This program 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 2 of the License, or
(at your option) any later version.
This program 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.
Written by: 1995 Miguel de Icaza
1997 Timur Bakeyev
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <config.h>
#include "tty.h"
#include "fs.h"
#include <sys/param.h>
#include <string.h>
#include <stdlib.h> /* For malloc() and free() */
#include <stdio.h>
#include <errno.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h> /* For chdir(), readlink() and getwd()/getcwd() */
#endif
#include "mem.h"
#include "mad.h"
#include "global.h"
#include "dir.h"
#include "util.h"
#include "panel.h"
#include "color.h"
#include "tree.h"
#include "win.h"
#include "main.h"
#include "ext.h" /* regexp_command */
#include "mouse.h" /* For Gpm_Event */
#include "cons.saver.h" /* For console_flag */
#include "layout.h" /* Most layout variables are here */
#include "dialog.h" /* for message (...) */
#include "cmd.h"
#include "key.h" /* XCTRL and ALT macros */
#include "setup.h" /* For loading/saving panel options */
#include "user.h"
#include "profile.h"
#include "widget.h"
#include "../vfs/vfs.h"
#include "../vfs/extfs.h"
#if defined(OS2_NT)
# include "drive.h"
#endif
#include "x.h"
/* "$Id: screen.c 15091 2005-05-07 21:24:31Z sedwards $" */
#define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
/* If true, show the mini-info on the panel */
int show_mini_info = 1;
/* If true, then use stat() on the cwd to determine directory changes */
int fast_reload = 0;
/* If true, use some usability hacks by Torben */
int torben_fj_mode = 0;
/* If true, up/down keys scroll the pane listing by pages */
int panel_scroll_pages = 1;
/* If 1, we use permission hilighting */
int permission_mode = 0;
/* If 1 - then add per file type hilighting */
int filetype_mode = 1;
/* This gives abilitiy to determine colored user priveleges */
extern user_in_groups *current_user_gid;
extern uid_t current_user_uid;
/* If we have an info panel, this points to it */
WPanel *the_info_panel = 0;
/* The hook list for the select file function */
Hook *select_file_hook = 0;
static int panel_callback (Dlg_head *h, WPanel *p, int Msg, int Par);
int panel_event (Gpm_Event *event, WPanel *panel);
#ifndef PORT_HAS_PANEL_ADJUST_TOP_FILE
# define x_adjust_top_file(p)
#endif
#ifndef PORT_HAS_PANEL_RESET_SORT_LABELS
# define x_reset_sort_labels(x)
#endif
/* This macro extracts the number of available lines in a panel */
#ifndef PORT_HAS_LLINES
#define llines(p) (p->widget.lines-3 - (show_mini_info ? 2 : 0))
#else
#define llines(p) (p->widget.lines)
#endif
#ifdef PORT_NOT_FOCUS_SELECT_ITEM
# define focus_select_item(x)
#else
# define focus_select_item(x) select_item(x)
#endif
#ifdef PORT_NOT_UNFOCUS_UNSELECT_ITEM
# define unfocus_unselect_item(x)
#else
# define unfocus_unselect_item(x) unselect_item(x)
#endif
#ifdef HAVE_X
# define set_colors(x)
#else
# define x_create_panel(x,y,z) 1;
# define x_panel_load_index(p,x)
# define x_panel_select_item(a,b,c)
# define x_panel_destroy(p)
void
set_colors (WPanel *panel)
{
standend ();
if (hascolors)
attrset (NORMAL_COLOR);
}
#endif
#ifndef ICONS_PER_ROW
# define ICONS_PER_ROW(x) 1
#endif
/* Delete format string, it is a linked list */
void
delete_format (format_e *format)
{
format_e *next;
while (format){
next = format->next;
free (format);
format = next;
}
}
/* This code relies on the default justification!!! */
void
add_permission_string (char *dest, int width, file_entry *fe, int attr, int color, int is_octal)
{
int i, r, l;
l = get_user_rights (&fe->buf);
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 == SELECTED || attr == MARKED_SELECTED)
attrset (MARKED_SELECTED_COLOR);
else
attrset (MARKED_COLOR);
} else
attrset (color);
addch (dest[i]);
}
}
int
file_entry_color (file_entry *fe)
{
if (filetype_mode){
if (S_ISDIR (fe->buf.st_mode))
return (DIRECTORY_COLOR);
else if (S_ISLNK (fe->buf.st_mode)) {
if (fe->f.link_to_dir)
return (DIRECTORY_COLOR);
else if (fe->f.stalled_link)
return (STALLED_COLOR);
else
return (LINK_COLOR);
} else if (S_ISSOCK (fe->buf.st_mode))
return (SPECIAL_COLOR);
else if (S_ISCHR (fe->buf.st_mode))
return (DEVICE_COLOR);
else if (S_ISBLK (fe->buf.st_mode))
return (DEVICE_COLOR);
else if (S_ISFIFO (fe->buf.st_mode))
return (SPECIAL_COLOR);
else if (is_exe (fe->buf.st_mode))
return (EXECUTABLE_COLOR);
else if (fe->fname && (strcmp (fe->fname, "core") == 0))
return (CORE_COLOR);
}
return (NORMAL_COLOR);
}
/* This functions return a string representation of a file entry */
char *
string_file_type (file_entry *fe, int len)
{
static char buffer [2];
if (S_ISDIR (fe->buf.st_mode))
buffer [0] = PATH_SEP;
else if (S_ISLNK (fe->buf.st_mode)) {
if (fe->f.link_to_dir)
buffer [0] = '~';
else if (fe->f.stalled_link)
buffer [0] = '!';
else
buffer [0] = '@';
} else if (S_ISSOCK (fe->buf.st_mode))
buffer [0] = '=';
else if (S_ISCHR (fe->buf.st_mode))
buffer [0] = '-';
else if (S_ISBLK (fe->buf.st_mode))
buffer [0] = '+';
else if (S_ISFIFO (fe->buf.st_mode))
buffer [0] = '|';
else if (is_exe (fe->buf.st_mode))
buffer [0] = '*';
else
buffer [0] = ' ';
buffer [1] = 0;
return buffer;
}
char *
string_file_size_brief (file_entry *fe, int len)
{
static char buffer [8];
if (S_ISDIR (fe->buf.st_mode)){
strcpy (buffer, (strcmp (fe->fname, "..") ? "SUB-DIR" : "UP--DIR"));
return buffer;
}
return string_file_size (fe, len);
}
char *
string_file_permission (file_entry *fe, int len)
{
return string_perm (fe->buf.st_mode);
}
char *
string_file_nlinks (file_entry *fe, int len)
{
static char buffer [20];
sprintf (buffer, "%16d", fe->buf.st_nlink);
return buffer;
}
char *
string_file_owner (file_entry *fe, int len)
{
return get_owner (fe->buf.st_uid);
}
char *
string_file_group (file_entry *fe, int len)
{
return get_group (fe->buf.st_gid);
}
char *
string_file_size (file_entry *fe, int len)
{
static char buffer [16];
int i;
#ifdef HAVE_ST_RDEV
if (S_ISBLK (fe->buf.st_mode) || S_ISCHR (fe->buf.st_mode))
sprintf (buffer, "%3d,%3d", (int) (fe->buf.st_rdev >> 8),
(int) (fe->buf.st_rdev & 0xff));
else
#endif
{
sprintf (buffer, "%lu", (unsigned long) fe->buf.st_size);
if (len && (i = strlen (buffer)) > len) {
if (i - 2 > len) {
if (i - 5 > len)
sprintf (buffer, "%luG", (unsigned long) ((fe->buf.st_size) >> 30));
else
sprintf (buffer, "%luM", (unsigned long) ((fe->buf.st_size) >> 20));
} else
sprintf (buffer, "%luK", (unsigned long) ((fe->buf.st_size) >> 10));
}
}
return buffer;
}
char *
string_file_mtime (file_entry *fe, int len)
{
return file_date (fe->buf.st_mtime);
}
char *
string_file_atime (file_entry *fe, int len)
{
return file_date (fe->buf.st_atime);
}
char *
string_file_ctime (file_entry *fe, int len)
{
return file_date (fe->buf.st_ctime);
}
#ifdef HAVE_GNOME
/* In GNOME, the CList truncates the names */
char *
string_file_name (file_entry *fe, int len)
{
return fe->fname;
}
#else
char *
string_file_name (file_entry *fe, int len)
{
if (len)
return name_trunc (fe->fname, len);
else
return fe->fname;
}
#endif
char *
string_space (file_entry *fe, int len)
{
return " ";
}
char *
string_dot (file_entry *fe, int len)
{
return ".";
}
char *
string_marked (file_entry *fe, int len)
{
return fe->f.marked ? "*" : " ";
}
char *
string_file_perm_octal (file_entry *fe, int len)
{
static char buffer [9];
sprintf (buffer, "0%06o", fe->buf.st_mode);
return buffer;
}
char *
string_inode (file_entry *fe, int len)
{
static char buffer [9];
sprintf (buffer, "%ld", (long) fe->buf.st_ino);
return buffer;
}
char *
string_file_ngid (file_entry *fe, int len)
{
static char buffer [9];
sprintf (buffer, "%d", fe->buf.st_gid);
return buffer;
}
char *
string_file_nuid (file_entry *fe, int len)
{
static char buffer [9];
sprintf (buffer, "%d", fe->buf.st_uid);
return buffer;
}
#ifdef HAVE_GNOME
# define GT 2
#else
# define GT 1
#endif
static struct {
char *id;
int min_size;
int expands;
int default_just;
char *title;
int use_in_gui;
char *(*string_fn)(file_entry *, int);
sortfn *sort_routine;
} formats [] = {
{ "name", 12, 1, J_LEFT, N_("Name"), 1, string_file_name, (sortfn *) sort_name },
{ "size", 7, 0, J_RIGHT, N_("Size"), 1, string_file_size, (sortfn *) sort_size },
{ "type", GT, 0, J_LEFT, "", 1, string_file_type, (sortfn *) sort_type },
{ "mtime", 12, 0, J_RIGHT, N_("MTime"), 1, string_file_mtime, (sortfn *) sort_time },
{ "bsize", 7, 0, J_RIGHT, N_("Size"), 1, string_file_size_brief, (sortfn *) sort_size },
{ "perm", 10, 0, J_LEFT, N_("Permission"), 1, string_file_permission, NULL },
{ "mode", 6, 0, J_RIGHT, N_("Perm"), 1, string_file_perm_octal, NULL },
{ "|", 1, 0, J_RIGHT, N_("|"), 0, 0, NULL },
{ "nlink", 2, 0, J_RIGHT, N_("Nl"), 1, string_file_nlinks, (sortfn *) sort_links },
{ "ngid", 5, 0, J_RIGHT, N_("GID"), 1, string_file_ngid, (sortfn *) sort_ngid },
{ "nuid", 5, 0, J_RIGHT, N_("UID"), 1, string_file_nuid, (sortfn *) sort_nuid },
{ "owner", 8, 0, J_LEFT, N_("Owner"), 1, string_file_owner, (sortfn *) sort_owner },
{ "group", 8, 0, J_LEFT, N_("Group"), 1, string_file_group, (sortfn *) sort_group },
{ "atime", 12, 0, J_RIGHT, N_("ATime"), 1, string_file_atime, (sortfn *) sort_atime },
{ "ctime", 12, 0, J_RIGHT, N_("CTime"), 1, string_file_ctime, (sortfn *) sort_ctime },
{ "space", 1, 0, J_RIGHT, " ", 0, string_space, NULL },
{ "dot", 1, 0, J_RIGHT, " ", 0, string_dot, NULL },
{ "mark", 1, 0, J_RIGHT, " ", 1, string_marked, NULL },
{ "inode", 5, 0, J_RIGHT, N_("Inode"), 1, string_inode, (sortfn *) sort_inode },
};
static char *
to_buffer (char *dest, int just_mode, int len, char *txt)
{
int txtlen = strlen (txt);
int still;
if (txtlen > len){
if (just_mode != J_LEFT)
txt += txtlen - len;
txtlen = len;
}
still = len - txtlen;
if (just_mode == J_LEFT){
strcpy (dest, txt);
dest += txtlen;
while (still--)
*dest++ = ' ';
*dest = 0;
} else {
while (still--)
*dest++ = ' ';
strcpy (dest, txt);
dest += txtlen;
}
return dest;
}
int
file_compute_color (int attr, file_entry *fe)
{
int color;
switch (attr){
case SELECTED:
color = SELECTED_COLOR;
break;
case MARKED:
color = MARKED_COLOR;
break;
case MARKED_SELECTED:
color = MARKED_SELECTED_COLOR;
break;
case STATUS:
color = NORMAL_COLOR;
break;
case NORMAL:
default:
color = file_entry_color(fe);
}
return color;
}
/* Formats the file number file_index of panel in the buffer dest */
void
format_file (char *dest, WPanel *panel, int file_index, int width, int attr, int isstatus)
{
int color, length, empty_line;
char *txt;
char *old_pos;
char *cdest = dest;
format_e *format, *home;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -