Skip to content

shipping a repl #481

@crazymonkyyy

Description

@crazymonkyyy

I offered this code to opend; it would need adr's code to compile here(or shipping a file watching method in Phobos), but for parity you can have it as well

/*
repl

run dlang.io like gists
the `--- foo.d` thing
*/

import std;
enum tempfolder=".__gist/";
auto dropmap(alias F,R)(R r,int i){
	foreach(j;0..i){
		F(r.front);
		r.popFront;
	}
	return r;
}
void watchfile(F)(string file, F func){
	import arsd.core;
	auto w = new DirectoryWatcher(FilePath("."),file,false,(path, op) {
		if(path.path==file){
			func();
	}});
	getThisThreadEventLoop().run(() => false);
}
void exe(string s)=>executeShell(s).output.writeln;
void main(string[] args){
	assert(args.length>1,"gib file");
	watchfile(args[1],(){
		File temp;
		string command;
		exe("mkdir "~tempfolder);
		foreach(l;File(args[1]).byLine.dropmap!((s){command=s.dup;})(1)){
			if(l.length>3 && l[0..3]=="---"){
				//"opening:".writeln(l);
				temp=File((tempfolder~l[3..$].strip).to!string,"w");
			} else {
				temp.writeln(l);
			}
		}
		temp.close;
		exe("cd "~tempfolder~";"~command);
		exe("rm -rf "~tempfolder);
	});
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Prio.3.NormalA bug that is neither a blocker nor a regressionType.EnhancementAn improvement to an existing functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions