1
0
mirror of https://github.com/CPunch/Laika.git synced 2025-10-09 01:10:14 +00:00

Added termsize 'cols & rows' to SHELL_OPEN packets

This commit is contained in:
2022-03-07 15:16:46 -06:00
parent d283b977d9
commit e1ce053aa8
11 changed files with 47 additions and 12 deletions

View File

@@ -31,7 +31,7 @@ tShell_peer *shellC_getPeerByPub(tShell_client *client, uint8_t *pub, int *id);
int shellC_addPeer(tShell_client *client, tShell_peer *peer); /* returns new peer id */
void shellC_rmvPeer(tShell_client *client, tShell_peer *peer, int id);
void shellC_openShell(tShell_client *client, tShell_peer *peer);
void shellC_openShell(tShell_client *client, tShell_peer *peer, uint16_t col, uint16_t row);
void shellC_closeShell(tShell_client *client);
void shellC_sendDataShell(tShell_client *client, uint8_t *data, size_t sz);

View File

@@ -5,6 +5,7 @@
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <termios.h>
#include <stdbool.h>
@@ -19,6 +20,7 @@ void shellT_printf(const char *format, ...);
bool shellT_waitForInput(int timeout);
int shellT_readRawInput(uint8_t *buf, size_t max);
void shellT_writeRawOutput(uint8_t *buf, size_t sz);
void shellT_getTermSize(int *col, int *row);
char shellT_getch(void);
int shellT_kbget(void);
void shellT_printPrompt(void);

View File

@@ -318,7 +318,7 @@ void shellC_rmvPeer(tShell_client *client, tShell_peer *oldPeer, int id) {
shellP_freePeer(oldPeer);
}
void shellC_openShell(tShell_client *client, tShell_peer *peer) {
void shellC_openShell(tShell_client *client, tShell_peer *peer, uint16_t col, uint16_t row) {
/* check if we already have a shell open */
if (client->openShell)
return;
@@ -326,6 +326,8 @@ void shellC_openShell(tShell_client *client, tShell_peer *peer) {
/* send SHELL_OPEN request */
laikaS_startOutPacket(client->peer, LAIKAPKT_AUTHENTICATED_SHELL_OPEN_REQ);
laikaS_write(&client->peer->sock, peer->pub, sizeof(peer->pub));
laikaS_writeInt(&client->peer->sock, &col, sizeof(uint16_t));
laikaS_writeInt(&client->peer->sock, &row, sizeof(uint16_t));
laikaS_endOutPacket(client->peer);
client->openShell = peer;
}

View File

@@ -49,7 +49,7 @@ void listPeers(tShell_client *client, int args, char *argc[]) {
void openShell(tShell_client *client, int args, char *argc[]) {
uint8_t buf[LAIKA_SHELL_DATA_MAX_LENGTH];
tShell_peer *peer;
int id, sz;
int id, sz, cols, rows;
if (args < 2)
CMD_ERROR("Usage: shell [PEER_ID]\n");
@@ -60,7 +60,8 @@ void openShell(tShell_client *client, int args, char *argc[]) {
shellT_printf("\n\nOpening shell on peer %04d...\n\n");
/* open shell on peer */
shellC_openShell(client, peer);
shellT_getTermSize(&cols, &rows);
shellC_openShell(client, peer, cols, rows);
/* while client is alive, and our shell is open */
while (laikaS_isAlive((&client->peer->sock)) && shellC_isShellOpen(client)) {
@@ -78,6 +79,10 @@ void openShell(tShell_client *client, int args, char *argc[]) {
}
}
/* fix terminal */
shellT_resetTerm();
shellT_conioTerm();
shellT_printf("\n\nShell closed\n\n");
}

View File

@@ -69,6 +69,14 @@ void shellT_writeRawOutput(uint8_t *buf, size_t sz) {
fflush(stdout);
}
void shellT_getTermSize(int *col, int *row) {
struct winsize ws;
ioctl(STDIN_FILENO, TIOCGWINSZ, &ws);
*col = ws.ws_col;
*row = ws.ws_row;
}
char shellT_getch(void) {
int r;
char in;