diff --git a/src/client.c b/src/client.c index 62b2ca3..b5d716a 100644 --- a/src/client.c +++ b/src/client.c @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include "debug.h" @@ -133,6 +135,55 @@ int seeking_solutions(const char* filename, char* const argv[], write(sock, &path_len, sizeof(size_t)); write(sock, abs_path, path_len); + // 发送终端信息 + // 1. 检查是否为交互式终端 + int is_tty = isatty(STDIN_FILENO); + write(sock, &is_tty, sizeof(int)); + + // 2. 如果是终端,获取窗口大小 + struct winsize ws; + memset(&ws, 0, sizeof(ws)); + if (is_tty) { + ioctl(STDIN_FILENO, TIOCGWINSZ, &ws); + } + write(sock, &ws.ws_row, sizeof(unsigned short)); // 行数 + write(sock, &ws.ws_col, sizeof(unsigned short)); // 列数 + write(sock, &ws.ws_xpixel, sizeof(unsigned short)); // X像素 + write(sock, &ws.ws_ypixel, sizeof(unsigned short)); // Y像素 + + // 3. 获取终端类型 + const char* term_type = getenv("TERM"); + if (term_type == NULL) { + term_type = ""; + } + size_t term_type_len = strlen(term_type); + write(sock, &term_type_len, sizeof(size_t)); + write(sock, term_type, term_type_len); + + // 4. 获取SHELL类型 + const char* shell_type = getenv("SHELL"); + if (shell_type == NULL) { + shell_type = ""; + } + size_t shell_type_len = strlen(shell_type); + write(sock, &shell_type_len, sizeof(size_t)); + write(sock, shell_type, shell_type_len); + + // 5. 获取终端属性(如果是tty) + struct termios term_attr; + int has_termios = 0; + if (is_tty && tcgetattr(STDIN_FILENO, &term_attr) == 0) { + has_termios = 1; + } + write(sock, &has_termios, sizeof(int)); + if (has_termios) { + // 发送关键的termios标志 + write(sock, &term_attr.c_iflag, sizeof(tcflag_t)); + write(sock, &term_attr.c_oflag, sizeof(tcflag_t)); + write(sock, &term_attr.c_cflag, sizeof(tcflag_t)); + write(sock, &term_attr.c_lflag, sizeof(tcflag_t)); + } + // 接收服务器响应 char buffer[BUFFER_SIZE]; char display_buffer[BUFFER_SIZE];