чување eef7414de7638b48508da88a475ea36fe4a2cc4a
родитељ 6ba12cea7033497093a266924393ea10f124124a
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Tue, 21 Jun 2022 15:53:17 +0200
Add suspend (C-Z) support
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
измењених датотека: 5, додавања: 38(+), брисања: 3(-)
diff --git a/TODO b/TODO
@@ -1,7 +1,7 @@
TODO
====
- [ ] Allow C-Z to suspend
+ [x] Allow C-Z to suspend
[ ] Replace (patch)
diff --git a/config.def.h b/config.def.h
@@ -97,6 +97,7 @@ int toggle_overwrite(struct DrawState* state);
int toggle_selection(struct DrawState* state);
int write_file(struct DrawState* state);
int yank_to_paste(struct DrawState* state);
+int suspend_program(struct DrawState* state);
/* clang-format off */
@@ -104,7 +105,9 @@ int yank_to_paste(struct DrawState* state);
static const struct Key top_level_keys[] = {
{ .ev = { .key = TB_KEY_ESC }, .callback = cancel_close },
{ .ev = { .key = TB_KEY_CTRL_Q },
- .callback = exit_program }
+ .callback = exit_program },
+ { .ev = { .key = TB_KEY_CTRL_Z },
+ .callback = suspend_program }
};
/* Only when no dialog/prompt open */
diff --git a/config.h b/config.h
@@ -97,6 +97,7 @@ int toggle_overwrite(struct DrawState* state);
int toggle_selection(struct DrawState* state);
int write_file(struct DrawState* state);
int yank_to_paste(struct DrawState* state);
+int suspend_program(struct DrawState* state);
/* clang-format off */
@@ -104,7 +105,9 @@ int yank_to_paste(struct DrawState* state);
static const struct Key top_level_keys[] = {
{ .ev = { .key = TB_KEY_ESC }, .callback = cancel_close },
{ .ev = { .key = TB_KEY_CTRL_Q },
- .callback = exit_program }
+ .callback = exit_program },
+ { .ev = { .key = TB_KEY_CTRL_Z },
+ .callback = suspend_program }
};
/* Only when no dialog/prompt open */
diff --git a/sled.1.in b/sled.1.in
@@ -116,6 +116,7 @@ _
\fCC-V\fP@Paste from paste buffer
\fCC-X\fP@Cut to paste buffer
\fCC-Y\fP@Erase the entire current line
+\fCC-Z\fP@Suspend
\fCC-W\fP@Erase previous word
.TE
.
diff --git a/sled.c b/sled.c
@@ -6,11 +6,13 @@
#include <errno.h>
#include <fcntl.h>
+#include <signal.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#define TB_OPT_V1_COMPAT
#define TB_IMPL
@@ -1886,6 +1888,32 @@ simple_yank(struct DrawState* state)
}
int
+suspend_program(struct DrawState* state)
+{
+ tb_set_clear_attrs(TB_WHITE, TB_DEFAULT);
+ tb_clear();
+ tb_set_cursor(0, 0);
+ tb_present();
+
+ kill(getpid(), SIGTSTP);
+
+ /* --- back from suspend --- */
+
+ /* tb_clear() won't cut it unfortunately */
+ for (int y = 0; y < state->maxy; y++)
+ for (int x = 0; x < state->maxx; x++)
+ tb_set_cell(x, y, '.', TB_WHITE, TB_DEFAULT);
+ tb_present();
+ for (int y = 0; y < state->maxy; y++)
+ for (int x = 0; x < state->maxx; x++)
+ tb_set_cell(x, y, ' ', TB_WHITE, TB_DEFAULT);
+
+ draw(state);
+ tb_present();
+ return 0;
+}
+
+int
toggle_overwrite(struct DrawState* state)
{
TOGGLE(state->mode, M_OVERWRITE);