Skip to content

Commit

Permalink
Fixed #4 - Terminal not going back to cooked mode after the applicati…
Browse files Browse the repository at this point in the history
…on quits
  • Loading branch information
nathanpc committed Jan 15, 2013
1 parent a6b625d commit e6c1e94
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
6 changes: 3 additions & 3 deletions conio/conio.cpp
Expand Up @@ -9,7 +9,7 @@ using namespace std;
static struct termios old, _new;

/* Initialize _new terminal i/o settings */
void initTermios(int echo) {
void Conio::initTermios(int echo) {
tcgetattr(0, &old); /* grab old terminal i/o settings */
_new = old; /* make _new settings same as old settings */
_new.c_lflag &= ~ICANON; /* disable buffered i/o */
Expand All @@ -18,12 +18,12 @@ void initTermios(int echo) {
}

/* Restore old terminal i/o settings */
void resetTermios() {
void Conio::resetTermios() {
tcsetattr(0, TCSANOW, &old);
}

/* Read 1 character - echo defines echo mode */
char getch_(int echo) {
char Conio::getch_(int echo) {
char ch;
initTermios(echo);
ch = getchar();
Expand Down
5 changes: 5 additions & 0 deletions conio/conio.h
Expand Up @@ -4,7 +4,12 @@
#define CONIO_H_

class Conio {
private:
static char getch_(int echo);
public:
static void resetTermios();
static void initTermios(int echo);

static char getch();
static char getche();
};
Expand Down
7 changes: 7 additions & 0 deletions repl.cpp
Expand Up @@ -21,6 +21,13 @@ REPL::REPL() {
history_current_position = 0;
}

REPL::~REPL() {
clear();
Conio::initTermios(1);
Conio::resetTermios();
system("stty echo cooked");
}

void REPL::add_history() {
if (history.size() >= 100) {
history.erase(history.begin());
Expand Down
2 changes: 1 addition & 1 deletion repl.h
Expand Up @@ -28,7 +28,7 @@ class REPL {

// Constructor.
REPL();
//~REPL();
~REPL();

void clear();
void rewrite();
Expand Down

0 comments on commit e6c1e94

Please sign in to comment.