From a9324ea800301ea4a8fb8cf6b55f18e06104af33 Mon Sep 17 00:00:00 2001 From: TinWoodman92 Date: Sun, 11 Jun 2023 20:44:45 -0500 Subject: Initial version of dialoguer package. --- dialoguer/context_script.r | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 dialoguer/context_script.r (limited to 'dialoguer/context_script.r') diff --git a/dialoguer/context_script.r b/dialoguer/context_script.r new file mode 100644 index 0000000..ddc7dd9 --- /dev/null +++ b/dialoguer/context_script.r @@ -0,0 +1,56 @@ +HEADER <- 256 +PORT <- 6011 +SERVER <- "localhost" +FORMAT <- "utf-8" +DISCONNECT_MESSAGE <- "!DISSCONNECT" + +con <- socketConnection( + host = SERVER, + port = PORT, + server = FALSE +) + +display_msg <- function(msg) { + cat( + '\033[94m', + msg, + sep = '', + end = '\033[0m\n' + ) +} + +send <- function(conn, msg) { + sendme <- paste(msg, strrep(" ", HEADER - nchar(msg)), sep = "") + writeChar(sendme, conn) +} + +recv <- function(conn) { + suppressWarnings(msg <- trimws(readChar(conn, HEADER))) + while (length(msg) == 0) { + #cat('ALERT\n') + suppressWarnings(msg <- trimws(readChar(conn, HEADER))) + } + return(msg) +} + +#receive target file path +file_path <- recv(con) + +#load target file +source(file_path) + +confirm <- TRUE +msg <- 'confirm' + +while (msg != '!DISCONNECT') { + # there should be several handeling methods + # returning variables + # evaluating expressions + display_msg(msg) + val <- get(msg) + val <- as.character(val) + send(con, val) + msg <- recv(con) +} + +close(con) \ No newline at end of file -- cgit v1.2.3