sophuwu.site > bashprompt
idk anymore lol
sophuwu sophie@sophuwu.site
Mon, 09 Oct 2023 09:51:51 +0200
commit

43f072e8186b31f2600084e4287c4b888b862ccb

parent

40fbb355c784f8a72c610541545ce2a24fbac6f5

7 files changed, 105 insertions(+), 6 deletions(-)

jump to
A enablebash

@@ -0,0 +1,2 @@

+PS1='\r `bashprompt "!"` \0' +export PROMPT_COMMAND='`bashprompt`'
M main.cppmain.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 pcmd.txt

@@ -0,0 +1,1 @@

+`bashprompt`
A prompt.txt

@@ -0,0 +1,1 @@

+<3 375 :) bashpromt$
A ps1.txt

@@ -0,0 +1,1 @@

+`bashprompt "!"`PS1=`bashprompt "!"` $(printf "\e[3X")
A ps2.txt

@@ -0,0 +1,1 @@

+$( printf "\\r` bashprompt "!" `\\e7 \\e8" )
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); +}