Compare commits
5 Commits
07ef81d009
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b864fa072 | ||
|
|
059f8f67de | ||
|
|
dec55f18f6 | ||
| 8fdb9901a2 | |||
| a555160ad5 |
@@ -20,14 +20,16 @@ void setCursor(int XPos, int YPos);
|
||||
void getCursor(int* x, int* y);
|
||||
void hideCursor();
|
||||
void showCursor();
|
||||
void clearScreen();
|
||||
void clearScreen(short width, short height);
|
||||
void closeScreen();
|
||||
void closeScreen(short width, short height);
|
||||
void writeAt(int x, int y, char ch);
|
||||
void printFrame(vector<vector<char>> screen, short width, short height);
|
||||
void screen_type(vector<vector<char>> &screen, string str, int x, int y, bool vertical);
|
||||
void screen_clear(vector<vector<char>> &screen);
|
||||
void eachFrame(vector<vector<char>> &screen, short width, short height);
|
||||
|
||||
Timer t = Timer();
|
||||
ofstream Log ("log.txt");
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
@@ -57,10 +59,12 @@ int main(int argc, char **argv)
|
||||
|
||||
hideCursor();
|
||||
|
||||
t.setInterval([&]() {
|
||||
t.setInterval([&]()
|
||||
{
|
||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
||||
|
||||
if (w.ws_row > 0 && w.ws_col > 0) {
|
||||
if (w.ws_row > 0 && w.ws_col > 0)
|
||||
{
|
||||
|
||||
//fill vector
|
||||
screen.resize(w.ws_col);
|
||||
@@ -80,7 +84,7 @@ int main(int argc, char **argv)
|
||||
|
||||
void beforeExit()
|
||||
{
|
||||
//clearScreen();
|
||||
//closeScreen();
|
||||
setCursor(0,0);
|
||||
showCursor();
|
||||
t.stop();
|
||||
@@ -93,10 +97,12 @@ void beforeExit(int i)
|
||||
beforeExit();
|
||||
}
|
||||
|
||||
void setCursor(int XPos, int YPos) {
|
||||
void setCursor(int XPos, int YPos)
|
||||
{
|
||||
printf("\033[%d;%dH",YPos+1,XPos+1);
|
||||
}
|
||||
void getCursor(int* x, int* y) {
|
||||
void getCursor(int* x, int* y)
|
||||
{
|
||||
printf("\033[6n");
|
||||
scanf("\033[%d;%dR", x, y);
|
||||
}
|
||||
@@ -121,13 +127,14 @@ void writeAt(int x, int y, char ch)
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
void clearScreen() {
|
||||
void closeScreen()
|
||||
{
|
||||
struct winsize w;
|
||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
||||
clearScreen(w.ws_col, w.ws_row);
|
||||
closeScreen(w.ws_col, w.ws_row);
|
||||
}
|
||||
|
||||
void clearScreen(short width, short height)
|
||||
void closeScreen(short width, short height)
|
||||
{
|
||||
setCursor(0, 0);
|
||||
for (int i = 0; i < height; i++)
|
||||
@@ -148,7 +155,8 @@ void printFrame(vector<vector<char>> screen, short width, short height)
|
||||
//cout << endl;
|
||||
}
|
||||
setCursor(0,0);
|
||||
/*for (auto& col : screen) {
|
||||
/*for (auto& col : screen)
|
||||
{
|
||||
for (auto& ch : col)
|
||||
cout << ch;
|
||||
cout << endl;
|
||||
@@ -162,7 +170,8 @@ void screen_type(vector<vector<char>> &screen, string str, int x, int y, bool ve
|
||||
int width = 0,
|
||||
height = 0;
|
||||
|
||||
if (str.length()) {
|
||||
if (str.length())
|
||||
{
|
||||
|
||||
//str.append("\033[0m");
|
||||
|
||||
@@ -180,19 +189,29 @@ void screen_type(vector<vector<char>> &screen, string str, int x, int y, bool ve
|
||||
}
|
||||
|
||||
for (int i = x, ii = 0, d = 0; ii < width; i++, ii++)
|
||||
for (int j = y, jj = 0; jj < height; j++, jj++, d++) {
|
||||
for (int j = y, jj = 0; jj < height; j++, jj++, d++)
|
||||
{
|
||||
//cout << str.at(d) << " " << i << "," << j << endl;
|
||||
screen.at(i).at(j) = str.at(d);
|
||||
}
|
||||
}
|
||||
|
||||
void screen_clear(vector<vector<char>> &screen)
|
||||
{
|
||||
for (int i = 0; i < screen.size(); i++)
|
||||
for (int j = 0; j < screen.at(i).size(); j++)
|
||||
screen.at(i).at(j) = ' ';
|
||||
}
|
||||
|
||||
void eachFrame(vector<vector<char>> &screen, short width, short height)
|
||||
{
|
||||
|
||||
screen_clear(screen);
|
||||
|
||||
stringstream ss;
|
||||
|
||||
ss << width << "x" << height;
|
||||
//ss << "Hello World.";
|
||||
//ss << width << "x" << height;
|
||||
ss << "Hello World.";
|
||||
|
||||
screen_type(screen, ss.str(), 10, 10, false);
|
||||
|
||||
15
arch-discordbots-service/service/.vscode/c_cpp_properties.json
vendored
Normal file
15
arch-discordbots-service/service/.vscode/c_cpp_properties.json
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Linux",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"defines": [],
|
||||
"compilerPath": "/usr/bin/gcc",
|
||||
"cStandard": "gnu17",
|
||||
"intelliSenseMode": "linux-gcc-x64"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
34
arch-discordbots-service/service/.vscode/launch.json
vendored
Normal file
34
arch-discordbots-service/service/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "g++ - Build and debug active file",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "${fileDirname}/${fileBasenameNoExtension}",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${fileDirname}",
|
||||
"environment": [],
|
||||
"externalConsole": false,
|
||||
"MIMode": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
},
|
||||
{
|
||||
"description": "Set Disassembly Flavor to Intel",
|
||||
"text": "-gdb-set disassembly-flavor intel",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
],
|
||||
"preLaunchTask": "C/C++: g++ build active file",
|
||||
"miDebuggerPath": "/usr/bin/gdb"
|
||||
}
|
||||
]
|
||||
}
|
||||
5
arch-discordbots-service/service/.vscode/settings.json
vendored
Normal file
5
arch-discordbots-service/service/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"vector": "cpp"
|
||||
}
|
||||
}
|
||||
28
arch-discordbots-service/service/.vscode/tasks.json
vendored
Normal file
28
arch-discordbots-service/service/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"tasks": [
|
||||
{
|
||||
"type": "cppbuild",
|
||||
"label": "C/C++: g++ build active file",
|
||||
"command": "/usr/bin/g++",
|
||||
"args": [
|
||||
"-fdiagnostics-color=always",
|
||||
"-g",
|
||||
"${file}",
|
||||
"-o",
|
||||
"${fileDirname}/${fileBasenameNoExtension}"
|
||||
],
|
||||
"options": {
|
||||
"cwd": "${fileDirname}"
|
||||
},
|
||||
"problemMatcher": [
|
||||
"$gcc"
|
||||
],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"detail": "Task generated by Debugger."
|
||||
}
|
||||
],
|
||||
"version": "2.0.0"
|
||||
}
|
||||
1
arch-discordbots-service/service/build
Executable file
1
arch-discordbots-service/service/build
Executable file
@@ -0,0 +1 @@
|
||||
g++ $1.cpp -o $1.o && chmod +x $1.o
|
||||
BIN
arch-discordbots-service/service/main
Executable file
BIN
arch-discordbots-service/service/main
Executable file
Binary file not shown.
129
arch-discordbots-service/service/main.cpp
Normal file
129
arch-discordbots-service/service/main.cpp
Normal file
@@ -0,0 +1,129 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class DATA {
|
||||
public:
|
||||
string loc = "";
|
||||
string script = "";
|
||||
string name = "";
|
||||
bool disabled = false;
|
||||
};
|
||||
|
||||
static inline void trim(string &s) {
|
||||
s.erase(s.begin(), find_if(s.begin(), s.end(), [](unsigned char ch) {
|
||||
return !isspace(ch);
|
||||
}));
|
||||
s.erase(find_if(s.rbegin(), s.rend(), [](unsigned char ch) {
|
||||
return !isspace(ch);
|
||||
}).base(), s.end());
|
||||
}
|
||||
|
||||
string exec(const char* cmd) {
|
||||
array<char, 128> buffer;
|
||||
string result;
|
||||
unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
|
||||
if (!pipe) {
|
||||
throw runtime_error("popen() failed!");
|
||||
}
|
||||
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
|
||||
result += buffer.data();
|
||||
}
|
||||
trim(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
const int DATALEN = 2;
|
||||
void splitData(string str, DATA &data) {
|
||||
|
||||
stringstream ssin(str);
|
||||
|
||||
while (ssin.good()) {
|
||||
if (data.loc.length() == 0) {
|
||||
ssin >> data.loc;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (data.script.length() > 0)
|
||||
data.loc += " " + data.script;
|
||||
|
||||
ssin >> data.script;
|
||||
}
|
||||
|
||||
if (data.loc[0] == '~')
|
||||
data.loc = getenv("HOME") + data.loc.substr(1);
|
||||
|
||||
string cmd = "cd \"" + data.loc + "\" && cut -d \"=\" -f 2 <<< $(npm run env | grep npm_package_name)";
|
||||
data.name = exec(cmd.c_str());
|
||||
|
||||
}
|
||||
|
||||
void loadfile(vector<DATA> &scripts) {
|
||||
ifstream infile("scripts");
|
||||
string line;
|
||||
int linenum = 0;
|
||||
while (getline(infile, line)) {
|
||||
linenum++;
|
||||
istringstream iss(line);
|
||||
string str = iss.str();
|
||||
|
||||
if (str.length() == 0)
|
||||
continue;
|
||||
|
||||
DATA data;
|
||||
|
||||
if (str[0] == '#') {
|
||||
data.disabled = true;
|
||||
str = str.substr(1);
|
||||
}
|
||||
|
||||
splitData(str, data);
|
||||
|
||||
if (data.loc.length() == 0 || data.script.length() == 0 || data.name.length() == 0) {
|
||||
cout << "WARNING: skipping line " << linenum << endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
scripts.push_back(data);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
vector<DATA> scripts;
|
||||
|
||||
loadfile(scripts);
|
||||
|
||||
for (int i = 0; i < scripts.size(); i++) {
|
||||
DATA data = scripts.at(i);
|
||||
}
|
||||
|
||||
struct stat sb;
|
||||
time_t mtime = 0;
|
||||
|
||||
while (true) {
|
||||
stat("scripts", &sb);
|
||||
if (sb.st_mtime > mtime) {
|
||||
mtime = sb.st_mtime;
|
||||
cout << "modified" << endl;
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
7
arch-discordbots-service/service/scripts
Normal file
7
arch-discordbots-service/service/scripts
Normal file
@@ -0,0 +1,7 @@
|
||||
~/discordBots/autovc/ start
|
||||
~/discordBots/autorole/ start
|
||||
#~/discordBots/funnyBike/cleverbot-bot/ start
|
||||
#~/discordBots/funnyBike/watch-cleverbot-talk/ start
|
||||
#~/discordBots/funnyBike/wolframalpha/ start
|
||||
~/discordBots/IKEA-Canada-Support/rolemanager tmux
|
||||
~/discordBots/thom wishlane server/rolemanager tmux
|
||||
Reference in New Issue
Block a user