Compare commits
3 Commits
70e391eed0
...
638d570cbd
Author | SHA1 | Date | |
---|---|---|---|
638d570cbd | |||
ae310d1380 | |||
edf94db8df |
62
sdn.cpp
62
sdn.cpp
@ -297,27 +297,28 @@ static const char *g_ls_colors[] = {LS(XX)};
|
|||||||
#undef XX
|
#undef XX
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
string cwd; // Current working directory
|
string cwd; ///< Current working directory
|
||||||
vector<entry> entries; // Current directory entries
|
string start_dir; ///< Starting directory
|
||||||
int offset, cursor; // Scroll offset and cursor position
|
vector<entry> entries; ///< Current directory entries
|
||||||
bool full_view; // Whether to show extended information
|
int offset, cursor; ///< Scroll offset and cursor position
|
||||||
int max_widths[row::COLUMNS]; // Column widths
|
bool full_view; ///< Show extended information
|
||||||
|
int max_widths[row::COLUMNS]; ///< Column widths
|
||||||
|
|
||||||
string chosen; // Chosen item for the command line
|
string chosen; ///< Chosen item for the command line
|
||||||
bool chosen_full; // Use the full path
|
bool chosen_full; ///< Use the full path
|
||||||
|
|
||||||
int inotify_fd, inotify_wd = -1; // File watch
|
int inotify_fd, inotify_wd = -1; ///< File watch
|
||||||
bool out_of_date; // Entries may be out of date
|
bool out_of_date; ///< Entries may be out of date
|
||||||
|
|
||||||
wchar_t editor; // Prompt character for editing
|
wchar_t editor; ///< Prompt character for editing
|
||||||
wstring editor_line; // Current user input
|
wstring editor_line; ///< Current user input
|
||||||
|
|
||||||
enum { AT_CURSOR, AT_BAR, AT_CWD, AT_INPUT, AT_COUNT };
|
enum { AT_CURSOR, AT_BAR, AT_CWD, AT_INPUT, AT_COUNT };
|
||||||
chtype attrs[AT_COUNT] = {A_REVERSE, 0, A_BOLD, 0};
|
chtype attrs[AT_COUNT] = {A_REVERSE, 0, A_BOLD, 0};
|
||||||
const char *attr_names[AT_COUNT] = {"cursor", "bar", "cwd", "input"};
|
const char *attr_names[AT_COUNT] = {"cursor", "bar", "cwd", "input"};
|
||||||
|
|
||||||
map<int, chtype> ls_colors; // LS_COLORS decoded
|
map<int, chtype> ls_colors; ///< LS_COLORS decoded
|
||||||
map<string, chtype> ls_exts; // LS_COLORS file extensions
|
map<string, chtype> ls_exts; ///< LS_COLORS file extensions
|
||||||
} g;
|
} g;
|
||||||
|
|
||||||
fun ls_format (const string &filename, const struct stat &info) -> chtype {
|
fun ls_format (const string &filename, const struct stat &info) -> chtype {
|
||||||
@ -495,8 +496,9 @@ fun reload () {
|
|||||||
if (g.inotify_wd != -1)
|
if (g.inotify_wd != -1)
|
||||||
inotify_rm_watch (g.inotify_fd, g.inotify_wd);
|
inotify_rm_watch (g.inotify_fd, g.inotify_wd);
|
||||||
|
|
||||||
|
// We don't show atime, so access and open are merely spam
|
||||||
g.inotify_wd = inotify_add_watch (g.inotify_fd, buf,
|
g.inotify_wd = inotify_add_watch (g.inotify_fd, buf,
|
||||||
IN_ALL_EVENTS | IN_ONLYDIR);
|
(IN_ALL_EVENTS | IN_ONLYDIR | IN_EXCL_UNLINK) & ~(IN_ACCESS | IN_OPEN));
|
||||||
}
|
}
|
||||||
|
|
||||||
fun search (const wstring &needle) {
|
fun search (const wstring &needle) {
|
||||||
@ -536,6 +538,16 @@ fun handle_editor (wint_t c, bool is_char) {
|
|||||||
beep ();
|
beep ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun change_dir (const string& path) {
|
||||||
|
if (chdir (path.c_str ())) {
|
||||||
|
beep ();
|
||||||
|
} else {
|
||||||
|
// TODO: remember cursor going down, then restore going up
|
||||||
|
g.cursor = 0;
|
||||||
|
reload ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun choose (const entry &entry) -> bool {
|
fun choose (const entry &entry) -> bool {
|
||||||
bool is_dir = S_ISDIR (entry.info.st_mode) != 0;
|
bool is_dir = S_ISDIR (entry.info.st_mode) != 0;
|
||||||
// Dive into directories and accessible symlinks to them
|
// Dive into directories and accessible symlinks to them
|
||||||
@ -552,13 +564,7 @@ fun choose (const entry &entry) -> bool {
|
|||||||
g.chosen = entry.filename;
|
g.chosen = entry.filename;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (chdir (entry.filename.c_str ())) {
|
change_dir (entry.filename);
|
||||||
beep ();
|
|
||||||
} else {
|
|
||||||
// TODO: remember cursor going down, then restore going up
|
|
||||||
g.cursor = 0;
|
|
||||||
reload ();
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -616,6 +622,16 @@ fun handle (wint_t c, bool is_char) -> bool {
|
|||||||
case CTRL L'e': g.offset++; break;
|
case CTRL L'e': g.offset++; break;
|
||||||
case CTRL L'y': g.offset--; break;
|
case CTRL L'y': g.offset--; break;
|
||||||
|
|
||||||
|
case '&':
|
||||||
|
change_dir (g.start_dir);
|
||||||
|
break;
|
||||||
|
case '~':
|
||||||
|
if (const auto *home = getenv ("HOME"))
|
||||||
|
change_dir (home);
|
||||||
|
else if (const auto *pw = getpwuid (getuid ()))
|
||||||
|
change_dir (pw->pw_dir);
|
||||||
|
break;
|
||||||
|
|
||||||
case L't':
|
case L't':
|
||||||
case ALT | L't':
|
case ALT | L't':
|
||||||
g.full_view = !g.full_view;
|
g.full_view = !g.full_view;
|
||||||
@ -794,8 +810,8 @@ int main (int argc, char *argv[]) {
|
|||||||
|
|
||||||
load_configuration ();
|
load_configuration ();
|
||||||
reload ();
|
reload ();
|
||||||
|
g.start_dir = g.cwd;
|
||||||
update ();
|
update ();
|
||||||
auto start_dir = g.cwd;
|
|
||||||
|
|
||||||
wint_t c;
|
wint_t c;
|
||||||
while (1) {
|
while (1) {
|
||||||
@ -818,7 +834,7 @@ int main (int argc, char *argv[]) {
|
|||||||
cout << "local insert=" << shell_escape (full_path) << endl;
|
cout << "local insert=" << shell_escape (full_path) << endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (g.cwd != start_dir)
|
if (g.cwd != g.start_dir)
|
||||||
cout << "local cd=" << shell_escape (g.cwd) << endl;
|
cout << "local cd=" << shell_escape (g.cwd) << endl;
|
||||||
if (!g.chosen.empty ())
|
if (!g.chosen.empty ())
|
||||||
cout << "local insert=" << shell_escape (g.chosen) << endl;
|
cout << "local insert=" << shell_escape (g.chosen) << endl;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user