Skip to content

repl #96

Description

@crazymonkyyy

adr wants to make the compiler have a repl mode but for reasons I dont actually understand somethings blocking it

when I was looking into file watching I made a trivial one

this is slow, but not as slow as dlang.io and it also support har

/*
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);
	});
}

If that isnt happening soon Id just ship this

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions