Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* use MicroConf to parse config file
* make it possible to have vim-like seek keys
(configure hjkl keyboard shortcuts to arrow keys)
- fix terminal settings after crash

wishlist:
- wav output with --wav foo.wav
Expand Down
1 change: 1 addition & 0 deletions src/gst123.cc
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ struct Player : public KeyHandler
{
string uri = uris[play_position++];

cols = get_columns();
overwrite_time_display();

if (is_image_file (uri))
Expand Down
39 changes: 20 additions & 19 deletions src/terminal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
#include <vector>
#include <map>

#ifdef getch
#undef getch
#endif

#include "terminal.h"

using std::vector;
Expand All @@ -40,6 +36,7 @@ using std::map;
static char term_buffer[4096];
static char term_buffer2[4096];
static char *term_p = term_buffer2;
static struct termios tio_orig;
static Terminal *terminal_instance;

static GPollFD stdin_poll_fd = { 0, G_IO_IN, 0 };
Expand All @@ -61,6 +58,17 @@ stdin_check (GSource *source)
return FALSE;
}

static void
reset_terminal ()
{
tcsetattr(0, TCSANOW, &tio_orig);
char *ret = tgetstr ("ke", &term_p);
// disable keypad xmit
if (ret)
printf ("%s", ret);
fflush (stdout);
}

gboolean
Terminal::stdin_dispatch (GSource *source,
GSourceFunc callback,
Expand All @@ -71,7 +79,7 @@ Terminal::stdin_dispatch (GSource *source,
int key;
do
{
key = terminal_instance->getch();
key = terminal_instance->getchar();

if (key > 0)
terminal_instance->key_handler->process_input (key);
Expand All @@ -87,15 +95,6 @@ Terminal::signal_sig_cont (int)
terminal_instance->init_terminal();
}

void
Terminal::print_term (const char *key)
{
char *ret = tgetstr (const_cast<char *> (key), &term_p);

if (ret)
printf ("%s", ret);
}

void
Terminal::init_terminal()
{
Expand All @@ -109,7 +108,10 @@ Terminal::init_terminal()
tcsetattr (0, TCSANOW, &tio_new);

// enable keypad_xmit
print_term ("ks");
char *ret = tgetstr ("ks", &term_p);
// disable keypad xmit
if (ret)
printf ("%s", ret);
fflush (stdout);
}

Expand Down Expand Up @@ -138,6 +140,7 @@ Terminal::init (GMainLoop *loop, KeyHandler *key_handler)

// initialize termios & keypad xmit
init_terminal();
atexit(reset_terminal);

// initialize common keyboard escape sequences
bind_key ("ku", KEY_HANDLER_UP);
Expand All @@ -159,9 +162,7 @@ Terminal::init (GMainLoop *loop, KeyHandler *key_handler)
void
Terminal::end()
{
tcsetattr(0,TCSANOW,&tio_orig);
// disable keypad xmit
print_term("ke");
reset_terminal();
}

void
Expand All @@ -177,7 +178,7 @@ Terminal::read_stdin()
}

int
Terminal::getch()
Terminal::getchar()
{
for (;;)
{
Expand Down
3 changes: 1 addition & 2 deletions src/terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

class Terminal
{
struct termios tio_orig;
std::string terminal_type;
std::vector<int> chars;
std::map<std::string, int> keys;
Expand All @@ -39,7 +38,7 @@ class Terminal
static void signal_sig_cont (int);

void read_stdin();
int getch();
int getchar();
void init_terminal();
void bind_key (const char *key, int handler);
void print_term (const char *key);
Expand Down