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