load file
This commit is contained in:
@@ -1,218 +1,65 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdio.h>
|
#include <string>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <term.h>
|
|
||||||
#include <termios.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "timercpp.h"
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
void beforeExit();
|
static inline string trim(string &s) {
|
||||||
void beforeExit(int i);
|
s.erase(s.begin(), find_if(s.begin(), s.end(), [](unsigned char ch) {
|
||||||
void setCursor(int XPos, int YPos);
|
return !isspace(ch);
|
||||||
void getCursor(int* x, int* y);
|
}));
|
||||||
void hideCursor();
|
s.erase(find_if(s.rbegin(), s.rend(), [](unsigned char ch) {
|
||||||
void showCursor();
|
return !isspace(ch);
|
||||||
void closeScreen();
|
}).base(), s.end());
|
||||||
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)
|
|
||||||
{
|
|
||||||
|
|
||||||
//^C
|
|
||||||
signal(SIGINT, beforeExit);
|
|
||||||
//abort()
|
|
||||||
signal(SIGABRT, beforeExit);
|
|
||||||
//sent by "kill" command
|
|
||||||
signal(SIGTERM, beforeExit);
|
|
||||||
//^Z
|
|
||||||
signal(SIGTSTP, beforeExit);
|
|
||||||
atexit(beforeExit);
|
|
||||||
|
|
||||||
float framerate = 10.0;
|
|
||||||
float frameduration = 1000.0/framerate;
|
|
||||||
|
|
||||||
vector<vector<char>> screen; // WILL ALWAYS BE AT LEAST 1x1
|
|
||||||
|
|
||||||
struct winsize w;
|
|
||||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
|
||||||
// width: w.ws_col
|
|
||||||
// height: w.ws_row
|
|
||||||
|
|
||||||
for (int i = 0; i < w.ws_row-1; i++)
|
|
||||||
cout << endl;
|
|
||||||
|
|
||||||
hideCursor();
|
|
||||||
|
|
||||||
t.setInterval([&]()
|
|
||||||
{
|
|
||||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
|
||||||
|
|
||||||
if (w.ws_row > 0 && w.ws_col > 0)
|
|
||||||
{
|
|
||||||
|
|
||||||
//fill vector
|
|
||||||
screen.resize(w.ws_col);
|
|
||||||
for (auto& col : screen)
|
|
||||||
col.resize(w.ws_row);
|
|
||||||
|
|
||||||
eachFrame(screen, w.ws_col, w.ws_row);
|
|
||||||
|
|
||||||
printFrame(screen, w.ws_col, w.ws_row);
|
|
||||||
}
|
|
||||||
}, (int) frameduration);
|
|
||||||
|
|
||||||
while (true);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void beforeExit()
|
void loadfile(vector<string[2]> &scripts) {
|
||||||
{
|
ifstream infile("bots");
|
||||||
//closeScreen();
|
string line;
|
||||||
setCursor(0,0);
|
int linenum = 0;
|
||||||
showCursor();
|
while (getline(infile, line)) {
|
||||||
t.stop();
|
linenum++;
|
||||||
cout << "goodbye" << endl;
|
istringstream iss(line);
|
||||||
exit(0);
|
string str = iss.str();
|
||||||
}
|
|
||||||
|
|
||||||
void beforeExit(int i)
|
if (str.length() == 0 || str.substr(0,1) == "#")
|
||||||
{
|
break;
|
||||||
beforeExit();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setCursor(int XPos, int YPos)
|
string loc = "";
|
||||||
{
|
string script = "start";
|
||||||
printf("\033[%d;%dH",YPos+1,XPos+1);
|
|
||||||
}
|
|
||||||
void getCursor(int* x, int* y)
|
|
||||||
{
|
|
||||||
printf("\033[6n");
|
|
||||||
scanf("\033[%d;%dR", x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
void hideCursor()
|
size_t pos = 0;
|
||||||
{
|
string token;
|
||||||
cout << "\e[?25l" << flush;
|
while ((pos = str.find(":")) != string::npos) {
|
||||||
}
|
token = str.substr(0, pos);
|
||||||
|
trim(token);
|
||||||
void showCursor()
|
if (loc.length() == 0)
|
||||||
{
|
loc = token;
|
||||||
cout << "\e[?25h" << flush;
|
|
||||||
}
|
|
||||||
|
|
||||||
void writeAt(int x, int y, char ch)
|
|
||||||
{
|
|
||||||
if (ch == 0)
|
|
||||||
ch == ' ';
|
|
||||||
setCursor(x, y);
|
|
||||||
//printf("%s", ch);
|
|
||||||
cout << ch << flush;
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
void closeScreen()
|
|
||||||
{
|
|
||||||
struct winsize w;
|
|
||||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
|
||||||
closeScreen(w.ws_col, w.ws_row);
|
|
||||||
}
|
|
||||||
|
|
||||||
void closeScreen(short width, short height)
|
|
||||||
{
|
|
||||||
setCursor(0, 0);
|
|
||||||
for (int i = 0; i < height; i++)
|
|
||||||
for (int j = 0; j < width; j++)
|
|
||||||
writeAt(j, i, ' ');
|
|
||||||
setCursor(0, 0);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void printFrame(vector<vector<char>> screen, short width, short height)
|
|
||||||
{
|
|
||||||
//print frame
|
|
||||||
for (int y = 0; y < height; y++)
|
|
||||||
{
|
|
||||||
for (int x = 0; x < width; x++)
|
|
||||||
//cout << screen.at(x).at(y);
|
|
||||||
writeAt(x, y, screen.at(x).at(y));
|
|
||||||
//cout << endl;
|
|
||||||
}
|
|
||||||
setCursor(0,0);
|
|
||||||
/*for (auto& col : screen)
|
|
||||||
{
|
|
||||||
for (auto& ch : col)
|
|
||||||
cout << ch;
|
|
||||||
cout << endl;
|
|
||||||
}*/
|
|
||||||
//cout << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void screen_type(vector<vector<char>> &screen, string str, int x, int y, bool vertical)
|
|
||||||
{
|
|
||||||
|
|
||||||
int width = 0,
|
|
||||||
height = 0;
|
|
||||||
|
|
||||||
if (str.length())
|
|
||||||
{
|
|
||||||
|
|
||||||
//str.append("\033[0m");
|
|
||||||
|
|
||||||
width = 1;
|
|
||||||
height = 1;
|
|
||||||
|
|
||||||
if (vertical)
|
|
||||||
height = str.length();
|
|
||||||
else
|
else
|
||||||
width = str.length();
|
script = token;
|
||||||
|
str.erase(0, pos + 1);
|
||||||
|
}
|
||||||
|
|
||||||
width = min(width, (int) screen.size() - x);
|
if (loc.length() == 0) {
|
||||||
height = min(height, (int) screen.at(0).size() - y);
|
cout << "WARNING: skipping line " << linenum << endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
scripts.push_back({ loc, script });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = x, ii = 0, d = 0; ii < width; i++, ii++)
|
|
||||||
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)
|
int main() {
|
||||||
{
|
|
||||||
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)
|
vector<string[2]> scripts;
|
||||||
{
|
|
||||||
|
|
||||||
screen_clear(screen);
|
loadfile(scripts);
|
||||||
|
|
||||||
stringstream ss;
|
|
||||||
|
|
||||||
//ss << width << "x" << height;
|
|
||||||
ss << "Hello World.";
|
|
||||||
|
|
||||||
screen_type(screen, ss.str(), 10, 10, false);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
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/ : start
|
||||||
|
~/discordBots/funnyBike/watch-it-talk/ : start
|
||||||
|
~/discordBots/funnyBike/wolframalpha/ : start
|
||||||
|
~/discordBots/IKEA-Canada-Support/rolemanager : tmux
|
||||||
|
~/discordBots/thom wishlane server/rolemanager : tmux
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
// https: //github.com/99x/timercpp/blob/master/timercpp.h
|
|
||||||
#include <iostream>
|
|
||||||
#include <thread>
|
|
||||||
#include <chrono>
|
|
||||||
|
|
||||||
class Timer
|
|
||||||
{
|
|
||||||
bool clear = false;
|
|
||||||
|
|
||||||
public:
|
|
||||||
void setTimeout(auto function, int delay);
|
|
||||||
void setInterval(auto function, int interval);
|
|
||||||
void stop();
|
|
||||||
};
|
|
||||||
|
|
||||||
void Timer::setTimeout(auto function, int delay)
|
|
||||||
{
|
|
||||||
this->clear = false;
|
|
||||||
std::thread t([=]() {
|
|
||||||
if (this->clear)
|
|
||||||
return;
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(delay));
|
|
||||||
if (this->clear)
|
|
||||||
return;
|
|
||||||
function();
|
|
||||||
});
|
|
||||||
t.detach();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Timer::setInterval(auto function, int interval)
|
|
||||||
{
|
|
||||||
this->clear = false;
|
|
||||||
std::thread t([=]() {
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
if (this->clear)
|
|
||||||
return;
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(interval));
|
|
||||||
if (this->clear)
|
|
||||||
return;
|
|
||||||
function();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
t.detach();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Timer::stop()
|
|
||||||
{
|
|
||||||
this->clear = true;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user