summaryrefslogtreecommitdiff
path: root/sdn.cpp
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2020-10-01 11:54:01 +0200
committerPřemysl Eric Janouch <p@janouch.name>2020-10-01 11:58:32 +0200
commitb8c767354ec847e1415550b8002430c71e99ed47 (patch)
treed90cce80028436a29bb87b55c2cf9157381c7c68 /sdn.cpp
parentc07f557c1613c7b962c51206415db911090bdd0d (diff)
downloadsdn-b8c767354ec847e1415550b8002430c71e99ed47.tar.gz
sdn-b8c767354ec847e1415550b8002430c71e99ed47.tar.xz
sdn-b8c767354ec847e1415550b8002430c71e99ed47.zip
Show external command line if appropriate
Since I'm already dealing with the fish shell. All of our supported shells seem to handle cursor position in Unicode (wide character) codepoints. It was easiest and most straight-forward to pass the data through yet-unused program arguments. The cursor position is marked by a Unicode glyph equivalent to ACS_DIAMOND, although ncurses doesn't get a chance to make any ACS translation.
Diffstat (limited to 'sdn.cpp')
-rw-r--r--sdn.cpp27
1 files changed, 21 insertions, 6 deletions
diff --git a/sdn.cpp b/sdn.cpp
index f3af9bf..38475d4 100644
--- a/sdn.cpp
+++ b/sdn.cpp
@@ -495,6 +495,7 @@ struct level {
};
static struct {
+ wstring cmdline; ///< Outer command line
string cwd; ///< Current working directory
string start_dir; ///< Starting directory
vector<entry> entries; ///< Current directory entries
@@ -525,9 +526,10 @@ static struct {
void (*editor_on_change) (); ///< Callback on editor change
void (*editor_on_confirm) (); ///< Callback on editor confirmation
- 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"};
+ enum { AT_CURSOR, AT_BAR, AT_CWD, AT_INPUT, AT_CMDLINE, AT_COUNT };
+ chtype attrs[AT_COUNT] = {A_REVERSE, 0, A_BOLD, 0, 0};
+ const char *attr_names[AT_COUNT] =
+ {"cursor", "bar", "cwd", "input", "cmdline"};
map<int, chtype> ls_colors; ///< LS_COLORS decoded
map<string, chtype> ls_exts; ///< LS_COLORS file extensions
@@ -746,6 +748,9 @@ fun update () {
} else if (!g.message.empty ()) {
move (LINES - 1, 0);
print (apply_attrs (g.message, 0), COLS);
+ } else if (!g.cmdline.empty ()) {
+ move (LINES - 1, 0);
+ print (apply_attrs (g.cmdline, g.attrs[g.AT_CMDLINE]), COLS);
}
refresh ();
@@ -1352,6 +1357,18 @@ fun inotify_check () {
update ();
}
+fun load_cmdline (int argc, char *argv[]) {
+ if (argc < 3)
+ return;
+
+ wstring line = to_wide (argv[1]); int point = atoi (argv[2]);
+ if (line.empty () || point < 0 || point > (int) line.length ())
+ return;
+
+ std::replace_if (line.begin (), line.end (), iswspace, L' ');
+ g.cmdline = line.substr (0, point) + L"◆" + line.substr (point);
+}
+
fun decode_ansi_sgr (const vector<string> &v) -> chtype {
vector<int> args;
for (const auto &arg : v) {
@@ -1627,9 +1644,6 @@ fun save_config () {
}
int main (int argc, char *argv[]) {
- (void) argc;
- (void) argv;
-
// That bitch zle closes stdin before exec without redirection
(void) close (STDIN_FILENO);
if (open ("/dev/tty", O_RDWR)) {
@@ -1658,6 +1672,7 @@ int main (int argc, char *argv[]) {
return 1;
}
+ load_cmdline (argc, argv);
load_colors ();
g.start_dir = g.cwd = initial_cwd ();
reload (false);