Compare commits

..

5 Commits

Author SHA1 Message Date
Ashley Rosch
2b864fa072 check for modifications 2021-12-24 04:07:44 -06:00
Ashley Rosch
059f8f67de working 2021-12-24 03:50:27 -06:00
Ashley Rosch
dec55f18f6 load file 2021-12-24 01:51:21 -06:00
8fdb9901a2 temp 2021-12-24 00:38:37 -06:00
a555160ad5 i forgot that did nothing 2021-12-24 00:34:57 -06:00
11 changed files with 253 additions and 15 deletions

View File

@@ -20,14 +20,16 @@ void setCursor(int XPos, int YPos);
void getCursor(int* x, int* y); void getCursor(int* x, int* y);
void hideCursor(); void hideCursor();
void showCursor(); void showCursor();
void clearScreen(); void closeScreen();
void clearScreen(short width, short height); void closeScreen(short width, short height);
void writeAt(int x, int y, char ch); void writeAt(int x, int y, char ch);
void printFrame(vector<vector<char>> screen, short width, short height); 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_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); void eachFrame(vector<vector<char>> &screen, short width, short height);
Timer t = Timer(); Timer t = Timer();
ofstream Log ("log.txt");
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
@@ -57,10 +59,12 @@ int main(int argc, char **argv)
hideCursor(); hideCursor();
t.setInterval([&]() { t.setInterval([&]()
{
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); 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 //fill vector
screen.resize(w.ws_col); screen.resize(w.ws_col);
@@ -80,7 +84,7 @@ int main(int argc, char **argv)
void beforeExit() void beforeExit()
{ {
//clearScreen(); //closeScreen();
setCursor(0,0); setCursor(0,0);
showCursor(); showCursor();
t.stop(); t.stop();
@@ -93,10 +97,12 @@ void beforeExit(int i)
beforeExit(); beforeExit();
} }
void setCursor(int XPos, int YPos) { void setCursor(int XPos, int YPos)
{
printf("\033[%d;%dH",YPos+1,XPos+1); printf("\033[%d;%dH",YPos+1,XPos+1);
} }
void getCursor(int* x, int* y) { void getCursor(int* x, int* y)
{
printf("\033[6n"); printf("\033[6n");
scanf("\033[%d;%dR", x, y); scanf("\033[%d;%dR", x, y);
} }
@@ -121,13 +127,14 @@ void writeAt(int x, int y, char ch)
fflush(stdout); fflush(stdout);
} }
void clearScreen() { void closeScreen()
{
struct winsize w; struct winsize w;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &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); setCursor(0, 0);
for (int i = 0; i < height; i++) for (int i = 0; i < height; i++)
@@ -148,7 +155,8 @@ void printFrame(vector<vector<char>> screen, short width, short height)
//cout << endl; //cout << endl;
} }
setCursor(0,0); setCursor(0,0);
/*for (auto& col : screen) { /*for (auto& col : screen)
{
for (auto& ch : col) for (auto& ch : col)
cout << ch; cout << ch;
cout << endl; cout << endl;
@@ -162,7 +170,8 @@ void screen_type(vector<vector<char>> &screen, string str, int x, int y, bool ve
int width = 0, int width = 0,
height = 0; height = 0;
if (str.length()) { if (str.length())
{
//str.append("\033[0m"); //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 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; //cout << str.at(d) << " " << i << "," << j << endl;
screen.at(i).at(j) = str.at(d); 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) void eachFrame(vector<vector<char>> &screen, short width, short height)
{ {
screen_clear(screen);
stringstream ss; stringstream ss;
ss << width << "x" << height; //ss << width << "x" << height;
//ss << "Hello World."; ss << "Hello World.";
screen_type(screen, ss.str(), 10, 10, false); screen_type(screen, ss.str(), 10, 10, false);

View File

@@ -0,0 +1,15 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}

View 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"
}
]
}

View File

@@ -0,0 +1,5 @@
{
"files.associations": {
"vector": "cpp"
}
}

View 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"
}

View File

@@ -0,0 +1 @@
g++ $1.cpp -o $1.o && chmod +x $1.o

Binary file not shown.

View 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;
}

View 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