Clean up code ... rename ssh_guac_terminal to guac_terminal (preparing for generic).
This commit is contained in:
parent
baa6d98724
commit
80a56bc9fd
@ -40,7 +40,17 @@ ACLOCAL_AMFLAGS = -I m4
|
|||||||
|
|
||||||
lib_LTLIBRARIES = libguac-client-ssh.la
|
lib_LTLIBRARIES = libguac-client-ssh.la
|
||||||
|
|
||||||
libguac_client_ssh_la_SOURCES = src/ssh_client.c src/ssh_handlers.c src/ssh_terminal.c src/ssh_terminal_handlers.c
|
libguac_client_ssh_la_SOURCES = \
|
||||||
|
src/ssh_client.c \
|
||||||
|
src/ssh_handlers.c \
|
||||||
|
src/terminal.c \
|
||||||
|
src/terminal_handlers.c
|
||||||
|
|
||||||
|
noinst_HEADERS = \
|
||||||
|
include/ssh_client.h \
|
||||||
|
include/ssh_handlers.h \
|
||||||
|
include/terminal.h \
|
||||||
|
include/terminal_handlers.h
|
||||||
|
|
||||||
libguac_client_ssh_la_CFLAGS = -Werror -Wall -pedantic -Iinclude @PANGO_CFLAGS@ @PANGOCAIRO_CFLAGS@
|
libguac_client_ssh_la_CFLAGS = -Werror -Wall -pedantic -Iinclude @PANGO_CFLAGS@ @PANGOCAIRO_CFLAGS@
|
||||||
libguac_client_ssh_la_LIBADD = @PANGO_LIBS@ @PANGOCAIRO_LIBS@
|
libguac_client_ssh_la_LIBADD = @PANGO_LIBS@ @PANGOCAIRO_LIBS@
|
||||||
|
@ -45,14 +45,14 @@
|
|||||||
|
|
||||||
#include "ssh_client.h"
|
#include "ssh_client.h"
|
||||||
#include "ssh_handlers.h"
|
#include "ssh_handlers.h"
|
||||||
#include "ssh_terminal.h"
|
#include "terminal.h"
|
||||||
|
|
||||||
typedef struct ssh_guac_client_data {
|
typedef struct ssh_guac_client_data {
|
||||||
|
|
||||||
ssh_session session;
|
ssh_session session;
|
||||||
ssh_channel term_channel;
|
ssh_channel term_channel;
|
||||||
|
|
||||||
ssh_guac_terminal* term;
|
guac_terminal* term;
|
||||||
|
|
||||||
char * clipboard_data;
|
char * clipboard_data;
|
||||||
|
|
||||||
|
@ -42,20 +42,20 @@
|
|||||||
|
|
||||||
#include <guacamole/client.h>
|
#include <guacamole/client.h>
|
||||||
|
|
||||||
typedef struct ssh_guac_terminal ssh_guac_terminal;
|
typedef struct guac_terminal guac_terminal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for characters printed to the terminal. When a character is printed,
|
* Handler for characters printed to the terminal. When a character is printed,
|
||||||
* the current char handler for the terminal is called and given that
|
* the current char handler for the terminal is called and given that
|
||||||
* character.
|
* character.
|
||||||
*/
|
*/
|
||||||
typedef int ssh_guac_terminal_char_handler(ssh_guac_terminal* term, char c);
|
typedef int guac_terminal_char_handler(guac_terminal* term, char c);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a single character for display in a terminal, including actual
|
* Represents a single character for display in a terminal, including actual
|
||||||
* character value, foreground color, and background color.
|
* character value, foreground color, and background color.
|
||||||
*/
|
*/
|
||||||
typedef struct ssh_guac_terminal_char {
|
typedef struct guac_terminal_char {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The character value of the character to display.
|
* The character value of the character to display.
|
||||||
@ -72,13 +72,13 @@ typedef struct ssh_guac_terminal_char {
|
|||||||
*/
|
*/
|
||||||
int background;
|
int background;
|
||||||
|
|
||||||
} ssh_guac_terminal_char;
|
} guac_terminal_char;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a terminal emulator which uses a given Guacamole client to
|
* Represents a terminal emulator which uses a given Guacamole client to
|
||||||
* render itself.
|
* render itself.
|
||||||
*/
|
*/
|
||||||
struct ssh_guac_terminal {
|
struct guac_terminal {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Guacamole client this terminal emulator will use for rendering.
|
* The Guacamole client this terminal emulator will use for rendering.
|
||||||
@ -126,7 +126,7 @@ struct ssh_guac_terminal {
|
|||||||
* Array of scrollback buffer rows, where each row is an array of
|
* Array of scrollback buffer rows, where each row is an array of
|
||||||
* characters.
|
* characters.
|
||||||
*/
|
*/
|
||||||
ssh_guac_terminal_char** scrollback;
|
guac_terminal_char** scrollback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The width of each character, in pixels.
|
* The width of each character, in pixels.
|
||||||
@ -182,46 +182,46 @@ struct ssh_guac_terminal {
|
|||||||
int default_foreground;
|
int default_foreground;
|
||||||
int default_background;
|
int default_background;
|
||||||
|
|
||||||
ssh_guac_terminal_char_handler* char_handler;
|
guac_terminal_char_handler* char_handler;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct ssh_guac_terminal_color {
|
typedef struct guac_terminal_color {
|
||||||
int red;
|
int red;
|
||||||
int green;
|
int green;
|
||||||
int blue;
|
int blue;
|
||||||
} ssh_guac_terminal_color;
|
} guac_terminal_color;
|
||||||
|
|
||||||
extern const ssh_guac_terminal_color ssh_guac_terminal_palette[16];
|
extern const guac_terminal_color guac_terminal_palette[16];
|
||||||
|
|
||||||
ssh_guac_terminal* ssh_guac_terminal_create(guac_client* client,
|
guac_terminal* guac_terminal_create(guac_client* client,
|
||||||
int width, int height);
|
int width, int height);
|
||||||
|
|
||||||
void ssh_guac_terminal_free(ssh_guac_terminal* term);
|
void guac_terminal_free(guac_terminal* term);
|
||||||
|
|
||||||
int ssh_guac_terminal_write(ssh_guac_terminal* term, const char* c, int size);
|
int guac_terminal_write(guac_terminal* term, const char* c, int size);
|
||||||
|
|
||||||
int ssh_guac_terminal_redraw_cursor(ssh_guac_terminal* term);
|
int guac_terminal_redraw_cursor(guac_terminal* term);
|
||||||
|
|
||||||
int ssh_guac_terminal_set_colors(ssh_guac_terminal* term,
|
int guac_terminal_set_colors(guac_terminal* term,
|
||||||
int foreground, int background);
|
int foreground, int background);
|
||||||
|
|
||||||
int ssh_guac_terminal_set(ssh_guac_terminal* term, int row, int col, char c);
|
int guac_terminal_set(guac_terminal* term, int row, int col, char c);
|
||||||
|
|
||||||
int ssh_guac_terminal_copy(ssh_guac_terminal* term,
|
int guac_terminal_copy(guac_terminal* term,
|
||||||
int src_row, int src_col, int rows, int cols,
|
int src_row, int src_col, int rows, int cols,
|
||||||
int dst_row, int dst_col);
|
int dst_row, int dst_col);
|
||||||
|
|
||||||
int ssh_guac_terminal_clear(ssh_guac_terminal* term,
|
int guac_terminal_clear(guac_terminal* term,
|
||||||
int row, int col, int rows, int cols, int background_color);
|
int row, int col, int rows, int cols, int background_color);
|
||||||
|
|
||||||
int ssh_guac_terminal_scroll_up(ssh_guac_terminal* term,
|
int guac_terminal_scroll_up(guac_terminal* term,
|
||||||
int start_row, int end_row, int amount);
|
int start_row, int end_row, int amount);
|
||||||
|
|
||||||
int ssh_guac_terminal_scroll_down(ssh_guac_terminal* term,
|
int guac_terminal_scroll_down(guac_terminal* term,
|
||||||
int start_row, int end_row, int amount);
|
int start_row, int end_row, int amount);
|
||||||
|
|
||||||
int ssh_guac_terminal_clear_range(ssh_guac_terminal* term,
|
int guac_terminal_clear_range(guac_terminal* term,
|
||||||
int start_row, int start_col,
|
int start_row, int start_col,
|
||||||
int end_row, int end_col, int background_color);
|
int end_row, int end_col, int background_color);
|
||||||
|
|
@ -38,13 +38,13 @@
|
|||||||
#ifndef _SSH_GUAC_TERMINAL_HANDLERS
|
#ifndef _SSH_GUAC_TERMINAL_HANDLERS
|
||||||
#define _SSH_GUAC_TERMINAL_HANDLERS
|
#define _SSH_GUAC_TERMINAL_HANDLERS
|
||||||
|
|
||||||
#include "ssh_terminal.h"
|
#include "terminal.h"
|
||||||
|
|
||||||
int ssh_guac_terminal_echo(ssh_guac_terminal* term, char c);
|
int guac_terminal_echo(guac_terminal* term, char c);
|
||||||
int ssh_guac_terminal_escape(ssh_guac_terminal* term, char c);
|
int guac_terminal_escape(guac_terminal* term, char c);
|
||||||
int ssh_guac_terminal_charset(ssh_guac_terminal* term, char c);
|
int guac_terminal_charset(guac_terminal* term, char c);
|
||||||
int ssh_guac_terminal_csi(ssh_guac_terminal* term, char c);
|
int guac_terminal_csi(guac_terminal* term, char c);
|
||||||
int ssh_guac_terminal_osc(ssh_guac_terminal* term, char c);
|
int guac_terminal_osc(guac_terminal* term, char c);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -47,7 +47,7 @@
|
|||||||
|
|
||||||
#include "ssh_client.h"
|
#include "ssh_client.h"
|
||||||
#include "ssh_handlers.h"
|
#include "ssh_handlers.h"
|
||||||
#include "ssh_terminal.h"
|
#include "terminal.h"
|
||||||
|
|
||||||
/* Client plugin arguments */
|
/* Client plugin arguments */
|
||||||
const char* GUAC_CLIENT_ARGS[] = {
|
const char* GUAC_CLIENT_ARGS[] = {
|
||||||
@ -68,8 +68,8 @@ int ssh_guac_client_password_key_handler(guac_client* client, int keysym, int pr
|
|||||||
if (keysym >= 0x00 && keysym <= 0xFF) {
|
if (keysym >= 0x00 && keysym <= 0xFF) {
|
||||||
/* Add to password */
|
/* Add to password */
|
||||||
client_data->password[client_data->password_length++] = keysym;
|
client_data->password[client_data->password_length++] = keysym;
|
||||||
ssh_guac_terminal_write(client_data->term, "*", 1);
|
guac_terminal_write(client_data->term, "*", 1);
|
||||||
ssh_guac_terminal_redraw_cursor(client_data->term);
|
guac_terminal_redraw_cursor(client_data->term);
|
||||||
guac_socket_flush(client->socket);
|
guac_socket_flush(client->socket);
|
||||||
}
|
}
|
||||||
else if (keysym == 0xFF08) {
|
else if (keysym == 0xFF08) {
|
||||||
@ -78,8 +78,8 @@ int ssh_guac_client_password_key_handler(guac_client* client, int keysym, int pr
|
|||||||
client_data->password_length--;
|
client_data->password_length--;
|
||||||
|
|
||||||
/* Backspace */
|
/* Backspace */
|
||||||
ssh_guac_terminal_write(client_data->term, "\x08\x1B[K", 4);
|
guac_terminal_write(client_data->term, "\x08\x1B[K", 4);
|
||||||
ssh_guac_terminal_redraw_cursor(client_data->term);
|
guac_terminal_redraw_cursor(client_data->term);
|
||||||
guac_socket_flush(client->socket);
|
guac_socket_flush(client->socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,8 +90,8 @@ int ssh_guac_client_password_key_handler(guac_client* client, int keysym, int pr
|
|||||||
client_data->password[client_data->password_length] = '\0';
|
client_data->password[client_data->password_length] = '\0';
|
||||||
|
|
||||||
/* Clear screen */
|
/* Clear screen */
|
||||||
ssh_guac_terminal_write(client_data->term, "\x1B[2J\x1B[1;1H", 10);
|
guac_terminal_write(client_data->term, "\x1B[2J\x1B[1;1H", 10);
|
||||||
ssh_guac_terminal_redraw_cursor(client_data->term);
|
guac_terminal_redraw_cursor(client_data->term);
|
||||||
guac_socket_flush(client->socket);
|
guac_socket_flush(client->socket);
|
||||||
|
|
||||||
return ssh_guac_client_auth(client, client_data->password);
|
return ssh_guac_client_auth(client, client_data->password);
|
||||||
@ -109,7 +109,7 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
|
|||||||
guac_socket* socket = client->socket;
|
guac_socket* socket = client->socket;
|
||||||
|
|
||||||
ssh_guac_client_data* client_data = malloc(sizeof(ssh_guac_client_data));
|
ssh_guac_client_data* client_data = malloc(sizeof(ssh_guac_client_data));
|
||||||
ssh_guac_terminal* term = ssh_guac_terminal_create(client,
|
guac_terminal* term = guac_terminal_create(client,
|
||||||
client->info.optimal_width, client->info.optimal_height);
|
client->info.optimal_width, client->info.optimal_height);
|
||||||
|
|
||||||
/* Init client data */
|
/* Init client data */
|
||||||
@ -165,8 +165,8 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
|
|||||||
else {
|
else {
|
||||||
|
|
||||||
client_data->password_length = 0;
|
client_data->password_length = 0;
|
||||||
ssh_guac_terminal_write(client_data->term, "Password: ", 10);
|
guac_terminal_write(client_data->term, "Password: ", 10);
|
||||||
ssh_guac_terminal_redraw_cursor(client_data->term);
|
guac_terminal_redraw_cursor(client_data->term);
|
||||||
guac_socket_flush(client->socket);
|
guac_socket_flush(client->socket);
|
||||||
|
|
||||||
client->key_handler = ssh_guac_client_password_key_handler;
|
client->key_handler = ssh_guac_client_password_key_handler;
|
||||||
@ -182,7 +182,7 @@ int ssh_guac_client_auth(guac_client* client, const char* password) {
|
|||||||
|
|
||||||
guac_socket* socket = client->socket;
|
guac_socket* socket = client->socket;
|
||||||
ssh_guac_client_data* client_data = (ssh_guac_client_data*) client->data;
|
ssh_guac_client_data* client_data = (ssh_guac_client_data*) client->data;
|
||||||
ssh_guac_terminal* term = client_data->term;
|
guac_terminal* term = client_data->term;
|
||||||
|
|
||||||
/* Authenticate */
|
/* Authenticate */
|
||||||
if (ssh_userauth_password(client_data->session, NULL, password) != SSH_AUTH_SUCCESS) {
|
if (ssh_userauth_password(client_data->session, NULL, password) != SSH_AUTH_SUCCESS) {
|
||||||
|
@ -90,8 +90,8 @@ int ssh_guac_client_handle_messages(guac_client* client) {
|
|||||||
&& !channel_is_eof(client_data->term_channel)
|
&& !channel_is_eof(client_data->term_channel)
|
||||||
&& (bytes_read = channel_read_nonblocking(client_data->term_channel, buffer, sizeof(buffer), 0)) > 0) {
|
&& (bytes_read = channel_read_nonblocking(client_data->term_channel, buffer, sizeof(buffer), 0)) > 0) {
|
||||||
|
|
||||||
if (ssh_guac_terminal_write(client_data->term, buffer, bytes_read)
|
if (guac_terminal_write(client_data->term, buffer, bytes_read)
|
||||||
|| ssh_guac_terminal_redraw_cursor(client_data->term)
|
|| guac_terminal_redraw_cursor(client_data->term)
|
||||||
|| guac_socket_flush(socket))
|
|| guac_socket_flush(socket))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
@ -206,7 +206,7 @@ int ssh_guac_client_free_handler(guac_client* client) {
|
|||||||
ssh_guac_client_data* guac_client_data = (ssh_guac_client_data*) client->data;
|
ssh_guac_client_data* guac_client_data = (ssh_guac_client_data*) client->data;
|
||||||
|
|
||||||
/* Free terminal */
|
/* Free terminal */
|
||||||
ssh_guac_terminal_free(guac_client_data->term);
|
guac_terminal_free(guac_client_data->term);
|
||||||
|
|
||||||
/* Free clipboard data */
|
/* Free clipboard data */
|
||||||
free(guac_client_data->clipboard_data);
|
free(guac_client_data->clipboard_data);
|
||||||
|
@ -46,10 +46,10 @@
|
|||||||
#include <guacamole/protocol.h>
|
#include <guacamole/protocol.h>
|
||||||
#include <guacamole/client.h>
|
#include <guacamole/client.h>
|
||||||
|
|
||||||
#include "ssh_terminal.h"
|
#include "terminal.h"
|
||||||
#include "ssh_terminal_handlers.h"
|
#include "terminal_handlers.h"
|
||||||
|
|
||||||
const ssh_guac_terminal_color ssh_guac_terminal_palette[16] = {
|
const guac_terminal_color guac_terminal_palette[16] = {
|
||||||
|
|
||||||
/* Normal colors */
|
/* Normal colors */
|
||||||
{0x00, 0x00, 0x00}, /* Black */
|
{0x00, 0x00, 0x00}, /* Black */
|
||||||
@ -73,7 +73,7 @@ const ssh_guac_terminal_color ssh_guac_terminal_palette[16] = {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ssh_guac_terminal* ssh_guac_terminal_create(guac_client* client,
|
guac_terminal* guac_terminal_create(guac_client* client,
|
||||||
int width, int height) {
|
int width, int height) {
|
||||||
|
|
||||||
int row, col;
|
int row, col;
|
||||||
@ -83,7 +83,7 @@ ssh_guac_terminal* ssh_guac_terminal_create(guac_client* client,
|
|||||||
PangoFontMetrics* metrics;
|
PangoFontMetrics* metrics;
|
||||||
PangoContext* context;
|
PangoContext* context;
|
||||||
|
|
||||||
ssh_guac_terminal* term = malloc(sizeof(ssh_guac_terminal));
|
guac_terminal* term = malloc(sizeof(guac_terminal));
|
||||||
term->client = client;
|
term->client = client;
|
||||||
|
|
||||||
term->glyph_foreground = term->foreground = term->default_foreground = 7; /* White */
|
term->glyph_foreground = term->foreground = term->default_foreground = 7; /* White */
|
||||||
@ -131,20 +131,20 @@ ssh_guac_terminal* ssh_guac_terminal_create(guac_client* client,
|
|||||||
|
|
||||||
term->term_width = width / term->char_width;
|
term->term_width = width / term->char_width;
|
||||||
term->term_height = height / term->char_height;
|
term->term_height = height / term->char_height;
|
||||||
term->char_handler = ssh_guac_terminal_echo;
|
term->char_handler = guac_terminal_echo;
|
||||||
|
|
||||||
term->scroll_start = 0;
|
term->scroll_start = 0;
|
||||||
term->scroll_end = term->term_height - 1;
|
term->scroll_end = term->term_height - 1;
|
||||||
|
|
||||||
/* Create scrollback buffer */
|
/* Create scrollback buffer */
|
||||||
term->scrollback = malloc(term->term_height * sizeof(ssh_guac_terminal_char*));
|
term->scrollback = malloc(term->term_height * sizeof(guac_terminal_char*));
|
||||||
|
|
||||||
/* Init buffer */
|
/* Init buffer */
|
||||||
for (row = 0; row < term->term_height; row++) {
|
for (row = 0; row < term->term_height; row++) {
|
||||||
|
|
||||||
/* Create row */
|
/* Create row */
|
||||||
ssh_guac_terminal_char* current_row =
|
guac_terminal_char* current_row =
|
||||||
term->scrollback[row] = malloc(term->term_width * sizeof(ssh_guac_terminal_char));
|
term->scrollback[row] = malloc(term->term_width * sizeof(guac_terminal_char));
|
||||||
|
|
||||||
/* Init row */
|
/* Init row */
|
||||||
for (col = 0; col < term->term_width; col++) {
|
for (col = 0; col < term->term_width; col++) {
|
||||||
@ -159,7 +159,7 @@ ssh_guac_terminal* ssh_guac_terminal_create(guac_client* client,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Clear with background color */
|
/* Clear with background color */
|
||||||
ssh_guac_terminal_clear(term,
|
guac_terminal_clear(term,
|
||||||
0, 0, term->term_height, term->term_width,
|
0, 0, term->term_height, term->term_width,
|
||||||
term->background);
|
term->background);
|
||||||
|
|
||||||
@ -167,7 +167,7 @@ ssh_guac_terminal* ssh_guac_terminal_create(guac_client* client,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ssh_guac_terminal_free(ssh_guac_terminal* term) {
|
void guac_terminal_free(guac_terminal* term) {
|
||||||
|
|
||||||
/* Free scrollback buffer */
|
/* Free scrollback buffer */
|
||||||
for (int row = 0; row < term->term_height; row++)
|
for (int row = 0; row < term->term_height; row++)
|
||||||
@ -176,18 +176,18 @@ void ssh_guac_terminal_free(ssh_guac_terminal* term) {
|
|||||||
free(term->scrollback);
|
free(term->scrollback);
|
||||||
}
|
}
|
||||||
|
|
||||||
int __ssh_guac_terminal_get_glyph(ssh_guac_terminal* term, char c) {
|
int __guac_terminal_get_glyph(guac_terminal* term, char c) {
|
||||||
|
|
||||||
guac_socket* socket = term->client->socket;
|
guac_socket* socket = term->client->socket;
|
||||||
int location;
|
int location;
|
||||||
|
|
||||||
/* Use foreground color */
|
/* Use foreground color */
|
||||||
const ssh_guac_terminal_color* color =
|
const guac_terminal_color* color =
|
||||||
&ssh_guac_terminal_palette[term->glyph_foreground];
|
&guac_terminal_palette[term->glyph_foreground];
|
||||||
|
|
||||||
/* Use background color */
|
/* Use background color */
|
||||||
const ssh_guac_terminal_color* background =
|
const guac_terminal_color* background =
|
||||||
&ssh_guac_terminal_palette[term->glyph_background];
|
&guac_terminal_palette[term->glyph_background];
|
||||||
|
|
||||||
cairo_surface_t* surface;
|
cairo_surface_t* surface;
|
||||||
cairo_t* cairo;
|
cairo_t* cairo;
|
||||||
@ -251,7 +251,7 @@ int __ssh_guac_terminal_get_glyph(ssh_guac_terminal* term, char c) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ssh_guac_terminal_redraw_cursor(ssh_guac_terminal* term) {
|
int guac_terminal_redraw_cursor(guac_terminal* term) {
|
||||||
|
|
||||||
guac_socket* socket = term->client->socket;
|
guac_socket* socket = term->client->socket;
|
||||||
|
|
||||||
@ -267,21 +267,21 @@ int ssh_guac_terminal_redraw_cursor(ssh_guac_terminal* term) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ssh_guac_terminal_set_colors(ssh_guac_terminal* term,
|
int guac_terminal_set_colors(guac_terminal* term,
|
||||||
int foreground, int background) {
|
int foreground, int background) {
|
||||||
|
|
||||||
guac_socket* socket = term->client->socket;
|
guac_socket* socket = term->client->socket;
|
||||||
const ssh_guac_terminal_color* background_color;
|
const guac_terminal_color* background_color;
|
||||||
|
|
||||||
/* Get background color */
|
/* Get background color */
|
||||||
background_color = &ssh_guac_terminal_palette[background];
|
background_color = &guac_terminal_palette[background];
|
||||||
|
|
||||||
/* If foreground different from current, colorize */
|
/* If foreground different from current, colorize */
|
||||||
if (foreground != term->glyph_foreground) {
|
if (foreground != term->glyph_foreground) {
|
||||||
|
|
||||||
/* Get color */
|
/* Get color */
|
||||||
const ssh_guac_terminal_color* color =
|
const guac_terminal_color* color =
|
||||||
&ssh_guac_terminal_palette[foreground];
|
&guac_terminal_palette[foreground];
|
||||||
|
|
||||||
/* Colorize letter */
|
/* Colorize letter */
|
||||||
guac_protocol_send_rect(socket, term->glyph_stroke,
|
guac_protocol_send_rect(socket, term->glyph_stroke,
|
||||||
@ -328,10 +328,10 @@ int ssh_guac_terminal_set_colors(ssh_guac_terminal* term,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ssh_guac_terminal_set(ssh_guac_terminal* term, int row, int col, char c) {
|
int guac_terminal_set(guac_terminal* term, int row, int col, char c) {
|
||||||
|
|
||||||
guac_socket* socket = term->client->socket;
|
guac_socket* socket = term->client->socket;
|
||||||
int location = __ssh_guac_terminal_get_glyph(term, c);
|
int location = __guac_terminal_get_glyph(term, c);
|
||||||
|
|
||||||
return guac_protocol_send_copy(socket,
|
return guac_protocol_send_copy(socket,
|
||||||
term->filled_glyphs,
|
term->filled_glyphs,
|
||||||
@ -342,7 +342,7 @@ int ssh_guac_terminal_set(ssh_guac_terminal* term, int row, int col, char c) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ssh_guac_terminal_write(ssh_guac_terminal* term, const char* c, int size) {
|
int guac_terminal_write(guac_terminal* term, const char* c, int size) {
|
||||||
|
|
||||||
while (size > 0) {
|
while (size > 0) {
|
||||||
term->char_handler(term, *(c++));
|
term->char_handler(term, *(c++));
|
||||||
@ -353,7 +353,7 @@ int ssh_guac_terminal_write(ssh_guac_terminal* term, const char* c, int size) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ssh_guac_terminal_copy(ssh_guac_terminal* term,
|
int guac_terminal_copy(guac_terminal* term,
|
||||||
int src_row, int src_col, int rows, int cols,
|
int src_row, int src_col, int rows, int cols,
|
||||||
int dst_row, int dst_col) {
|
int dst_row, int dst_col) {
|
||||||
|
|
||||||
@ -372,12 +372,12 @@ int ssh_guac_terminal_copy(ssh_guac_terminal* term,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int ssh_guac_terminal_clear(ssh_guac_terminal* term,
|
int guac_terminal_clear(guac_terminal* term,
|
||||||
int row, int col, int rows, int cols, int background_color) {
|
int row, int col, int rows, int cols, int background_color) {
|
||||||
|
|
||||||
guac_socket* socket = term->client->socket;
|
guac_socket* socket = term->client->socket;
|
||||||
const ssh_guac_terminal_color* color =
|
const guac_terminal_color* color =
|
||||||
&ssh_guac_terminal_palette[background_color];
|
&guac_terminal_palette[background_color];
|
||||||
|
|
||||||
/* Fill with color */
|
/* Fill with color */
|
||||||
return
|
return
|
||||||
@ -390,7 +390,7 @@ int ssh_guac_terminal_clear(ssh_guac_terminal* term,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ssh_guac_terminal_scroll_up(ssh_guac_terminal* term,
|
int guac_terminal_scroll_up(guac_terminal* term,
|
||||||
int start_row, int end_row, int amount) {
|
int start_row, int end_row, int amount) {
|
||||||
|
|
||||||
/* Calculate height of scroll region */
|
/* Calculate height of scroll region */
|
||||||
@ -399,19 +399,19 @@ int ssh_guac_terminal_scroll_up(ssh_guac_terminal* term,
|
|||||||
return
|
return
|
||||||
|
|
||||||
/* Move rows within scroll region up by the given amount */
|
/* Move rows within scroll region up by the given amount */
|
||||||
ssh_guac_terminal_copy(term,
|
guac_terminal_copy(term,
|
||||||
start_row + amount, 0,
|
start_row + amount, 0,
|
||||||
height - amount, term->term_width,
|
height - amount, term->term_width,
|
||||||
start_row, 0)
|
start_row, 0)
|
||||||
|
|
||||||
/* Fill new rows with background */
|
/* Fill new rows with background */
|
||||||
|| ssh_guac_terminal_clear(term,
|
|| guac_terminal_clear(term,
|
||||||
end_row - amount + 1, 0, amount, term->term_width,
|
end_row - amount + 1, 0, amount, term->term_width,
|
||||||
term->background);
|
term->background);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ssh_guac_terminal_scroll_down(ssh_guac_terminal* term,
|
int guac_terminal_scroll_down(guac_terminal* term,
|
||||||
int start_row, int end_row, int amount) {
|
int start_row, int end_row, int amount) {
|
||||||
|
|
||||||
/* Calculate height of scroll region */
|
/* Calculate height of scroll region */
|
||||||
@ -420,19 +420,19 @@ int ssh_guac_terminal_scroll_down(ssh_guac_terminal* term,
|
|||||||
return
|
return
|
||||||
|
|
||||||
/* Move rows within scroll region down by the given amount */
|
/* Move rows within scroll region down by the given amount */
|
||||||
ssh_guac_terminal_copy(term,
|
guac_terminal_copy(term,
|
||||||
start_row, 0,
|
start_row, 0,
|
||||||
height - amount, term->term_width,
|
height - amount, term->term_width,
|
||||||
start_row + amount, 0)
|
start_row + amount, 0)
|
||||||
|
|
||||||
/* Fill new rows with background */
|
/* Fill new rows with background */
|
||||||
|| ssh_guac_terminal_clear(term,
|
|| guac_terminal_clear(term,
|
||||||
start_row, 0, amount, term->term_width,
|
start_row, 0, amount, term->term_width,
|
||||||
term->background);
|
term->background);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ssh_guac_terminal_clear_range(ssh_guac_terminal* term,
|
int guac_terminal_clear_range(guac_terminal* term,
|
||||||
int start_row, int start_col,
|
int start_row, int start_col,
|
||||||
int end_row, int end_col, int background_color) {
|
int end_row, int end_col, int background_color) {
|
||||||
|
|
||||||
@ -440,7 +440,7 @@ int ssh_guac_terminal_clear_range(ssh_guac_terminal* term,
|
|||||||
if (start_col > 0) {
|
if (start_col > 0) {
|
||||||
|
|
||||||
/* Clear from start_col to far right */
|
/* Clear from start_col to far right */
|
||||||
if (ssh_guac_terminal_clear(term,
|
if (guac_terminal_clear(term,
|
||||||
start_row, start_col, 1, term->term_width - start_col,
|
start_row, start_col, 1, term->term_width - start_col,
|
||||||
background_color))
|
background_color))
|
||||||
return 1;
|
return 1;
|
||||||
@ -453,7 +453,7 @@ int ssh_guac_terminal_clear_range(ssh_guac_terminal* term,
|
|||||||
if (end_col < term->term_width - 1) {
|
if (end_col < term->term_width - 1) {
|
||||||
|
|
||||||
/* Clear from far left to end_col */
|
/* Clear from far left to end_col */
|
||||||
if (ssh_guac_terminal_clear(term,
|
if (guac_terminal_clear(term,
|
||||||
end_row, 0, 1, end_col + 1,
|
end_row, 0, 1, end_col + 1,
|
||||||
background_color))
|
background_color))
|
||||||
return 1;
|
return 1;
|
||||||
@ -466,7 +466,7 @@ int ssh_guac_terminal_clear_range(ssh_guac_terminal* term,
|
|||||||
/* Remaining region now guaranteed rectangular. Clear, if possible */
|
/* Remaining region now guaranteed rectangular. Clear, if possible */
|
||||||
if (start_row <= end_row) {
|
if (start_row <= end_row) {
|
||||||
|
|
||||||
if (ssh_guac_terminal_clear(term,
|
if (guac_terminal_clear(term,
|
||||||
start_row, 0, end_row - start_row + 1, term->term_width,
|
start_row, 0, end_row - start_row + 1, term->term_width,
|
||||||
background_color))
|
background_color))
|
||||||
return 1;
|
return 1;
|
@ -37,10 +37,10 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "ssh_terminal.h"
|
#include "terminal.h"
|
||||||
#include "ssh_terminal_handlers.h"
|
#include "terminal_handlers.h"
|
||||||
|
|
||||||
int ssh_guac_terminal_echo(ssh_guac_terminal* term, char c) {
|
int guac_terminal_echo(guac_terminal* term, char c) {
|
||||||
|
|
||||||
int foreground = term->foreground;
|
int foreground = term->foreground;
|
||||||
int background = term->background;
|
int background = term->background;
|
||||||
@ -71,14 +71,14 @@ int ssh_guac_terminal_echo(ssh_guac_terminal* term, char c) {
|
|||||||
term->cursor_row = term->scroll_end;
|
term->cursor_row = term->scroll_end;
|
||||||
|
|
||||||
/* Scroll up by one row */
|
/* Scroll up by one row */
|
||||||
ssh_guac_terminal_scroll_up(term, term->scroll_start, term->scroll_end, 1);
|
guac_terminal_scroll_up(term, term->scroll_start, term->scroll_end, 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* ESC */
|
/* ESC */
|
||||||
case 0x1B:
|
case 0x1B:
|
||||||
term->char_handler = ssh_guac_terminal_escape;
|
term->char_handler = guac_terminal_escape;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Displayable chars */
|
/* Displayable chars */
|
||||||
@ -95,7 +95,7 @@ int ssh_guac_terminal_echo(ssh_guac_terminal* term, char c) {
|
|||||||
term->cursor_row = term->scroll_end;
|
term->cursor_row = term->scroll_end;
|
||||||
|
|
||||||
/* Scroll up by one row */
|
/* Scroll up by one row */
|
||||||
ssh_guac_terminal_scroll_up(term, term->scroll_start, term->scroll_end, 1);
|
guac_terminal_scroll_up(term, term->scroll_start, term->scroll_end, 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,10 +110,10 @@ int ssh_guac_terminal_echo(ssh_guac_terminal* term, char c) {
|
|||||||
if (term->bold && foreground <= 7)
|
if (term->bold && foreground <= 7)
|
||||||
foreground += 8;
|
foreground += 8;
|
||||||
|
|
||||||
ssh_guac_terminal_set_colors(term,
|
guac_terminal_set_colors(term,
|
||||||
foreground, background);
|
foreground, background);
|
||||||
|
|
||||||
ssh_guac_terminal_set(term,
|
guac_terminal_set(term,
|
||||||
term->cursor_row,
|
term->cursor_row,
|
||||||
term->cursor_col,
|
term->cursor_col,
|
||||||
c);
|
c);
|
||||||
@ -127,25 +127,25 @@ int ssh_guac_terminal_echo(ssh_guac_terminal* term, char c) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ssh_guac_terminal_escape(ssh_guac_terminal* term, char c) {
|
int guac_terminal_escape(guac_terminal* term, char c) {
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
|
||||||
case '(':
|
case '(':
|
||||||
term->char_handler = ssh_guac_terminal_charset;
|
term->char_handler = guac_terminal_charset;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ']':
|
case ']':
|
||||||
term->char_handler = ssh_guac_terminal_osc;
|
term->char_handler = guac_terminal_osc;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '[':
|
case '[':
|
||||||
term->char_handler = ssh_guac_terminal_csi;
|
term->char_handler = guac_terminal_csi;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
guac_client_log_info(term->client, "Unhandled ESC sequence: %c", c);
|
guac_client_log_info(term->client, "Unhandled ESC sequence: %c", c);
|
||||||
term->char_handler = ssh_guac_terminal_echo;
|
term->char_handler = guac_terminal_echo;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,12 +153,12 @@ int ssh_guac_terminal_escape(ssh_guac_terminal* term, char c) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ssh_guac_terminal_charset(ssh_guac_terminal* term, char c) {
|
int guac_terminal_charset(guac_terminal* term, char c) {
|
||||||
term->char_handler = ssh_guac_terminal_echo;
|
term->char_handler = guac_terminal_echo;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ssh_guac_terminal_csi(ssh_guac_terminal* term, char c) {
|
int guac_terminal_csi(guac_terminal* term, char c) {
|
||||||
|
|
||||||
/* CSI function arguments */
|
/* CSI function arguments */
|
||||||
static int argc = 0;
|
static int argc = 0;
|
||||||
@ -361,21 +361,21 @@ int ssh_guac_terminal_csi(ssh_guac_terminal* term, char c) {
|
|||||||
|
|
||||||
/* Erase from cursor to end of display */
|
/* Erase from cursor to end of display */
|
||||||
if (argv[0] == 0)
|
if (argv[0] == 0)
|
||||||
ssh_guac_terminal_clear_range(term,
|
guac_terminal_clear_range(term,
|
||||||
term->cursor_row, term->cursor_col,
|
term->cursor_row, term->cursor_col,
|
||||||
term->term_height-1, term->term_width-1,
|
term->term_height-1, term->term_width-1,
|
||||||
term->background);
|
term->background);
|
||||||
|
|
||||||
/* Erase from start to cursor */
|
/* Erase from start to cursor */
|
||||||
else if (argv[0] == 1)
|
else if (argv[0] == 1)
|
||||||
ssh_guac_terminal_clear_range(term,
|
guac_terminal_clear_range(term,
|
||||||
0, 0,
|
0, 0,
|
||||||
term->cursor_row, term->cursor_col,
|
term->cursor_row, term->cursor_col,
|
||||||
term->background);
|
term->background);
|
||||||
|
|
||||||
/* Entire screen */
|
/* Entire screen */
|
||||||
else if (argv[0] == 2)
|
else if (argv[0] == 2)
|
||||||
ssh_guac_terminal_clear(term,
|
guac_terminal_clear(term,
|
||||||
0, 0, term->term_height, term->term_width,
|
0, 0, term->term_height, term->term_width,
|
||||||
term->background);
|
term->background);
|
||||||
|
|
||||||
@ -386,7 +386,7 @@ int ssh_guac_terminal_csi(ssh_guac_terminal* term, char c) {
|
|||||||
|
|
||||||
/* Erase from cursor to end of line */
|
/* Erase from cursor to end of line */
|
||||||
if (argv[0] == 0)
|
if (argv[0] == 0)
|
||||||
ssh_guac_terminal_clear(term,
|
guac_terminal_clear(term,
|
||||||
term->cursor_row, term->cursor_col,
|
term->cursor_row, term->cursor_col,
|
||||||
1, term->term_width - term->cursor_col,
|
1, term->term_width - term->cursor_col,
|
||||||
term->background);
|
term->background);
|
||||||
@ -394,14 +394,14 @@ int ssh_guac_terminal_csi(ssh_guac_terminal* term, char c) {
|
|||||||
|
|
||||||
/* Erase from start to cursor */
|
/* Erase from start to cursor */
|
||||||
else if (argv[0] == 1)
|
else if (argv[0] == 1)
|
||||||
ssh_guac_terminal_clear(term,
|
guac_terminal_clear(term,
|
||||||
term->cursor_row, 0,
|
term->cursor_row, 0,
|
||||||
1, term->cursor_col + 1,
|
1, term->cursor_col + 1,
|
||||||
term->background);
|
term->background);
|
||||||
|
|
||||||
/* Erase line */
|
/* Erase line */
|
||||||
else if (argv[0] == 2)
|
else if (argv[0] == 2)
|
||||||
ssh_guac_terminal_clear(term,
|
guac_terminal_clear(term,
|
||||||
term->cursor_row, 0,
|
term->cursor_row, 0,
|
||||||
1, term->term_width,
|
1, term->term_width,
|
||||||
term->background);
|
term->background);
|
||||||
@ -414,7 +414,7 @@ int ssh_guac_terminal_csi(ssh_guac_terminal* term, char c) {
|
|||||||
amount = argv[0];
|
amount = argv[0];
|
||||||
if (amount == 0) amount = 1;
|
if (amount == 0) amount = 1;
|
||||||
|
|
||||||
ssh_guac_terminal_scroll_down(term,
|
guac_terminal_scroll_down(term,
|
||||||
term->cursor_row, term->scroll_end, amount);
|
term->cursor_row, term->scroll_end, amount);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -425,7 +425,7 @@ int ssh_guac_terminal_csi(ssh_guac_terminal* term, char c) {
|
|||||||
amount = argv[0];
|
amount = argv[0];
|
||||||
if (amount == 0) amount = 1;
|
if (amount == 0) amount = 1;
|
||||||
|
|
||||||
ssh_guac_terminal_scroll_up(term,
|
guac_terminal_scroll_up(term,
|
||||||
term->cursor_row, term->scroll_end, amount);
|
term->cursor_row, term->scroll_end, amount);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -438,14 +438,14 @@ int ssh_guac_terminal_csi(ssh_guac_terminal* term, char c) {
|
|||||||
|
|
||||||
/* Scroll left by amount */
|
/* Scroll left by amount */
|
||||||
if (term->cursor_col + amount < term->term_width)
|
if (term->cursor_col + amount < term->term_width)
|
||||||
ssh_guac_terminal_copy(term,
|
guac_terminal_copy(term,
|
||||||
term->cursor_row, term->cursor_col + amount,
|
term->cursor_row, term->cursor_col + amount,
|
||||||
1,
|
1,
|
||||||
term->term_width - term->cursor_col - amount,
|
term->term_width - term->cursor_col - amount,
|
||||||
term->cursor_row, term->cursor_col);
|
term->cursor_row, term->cursor_col);
|
||||||
|
|
||||||
/* Clear right */
|
/* Clear right */
|
||||||
ssh_guac_terminal_clear(term,
|
guac_terminal_clear(term,
|
||||||
term->cursor_row, term->term_width - amount,
|
term->cursor_row, term->term_width - amount,
|
||||||
1, amount,
|
1, amount,
|
||||||
term->background);
|
term->background);
|
||||||
@ -460,13 +460,13 @@ int ssh_guac_terminal_csi(ssh_guac_terminal* term, char c) {
|
|||||||
|
|
||||||
/* Scroll right by amount */
|
/* Scroll right by amount */
|
||||||
if (term->cursor_col + amount < term->term_width)
|
if (term->cursor_col + amount < term->term_width)
|
||||||
ssh_guac_terminal_copy(term,
|
guac_terminal_copy(term,
|
||||||
term->cursor_row, term->cursor_col,
|
term->cursor_row, term->cursor_col,
|
||||||
1, term->term_width - term->cursor_col - amount,
|
1, term->term_width - term->cursor_col - amount,
|
||||||
term->cursor_row, term->cursor_col + amount);
|
term->cursor_row, term->cursor_col + amount);
|
||||||
|
|
||||||
/* Clear left */
|
/* Clear left */
|
||||||
ssh_guac_terminal_clear(term,
|
guac_terminal_clear(term,
|
||||||
term->cursor_row, term->cursor_col,
|
term->cursor_row, term->cursor_col,
|
||||||
1, amount,
|
1, amount,
|
||||||
term->background);
|
term->background);
|
||||||
@ -482,7 +482,7 @@ int ssh_guac_terminal_csi(ssh_guac_terminal* term, char c) {
|
|||||||
|
|
||||||
/* If not a semicolon, end of CSI sequence */
|
/* If not a semicolon, end of CSI sequence */
|
||||||
if (c != ';') {
|
if (c != ';') {
|
||||||
term->char_handler = ssh_guac_terminal_echo;
|
term->char_handler = guac_terminal_echo;
|
||||||
|
|
||||||
/* Reset parameters */
|
/* Reset parameters */
|
||||||
for (i=0; i<argc; i++)
|
for (i=0; i<argc; i++)
|
||||||
@ -499,10 +499,10 @@ int ssh_guac_terminal_csi(ssh_guac_terminal* term, char c) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ssh_guac_terminal_osc(ssh_guac_terminal* term, char c) {
|
int guac_terminal_osc(guac_terminal* term, char c) {
|
||||||
/* TODO: Implement OSC */
|
/* TODO: Implement OSC */
|
||||||
if (c == 0x9C || c == 0x5C || c == 0x07) /* ECMA-48 ST (String Terminator */
|
if (c == 0x9C || c == 0x5C || c == 0x07) /* ECMA-48 ST (String Terminator */
|
||||||
term->char_handler = ssh_guac_terminal_echo;
|
term->char_handler = guac_terminal_echo;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user