Use raw terminal, and handle signals manually

C-c now sends SIGINT to the process group of Kakoune server
when used in normal mode.

Fixes #30
This commit is contained in:
Maxime Coste 2014-09-20 19:35:37 +01:00
parent 2aaae7473c
commit 217ba625ad
2 changed files with 11 additions and 14 deletions

View File

@ -211,12 +211,9 @@ void on_term_resize(int)
EventManager::instance().force_signal(0);
}
static sig_atomic_t ctrl_c_pending = 0;
void on_sigint(int)
{
ctrl_c_pending = 1;
EventManager::instance().force_signal(0);
// do nothing
}
NCursesUI::NCursesUI()
@ -224,7 +221,7 @@ NCursesUI::NCursesUI()
m_input_callback(); }}
{
initscr();
cbreak();
raw();
noecho();
nonl();
intrflush(stdscr, false);
@ -403,9 +400,6 @@ bool NCursesUI::is_key_available()
{
check_resize();
if (ctrl_c_pending)
return true;
timeout(0);
const int c = getch();
if (c != ERR)
@ -418,17 +412,16 @@ Key NCursesUI::get_key()
{
check_resize();
if (ctrl_c_pending)
{
ctrl_c_pending = false;
return ctrl('c');
}
const int c = getch();
if (c > 0 and c < 27)
{
if (c == CTRL('l'))
redrawwin(stdscr);
if (c == CTRL('z'))
{
raise(SIGTSTP);
return Key::Invalid;
}
return ctrl(Codepoint(c) - 1 + 'a');
}
else if (c == 27)

View File

@ -17,6 +17,8 @@
#include "user_interface.hh"
#include "window.hh"
#include <signal.h>
namespace Kakoune
{
@ -1389,6 +1391,8 @@ KeyMap keymap =
{ Key::PageUp, { "scroll one page up", scroll<Key::PageUp> } },
{ Key::PageDown, { "scroll one page down", scroll<Key::PageDown> } },
{ ctrl('c'), { "interupt", [](Context&, int) { killpg(getpgrp(), SIGINT); } } },
};
}