Skip to content

Instantly share code, notes, and snippets.

@crazymonkyyy
Last active October 31, 2024 21:25
Show Gist options
  • Save crazymonkyyy/bd90fe3e7a9372cbe5c644cce11c1b9e to your computer and use it in GitHub Desktop.
Save crazymonkyyy/bd90fe3e7a9372cbe5c644cce11c1b9e to your computer and use it in GitHub Desktop.
import std;
enum string compiler="dmd -unittest -main -run ";
enum string printer="bat --color=always ";
void append(string file,string line){
exe("echo \""~line~"\" >> "~file);
}
void exe(string s)=>executeShell(s).output.writeln;
void delete_(string file,int linestart,int lineend){
auto source=File(file,"r").byLineCopy.array;
File sink=File(file~"temp","w");
if(linestart==-999){
linestart=cast(int)source.length;
lineend=linestart;
}
if(linestart<0){
linestart+=source.length-1;
}
if(lineend<0){
lineend+=source.length-1;
}
foreach(i,s;source){
if(i+1<linestart || i+1>lineend){
//s.writeln;
sink.writeln(s);
}}
//exe("rm "~file~"backup");
exe("mv -f "~file~" "~file~"backup");
exe("mv -f "~file~"temp "~file);
}
int toint(string s){
try{
return s.to!int;
}
catch(Throwable){
return -1;
}}
void main(string[] file){
assert(file.length==2,"pls select file");
string input;
bool lastlineempty=false;
while(true){
if( ! lastlineempty){
exe(printer~file[1]);
}
input=readln[0..$-1];
if(input=="quit"){
return;
} else { if(input==""&& ! lastlineempty){
lastlineempty=true;
} else { if(input==""&& lastlineempty){
exe(compiler~file[1]);
lastlineempty=false;
"press enter to continue".writeln;
readln;
} else { if(input[0]=='d'){
if(input=="d"){
delete_(file[1],-999,-999);
} else {
auto i=input.indexOf("..");
if(i==-1){
int j=input[1..$].toint;
delete_(file[1],j,j);
} else {
delete_(file[1],input[1..i].toint,input[i+2..$].toint);
}
}
} else {
if(lastlineempty){
lastlineempty=false;
append(file[1],"");
}
append(file[1],input);
}}}}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment