aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/boxes.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--boxes.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/boxes.c b/boxes.c
index 42446f3..8f9f19a 100644
--- a/boxes.c
+++ b/boxes.c
@@ -658,7 +658,6 @@ static box *rootBox; // Parent of the rest of the boxes, or the only box. Alway
658static box *currentBox; 658static box *currentBox;
659static view *commandLine; 659static view *commandLine;
660static int commandMode; 660static int commandMode;
661static volatile sig_atomic_t sigWinch;
662 661
663#define MEM_SIZE 128 // Chunk size for line memory allocation. 662#define MEM_SIZE 128 // Chunk size for line memory allocation.
664 663
@@ -1858,6 +1857,14 @@ static int handleKeySequence(long extra, char *sequence)
1858 return 0; 1857 return 0;
1859} 1858}
1860 1859
1860
1861static volatile sig_atomic_t sigWinch;
1862
1863static void handleSignals(int signo)
1864{
1865 sigWinch = 1;
1866}
1867
1861// Basically this is the main loop. 1868// Basically this is the main loop.
1862 1869
1863// TODO - Unhandled complications - 1870// TODO - Unhandled complications -
@@ -1867,12 +1874,19 @@ void handle_keys(long extra, int (*handle_sequence)(long extra, char *sequence))
1867{ 1874{
1868 fd_set selectFds; 1875 fd_set selectFds;
1869 struct timespec timeout; 1876 struct timespec timeout;
1877 struct sigaction sigAction, oldSigAction;
1870 sigset_t signalMask; 1878 sigset_t signalMask;
1871 char buffer[20], sequence[20]; 1879 char buffer[20], sequence[20];
1872 int buffIndex = 0; 1880 int buffIndex = 0;
1873 1881
1874 buffer[0] = 0; 1882 buffer[0] = 0;
1875 sequence[0] = 0; 1883 sequence[0] = 0;
1884
1885 // Terminals send the SIGWINCH signal when they resize.
1886 memset(&sigAction, 0, sizeof(sigAction));
1887 sigAction.sa_handler = handleSignals;
1888 sigAction.sa_flags = SA_RESTART;// Useless if we are using poll.
1889 if (sigaction(SIGWINCH, &sigAction, &oldSigAction)) perror_exit("can't set signal handler SIGWINCH");
1876 sigemptyset(&signalMask); 1890 sigemptyset(&signalMask);
1877 sigaddset(&signalMask, SIGWINCH); 1891 sigaddset(&signalMask, SIGWINCH);
1878 1892
@@ -2079,6 +2093,8 @@ TODO So abort the current CSI and start from scratch.
2079 } 2093 }
2080 } 2094 }
2081 } 2095 }
2096
2097 sigaction(SIGWINCH, &oldSigAction, NULL);
2082} 2098}
2083 2099
2084 2100
@@ -2718,18 +2734,12 @@ struct context simpleVi =
2718// TODO - have any unrecognised escape key sequence start up a new box (split one) to show the "show keys" content. 2734// TODO - have any unrecognised escape key sequence start up a new box (split one) to show the "show keys" content.
2719// That just adds each "Key is X" to the end of the content, and allows scrolling, as well as switching between other boxes. 2735// That just adds each "Key is X" to the end of the content, and allows scrolling, as well as switching between other boxes.
2720 2736
2721static void handleSignals(int signo)
2722{
2723 sigWinch = 1;
2724}
2725
2726void boxes_main(void) 2737void boxes_main(void)
2727{ 2738{
2728 struct context *context = &simpleMcedit; // The default is mcedit, coz that's what I use. 2739 struct context *context = &simpleMcedit; // The default is mcedit, coz that's what I use.
2729 struct termios termio, oldtermio; 2740 struct termios termio, oldtermio;
2730 char *prompt = "Enter a command : "; 2741 char *prompt = "Enter a command : ";
2731 unsigned W = 80, H = 24; 2742 unsigned W = 80, H = 24;
2732 struct sigaction sigAction, oldSigActions;
2733 2743
2734 // For testing purposes, figure out which context we use. When this gets real, the toybox multiplexer will sort this out for us instead. 2744 // For testing purposes, figure out which context we use. When this gets real, the toybox multiplexer will sort this out for us instead.
2735 if (toys.optflags & FLAG_m) 2745 if (toys.optflags & FLAG_m)
@@ -2810,11 +2820,6 @@ void boxes_main(void)
2810 termio.c_cc[VMIN]=1; 2820 termio.c_cc[VMIN]=1;
2811 tcsetattr(0, TCSANOW, &termio); 2821 tcsetattr(0, TCSANOW, &termio);
2812 2822
2813 // Terminals send the SIGWINCH signal when they resize.
2814 memset(&sigAction, 0, sizeof(sigAction));
2815 sigAction.sa_handler = handleSignals;
2816 sigAction.sa_flags = SA_RESTART;// Useless if we are using poll.
2817 if (sigaction(SIGWINCH, &sigAction, &oldSigActions)) perror_exit("can't set signal handler SIGWINCH");
2818 terminal_size(&W, &H); 2823 terminal_size(&W, &H);
2819 if (toys.optflags & FLAG_w) 2824 if (toys.optflags & FLAG_w)
2820 W = TT.w; 2825 W = TT.w;
@@ -2859,8 +2864,6 @@ void boxes_main(void)
2859 2864
2860 // TODO - Should remember to turn off mouse reporting when we leave. 2865 // TODO - Should remember to turn off mouse reporting when we leave.
2861 2866
2862 sigaction(SIGWINCH, &oldSigActions, NULL);
2863
2864 // Restore the old terminal settings. 2867 // Restore the old terminal settings.
2865 tcsetattr(0, TCSANOW, &oldtermio); 2868 tcsetattr(0, TCSANOW, &oldtermio);
2866 2869