mirror of
https://github.com/irssi/irssi.git
synced 2025-02-02 15:08:01 -05:00
Since I accidentally already committed some of the detach-code, here's the
rest of it. It doesn't really work, you can make irssi detached but you can't attach to it anymore :) git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2268 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
ba09b3f299
commit
e46446e950
@ -30,7 +30,6 @@
|
||||
#include "translation.h"
|
||||
|
||||
#include "term.h"
|
||||
#include "detach.h"
|
||||
#include "gui-entry.h"
|
||||
#include "gui-windows.h"
|
||||
|
||||
@ -366,8 +365,6 @@ static void sig_input(void)
|
||||
/* lost terminal */
|
||||
if (!term_detached)
|
||||
signal_emit("command quit", 1, "Lost terminal");
|
||||
else
|
||||
irssi_detach();
|
||||
} else {
|
||||
for (i = 0; i < ret; i++)
|
||||
handle_key(buffer[i]);
|
||||
|
@ -3,6 +3,9 @@
|
||||
|
||||
extern char *cutbuffer;
|
||||
|
||||
void input_listen_init(int handle);
|
||||
void input_listen_deinit(void);
|
||||
|
||||
void readline(void);
|
||||
time_t get_idle_time(void);
|
||||
|
||||
|
@ -309,6 +309,7 @@ int main(int argc, char **argv)
|
||||
core_init_paths(argc, argv);
|
||||
|
||||
check_files();
|
||||
|
||||
#ifdef WIN32
|
||||
winsock_init();
|
||||
#endif
|
||||
|
@ -35,13 +35,16 @@ struct _TERM_WINDOW {
|
||||
};
|
||||
|
||||
TERM_WINDOW *root_window;
|
||||
int term_width, term_height;
|
||||
char *term_lines_empty; /* 1 if line is entirely empty */
|
||||
int term_width, term_height, term_detached;
|
||||
|
||||
static char *term_lines_empty; /* 1 if line is entirely empty */
|
||||
static int vcmove, vcx, vcy, curs_visible;
|
||||
static int crealx, crealy, cforcemove;
|
||||
static int curs_x, curs_y;
|
||||
static int auto_detach;
|
||||
|
||||
static int last_fg, last_bg, last_attrs;
|
||||
|
||||
static int redraw_needed, redraw_tag;
|
||||
static int freeze_counter;
|
||||
|
||||
@ -87,6 +90,7 @@ int term_init(void)
|
||||
term_width = current_term->width;
|
||||
term_height = current_term->height;
|
||||
root_window = term_window_create(0, 0, term_width, term_height);
|
||||
term_detached = FALSE;
|
||||
|
||||
term_lines_empty = g_new0(char, term_height);
|
||||
|
||||
@ -104,6 +108,8 @@ void term_deinit(void)
|
||||
|
||||
static void term_move_real(void)
|
||||
{
|
||||
if (term_detached) return;
|
||||
|
||||
if (vcx != crealx || vcy != crealy || cforcemove) {
|
||||
if (curs_visible) {
|
||||
terminfo_set_cursor_visible(FALSE);
|
||||
@ -167,12 +173,16 @@ int term_has_colors(void)
|
||||
/* Force the colors on any way you can */
|
||||
void term_force_colors(int set)
|
||||
{
|
||||
if (term_detached) return;
|
||||
|
||||
terminfo_setup_colors(current_term, set);
|
||||
}
|
||||
|
||||
/* Clear screen */
|
||||
void term_clear(void)
|
||||
{
|
||||
if (term_detached) return;
|
||||
|
||||
term_set_color(root_window, 0);
|
||||
terminfo_clear();
|
||||
term_move_reset(0, 0);
|
||||
@ -183,6 +193,8 @@ void term_clear(void)
|
||||
/* Beep */
|
||||
void term_beep(void)
|
||||
{
|
||||
if (term_detached) return;
|
||||
|
||||
terminfo_beep(current_term);
|
||||
}
|
||||
|
||||
@ -219,6 +231,8 @@ void term_window_clear(TERM_WINDOW *window)
|
||||
{
|
||||
int y;
|
||||
|
||||
if (term_detached) return;
|
||||
|
||||
terminfo_set_normal();
|
||||
if (window->y == 0 && window->height == term_height) {
|
||||
term_clear();
|
||||
@ -235,6 +249,8 @@ void term_window_scroll(TERM_WINDOW *window, int count)
|
||||
{
|
||||
int y;
|
||||
|
||||
if (term_detached) return;
|
||||
|
||||
terminfo_scroll(window->y, window->y+window->height-1, count);
|
||||
term_move_reset(vcx, vcy);
|
||||
|
||||
@ -248,6 +264,8 @@ void term_set_color(TERM_WINDOW *window, int col)
|
||||
{
|
||||
int set_normal;
|
||||
|
||||
if (term_detached) return;
|
||||
|
||||
set_normal = ((col & ATTR_RESETFG) && last_fg != -1) ||
|
||||
((col & ATTR_RESETBG) && last_bg != -1);
|
||||
if (((last_attrs & ATTR_BOLD) && (col & ATTR_BOLD) == 0) ||
|
||||
@ -343,6 +361,8 @@ static void term_printed_text(int count)
|
||||
|
||||
void term_addch(TERM_WINDOW *window, int chr)
|
||||
{
|
||||
if (term_detached) return;
|
||||
|
||||
if (vcmove) term_move_real();
|
||||
term_printed_text(1);
|
||||
if (vcy != term_height || vcx != 0)
|
||||
@ -353,6 +373,8 @@ void term_addstr(TERM_WINDOW *window, const char *str)
|
||||
{
|
||||
int len;
|
||||
|
||||
if (term_detached) return;
|
||||
|
||||
if (vcmove) term_move_real();
|
||||
len = strlen(str);
|
||||
term_printed_text(len);
|
||||
@ -365,6 +387,8 @@ void term_addstr(TERM_WINDOW *window, const char *str)
|
||||
|
||||
void term_clrtoeol(TERM_WINDOW *window)
|
||||
{
|
||||
if (term_detached) return;
|
||||
|
||||
/* clrtoeol() doesn't necessarily understand colors */
|
||||
if (last_fg == -1 && last_bg == -1 &&
|
||||
(last_attrs & (ATTR_UNDERLINE|ATTR_REVERSE)) == 0) {
|
||||
@ -390,7 +414,7 @@ void term_move_cursor(int x, int y)
|
||||
|
||||
void term_refresh(TERM_WINDOW *window)
|
||||
{
|
||||
if (freeze_counter > 0)
|
||||
if (term_detached || freeze_counter > 0)
|
||||
return;
|
||||
|
||||
term_move(root_window, curs_x, curs_y);
|
||||
@ -407,7 +431,8 @@ void term_refresh(TERM_WINDOW *window)
|
||||
void term_refresh_freeze(void)
|
||||
{
|
||||
freeze_counter++;
|
||||
if (curs_visible) {
|
||||
|
||||
if (!term_detached && curs_visible) {
|
||||
terminfo_set_cursor_visible(FALSE);
|
||||
curs_visible = FALSE;
|
||||
}
|
||||
@ -419,23 +444,60 @@ void term_refresh_thaw(void)
|
||||
term_refresh(NULL);
|
||||
}
|
||||
|
||||
void term_stop(void)
|
||||
void term_auto_detach(int set)
|
||||
{
|
||||
terminfo_stop(current_term);
|
||||
kill(getpid(), SIGSTOP);
|
||||
auto_detach = set;
|
||||
}
|
||||
|
||||
void term_detach(void)
|
||||
{
|
||||
terminfo_stop(current_term);
|
||||
|
||||
fclose(current_term->in);
|
||||
fclose(current_term->out);
|
||||
|
||||
current_term->in = NULL;
|
||||
current_term->out = NULL;
|
||||
term_detached = TRUE;
|
||||
}
|
||||
|
||||
void term_attach(FILE *in, FILE *out)
|
||||
{
|
||||
current_term->in = in;
|
||||
current_term->out = out;
|
||||
term_detached = FALSE;
|
||||
|
||||
terminfo_cont(current_term);
|
||||
irssi_redraw();
|
||||
}
|
||||
|
||||
void term_stop(void)
|
||||
{
|
||||
if (term_detached) {
|
||||
kill(getpid(), SIGSTOP);
|
||||
} else {
|
||||
terminfo_stop(current_term);
|
||||
kill(getpid(), SIGSTOP);
|
||||
terminfo_cont(current_term);
|
||||
irssi_redraw();
|
||||
}
|
||||
}
|
||||
|
||||
int term_gets(unsigned char *buffer, int size)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (term_detached)
|
||||
return 0;
|
||||
|
||||
/* fread() doesn't work */
|
||||
ret = read(fileno(current_term->in), buffer, size);
|
||||
if (ret == 0)
|
||||
ret = -1;/* EOF - terminal got lost */
|
||||
else if (ret == -1 && (errno == EINTR || errno == EAGAIN))
|
||||
if (ret == 0) {
|
||||
/* EOF - terminal got lost */
|
||||
if (auto_detach)
|
||||
term_detach();
|
||||
ret = -1;
|
||||
} else if (ret == -1 && (errno == EINTR || errno == EAGAIN))
|
||||
ret = 0;
|
||||
|
||||
return ret;
|
||||
|
@ -93,6 +93,8 @@ static void read_settings(void)
|
||||
{
|
||||
int old_colors = term_use_colors;
|
||||
|
||||
term_auto_detach(settings_get_bool("term_auto_detach"));
|
||||
|
||||
if (force_colors != settings_get_bool("term_force_colors")) {
|
||||
force_colors = settings_get_bool("term_force_colors");
|
||||
term_force_colors(force_colors);
|
||||
@ -112,6 +114,7 @@ void term_common_init(void)
|
||||
#endif
|
||||
settings_add_bool("lookandfeel", "colors", TRUE);
|
||||
settings_add_bool("lookandfeel", "term_force_colors", FALSE);
|
||||
settings_add_bool("lookandfeel", "term_auto_detach", FALSE);
|
||||
|
||||
force_colors = FALSE;
|
||||
term_use_colors = term_has_colors() && settings_get_bool("colors");
|
||||
|
@ -23,7 +23,7 @@ typedef struct _TERM_WINDOW TERM_WINDOW;
|
||||
#endif
|
||||
|
||||
extern TERM_WINDOW *root_window;
|
||||
extern int term_width, term_height, term_use_colors;
|
||||
extern int term_width, term_height, term_use_colors, term_detached;
|
||||
|
||||
/* Initialize / deinitialize terminal */
|
||||
int term_init(void);
|
||||
@ -72,6 +72,11 @@ void term_refresh_freeze(void);
|
||||
void term_refresh_thaw(void);
|
||||
void term_refresh(TERM_WINDOW *window);
|
||||
|
||||
/* Automatically detach irssi when terminal is lost */
|
||||
void term_auto_detach(int set);
|
||||
void term_detach(void);
|
||||
void term_attach(FILE *in, FILE *out);
|
||||
|
||||
void term_stop(void);
|
||||
int term_gets(unsigned char *buffer, int size);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user