idk anymore lol
sophuwu sophie@sophuwu.site
Mon, 09 Oct 2023 09:51:51 +0200
7 files changed,
105 insertions(+),
6 deletions(-)
M
main.cpp
→
main.cpp
@@ -60,13 +60,12 @@ std::srand(std::time(nullptr)*count);
std::string path = std::filesystem::current_path(); return std::to_string(count).append(" ") .append(emotes[std::rand() % 12]).append(" ") - .append(path.substr(path.find_last_of('/')+1)).append("$ "); + .append(path.substr(path.find_last_of('/')+1)).append("$"); } int main(int argc, char* argv[]) { - /*Bash prompt should: - show current folder - count how many commands were executed@@ -85,10 +84,28 @@ rainbow r;
int count = 0; int err = getAllEnvs(r, count); if (argc > 1 && argv[1][0] == '!') { - printf("\033[38;2;255;0;180m<3\033[0m "); + std::string outbuff = "\033[38;2;255;0;180m<3\033[0m "; std::string prompt = makePrompt(count); - if (err) printf("%s", prompt.c_str()); - else r.print2d(prompt, 40+count%20-count%13+count%7); + if (err) { + outbuff.append(prompt); + printf("%s", outbuff.c_str()); + return 0; + } + // r.print2d(prompt, 40+count%20-count%13+count%7); + r.s=5.0*255.0/(double)(40+count%20-count%13+count%7); + int i = 0; + for (; i < prompt.length(); i++) { + outbuff.append("\033[38;2;") + .append(r.c.str()).append("m") + .append(prompt.substr(i, 1)) + .append("\033[0m"); + r.next(); + } + outbuff.append(" "); + for (const char* c = outbuff.c_str(); *c; c++) { + if (*c == 10 || *c == 13 || *c == 0) continue; + fwrite(c, 1, 1, stdout); + } return 0; }@@ -104,7 +121,7 @@ exportEnv("RAINBOWPSR", r.c.r);
exportEnv("RAINBOWPSG", r.c.g); exportEnv("RAINBOWPSB", r.c.b); exportEnv("RAINBOWPSC", ++count); - printf(" %c", '\n'); + printf("\n"); return 0; }
A
prompt.txt
@@ -0,0 +1,1 @@
+[38;2;255;0;180m<3[0m [38;2;0;255;127m3[0m[38;2;0;255;175m7[0m[38;2;0;255;223m5[0m[38;2;0;255;255m [0m[38;2;0;207;255m:[0m[38;2;0;159;255m)[0m[38;2;0;111;255m [0m[38;2;0;63;255mb[0m[38;2;0;15;255ma[0m[38;2;0;0;255ms[0m[38;2;48;0;255mh[0m[38;2;96;0;255mp[0m[38;2;144;0;255mr[0m[38;2;192;0;255mo[0m[38;2;240;0;255mm[0m[38;2;255;0;207mt[0m[38;2;255;0;159m$[0m
A
test.cpp
@@ -0,0 +1,76 @@
+#include <string> +#include <chrono> +#include <ctime> + +void appendTest(std::string test) { + std::string buff = ""; + for (int j = 0; j < test.length(); j++) { + buff.append("\033[38;2;").append(std::to_string(j)) + .append(";").append(std::to_string(j)) + .append(";").append(std::to_string(j)) + .append("m").append(test.substr(j, 1)) + .append("\033[0m "); + } + buff.append("\n"); + printf("\n"); +} + +void sprintfTest(std::string test) { + char cBuff[40]; + std::string buff = ""; + for (int j = 0; j < test.length(); j++) { + sprintf(cBuff, "\033[38;2;%d;%d;%dm%s\033[0m", j, j, j, test.substr(j, 1).c_str()); + buff.append(cBuff); + cBuff[0] = '\0'; + } + buff.append("\n"); + printf("\n"); +} + +void printfTest(std::string test) { + for (int j = 0; j < test.length(); j++) { + printf("\033[38;2;%d;%d;%dm%s\033[0m", j, j, j, test.substr(j, 1).c_str()); + } + printf("\n"); +} + +struct timetype { + std::chrono::time_point<std::chrono::steady_clock> t; + int ms(); + void get(); + int operator-(timetype& t2) { + return this->ms() - t2.ms(); + } +}; +int timetype::ms() { + return std::chrono::duration_cast<std::chrono::milliseconds>(this->t.time_since_epoch()).count(); +} +void timetype::get() { + this->t = std::chrono::steady_clock::now(); +} + +void resolve(const char* name,timetype& start,timetype& end) { + fprintf(stderr,"%s method: %d ms\n", name, end-start); +} + +int main() { + std::string test = "hello i am a really weird string that is really long and i am just typing random stuff to make it longer"; + timetype t1, t2, t3, t4; + + t1.get(); + for (int i = 0; i < 100000; i++) { + appendTest(test); + } + t2.get(); + for (int i = 0; i < 100000; i++) { + sprintfTest(test); + } + t3.get(); + for (int i = 0; i < 100000; i++) { + printfTest(test); + } + t4.get(); + resolve("append", t1, t2); + resolve("sprintf", t2, t3); + resolve("printf", t3, t4); +}